Skip to content

Commit

Permalink
fix(update-server): Avoid bricking when given a bad name (#10219)
Browse files Browse the repository at this point in the history
Closes #9960. Closes #10198.
  • Loading branch information
SyntaxColoring authored May 12, 2022
1 parent 90d8b0b commit b71278f
Show file tree
Hide file tree
Showing 6 changed files with 212 additions and 96 deletions.
2 changes: 1 addition & 1 deletion update-server/otupdate/buildroot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def get_app(
system_version_file = BR_BUILTIN_VERSION_FILE

version = get_version(system_version_file)
name = name_override or name_management.get_name()
name = name_override or name_management.get_pretty_hostname()
boot_id = boot_id_override or control.get_boot_id()
config_obj = config.load(config_file_override)

Expand Down
21 changes: 14 additions & 7 deletions update-server/otupdate/buildroot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,29 @@
LOG = logging.getLogger(__name__)


def main():
def main() -> None:
parser = cli.build_root_parser()
args = parser.parse_args()
loop = asyncio.get_event_loop()
systemd.configure_logging(getattr(logging, args.log_level.upper()))

LOG.info("Setting hostname")
hostname = loop.run_until_complete(name_management.setup_hostname())
LOG.info(f"Set hostname to {hostname}")
LOG.info("Setting static hostname")
hostname = loop.run_until_complete(name_management.set_up_static_hostname())
LOG.info(f"Set static hostname to {hostname}")

LOG.info("Building buildroot update server")
app = get_app(args.version_file, args.config_file)

name = app[constants.DEVICE_NAME_VARNAME]
LOG.info(f"Setting advertised name to {name}")
loop.run_until_complete(name_management.set_name(name))
name = app[constants.DEVICE_NAME_VARNAME] # Set by get_app().

LOG.info(f"Setting Avahi service name to {name}")
try:
loop.run_until_complete(name_management.set_avahi_service_name(name))
except Exception:
LOG.exception(
"Error setting the Avahi service name."
" mDNS + DNS-SD advertisement may not work."
)

LOG.info(f"Notifying {systemd.SOURCE} that service is up")
systemd.notify_up()
Expand Down
Loading

0 comments on commit b71278f

Please sign in to comment.