Feature shutdown improvement (#556)

* Use init instead of reboot for shutdown and restart

* Include file update
This commit is contained in:
Uwe Seimet 2021-12-22 09:21:07 +01:00 committed by GitHub
parent 94786aec54
commit e2580d77cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -28,8 +28,6 @@
#include "rascsi_interface.pb.h" #include "rascsi_interface.pb.h"
#include "spdlog/spdlog.h" #include "spdlog/spdlog.h"
#include "spdlog/sinks/stdout_color_sinks.h" #include "spdlog/sinks/stdout_color_sinks.h"
#include <sys/reboot.h>
#include <linux/reboot.h>
#include <string> #include <string>
#include <sstream> #include <sstream>
#include <iostream> #include <iostream>
@ -1162,9 +1160,8 @@ void ShutDown(int fd, const string& mode) {
SerializeMessage(fd, result); SerializeMessage(fd, result);
DetachAll(); DetachAll();
sync();
if (reboot(LINUX_REBOOT_CMD_HALT) == -1) { if (system("init 0") == -1) {
LOGERROR("System shutdown failed: %s", strerror(errno)); LOGERROR("System shutdown failed: %s", strerror(errno));
} }
} }
@ -1174,9 +1171,8 @@ void ShutDown(int fd, const string& mode) {
SerializeMessage(fd, result); SerializeMessage(fd, result);
DetachAll(); DetachAll();
sync();
if (reboot(LINUX_REBOOT_CMD_RESTART) == -1) { if (system("init 6") == -1) {
LOGERROR("System reboot failed: %s", strerror(errno)); LOGERROR("System reboot failed: %s", strerror(errno));
} }
} }