
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.
36 lines
945 B
C++
36 lines
945 B
C++
/*
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
* Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/RefPtr.h>
|
|
#include <AK/Types.h>
|
|
#include <AK/Vector.h>
|
|
#include <Kernel/FileSystem/SysFS.h>
|
|
#include <Kernel/Firmware/SysFSFirmware.h>
|
|
#include <Kernel/KBuffer.h>
|
|
#include <Kernel/Memory/MappedROM.h>
|
|
#include <Kernel/Memory/Region.h>
|
|
#include <Kernel/PhysicalAddress.h>
|
|
#include <Kernel/VirtualAddress.h>
|
|
|
|
namespace Kernel {
|
|
|
|
class PowerStateSwitchNode final : public SysFSComponent {
|
|
public:
|
|
static NonnullRefPtr<PowerStateSwitchNode> must_create(FirmwareSysFSDirectory&);
|
|
virtual mode_t permissions() const override;
|
|
virtual KResultOr<size_t> write_bytes(off_t, size_t, UserOrKernelBuffer const&, OpenFileDescription*) override;
|
|
|
|
private:
|
|
PowerStateSwitchNode(FirmwareSysFSDirectory&);
|
|
|
|
void reboot();
|
|
void poweroff();
|
|
};
|
|
|
|
}
|