1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 08:54:58 +00:00

Kernel+Userland: Introduce a new way to reboot and poweroff the machine

This change removes the halt and reboot syscalls, and create a new
mechanism to change the power state of the machine.
Instead of how power state was changed until now, put a SysFS node as
writable only for the superuser, that with a defined value, can result
in either reboot or poweroff.
In the future, a power group can be assigned to this node (which will be
the GroupID responsible for power management).

This opens an opportunity to permit to shutdown/reboot without superuser
permissions, so in the future, a userspace daemon can take control of
this node to perform power management operations without superuser
permissions, if we enforce different UserID/GroupID on that node.
This commit is contained in:
Liav A 2021-09-11 12:20:47 +03:00 committed by Andreas Kling
parent 06e95d0fd7
commit 8d0dbdeaac
11 changed files with 161 additions and 97 deletions

View file

@ -1,16 +1,24 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
int main(int, char**)
{
if (reboot() < 0) {
perror("reboot");
int power_state_switch_node = open("/sys/firmware/power_state", O_WRONLY);
if (power_state_switch_node < 0) {
perror("open");
return 1;
}
const char* value = "1";
if (write(power_state_switch_node, value, 1) < 0) {
perror("write");
return 1;
}
return 0;