Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
bootloader: gracefully reboot using '/sbin/init 6'
Browse files Browse the repository at this point in the history
This patch mainly aims to add a graceful reboot by executing
'/sbin/init 6' rather than calling reboot system call.

Signed-off-by: Ming Liu <liu.ming50@gmail.com>
  • Loading branch information
liuming50 committed Mar 21, 2019
1 parent e0398ee commit 409cd87
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/libaktualizr/bootloader/bootloader.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include <fcntl.h>
#include <sys/stat.h>

#include <sys/types.h>
#include <sys/reboot.h>
#include <unistd.h>
#include <stdlib.h>

#include <boost/filesystem.hpp>

Expand Down Expand Up @@ -169,13 +170,20 @@ void Bootloader::rebootFlagClear() {
}

void Bootloader::reboot(bool fake_reboot) {
struct stat st;

if (fake_reboot) {
boost::filesystem::remove(reboot_sentinel_);
} else {
sync();
if (setuid(0) != 0) {
LOG_ERROR << "Failed to set/verify a root user so cannot reboot system programmatically";
return;
}

if ((stat ("/sbin/init", &st) >= 0) && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))) {
system("/sbin/init 6");
} else {
sync();
::reboot(RB_AUTOBOOT);
}
}
Expand Down

0 comments on commit 409cd87

Please sign in to comment.