Skip to content

Commit

Permalink
Merge pull request #1034 from Dennisbonke/reboot
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennisbonke authored Oct 8, 2024
2 parents b842be7 + 8a4099a commit de2400d
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions sysdeps/managarm/generic/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stdio.h>
#include <sys/eventfd.h>
#include <sys/inotify.h>
#include <sys/reboot.h>
#include <sys/signalfd.h>
#include <unistd.h>

Expand Down Expand Up @@ -1334,6 +1335,37 @@ int sys_signalfd_create(const sigset_t *masks, int flags, int *fd) {
return 0;
}

int sys_reboot(int command) {
if(command != RB_POWER_OFF && command != RB_AUTOBOOT) {
mlibc::infoLogger() << "mlibc: Anything other than power off or reboot is not supported yet!" << frg::endlog;
return EINVAL;
}

SignalGuard sguard;

managarm::posix::RebootRequest<MemoryAllocator> req(getSysdepsAllocator());
req.set_cmd(command);

auto [offer, sendReq, recvResp] = exchangeMsgsSync(
getPosixLane(),
helix_ng::offer(
helix_ng::sendBragiHeadOnly(req, getSysdepsAllocator()),
helix_ng::recvInline()
)
);

HEL_CHECK(offer.error());
HEL_CHECK(sendReq.error());
HEL_CHECK(recvResp.error());

managarm::posix::SvrResponse<MemoryAllocator> resp(getSysdepsAllocator());
resp.ParseFromArray(recvResp.data(), recvResp.length());
if(resp.error() == managarm::posix::Errors::INSUFFICIENT_PERMISSION)
return EPERM;
__ensure(resp.error() == managarm::posix::Errors::SUCCESS);
return 0;
}

int sys_inotify_create(int flags, int *fd) {
__ensure(!(flags & ~(IN_CLOEXEC | IN_NONBLOCK)));

Expand Down

0 comments on commit de2400d

Please sign in to comment.