Skip to content

Commit

Permalink
Flush log a 2nd time on error during reboot/shutdown
Browse files Browse the repository at this point in the history
If, after flushing the log, an error occurs before an exec() call, we
need to flush the log again before the exec().
  • Loading branch information
davmac314 committed Aug 6, 2024
1 parent 9696912 commit 3867cf1
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/dinit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -698,18 +698,20 @@ int dinit_main(int argc, char **argv)
}

flush_log();
bool need_log_flush = false;
close_control_socket();

if (am_system_mgr) {
if (shutdown_type == shutdown_type_t::SOFTREBOOT) {
sync(); // Sync to minimise data loss if user elects to power off / hard reset
sync(); // Sync to minimise data loss in case soft-boot fails

execv(dinit_exec, argv);
log(loglevel_t::ERROR, error_exec_dinit, strerror(errno));

// reboot if soft-reboot fails or memory allocation failed
// if we get here, soft reboot failed; reboot normally
log(loglevel_t::ERROR, "Could not soft-reboot. Will attempt reboot.");
shutdown_type = shutdown_type_t::REBOOT;
need_log_flush = true;
}

if (shutdown_type == shutdown_type_t::NONE) {
Expand All @@ -730,11 +732,17 @@ int dinit_main(int argc, char **argv)
catch (...) {
// Couldn't start boot service, let's reboot the system
log(loglevel_t::ERROR, "Could not start 'boot' service. Will attempt reboot.");
need_log_flush = true;
shutdown_type = shutdown_type_t::REBOOT;
}
}
}

if (need_log_flush) {
// In case of error since the log was previously flushed, flush again now
flush_log();
}

const char * cmd_arg;
if (shutdown_type == shutdown_type_t::HALT) {
cmd_arg = "-h";
Expand Down

0 comments on commit 3867cf1

Please sign in to comment.