Skip to content

Commit 3867cf1

Browse files
committed
Flush log a 2nd time on error during reboot/shutdown
If, after flushing the log, an error occurs before an exec() call, we need to flush the log again before the exec().
1 parent 9696912 commit 3867cf1

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/dinit.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -698,18 +698,20 @@ int dinit_main(int argc, char **argv)
698698
}
699699

700700
flush_log();
701+
bool need_log_flush = false;
701702
close_control_socket();
702703

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

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

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

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

741+
if (need_log_flush) {
742+
// In case of error since the log was previously flushed, flush again now
743+
flush_log();
744+
}
745+
738746
const char * cmd_arg;
739747
if (shutdown_type == shutdown_type_t::HALT) {
740748
cmd_arg = "-h";

0 commit comments

Comments
 (0)