diff --git a/sysdeps/managarm/generic/fork-exec.cpp b/sysdeps/managarm/generic/fork-exec.cpp index bc86a414e..1e3262ff7 100644 --- a/sysdeps/managarm/generic/fork-exec.cpp +++ b/sysdeps/managarm/generic/fork-exec.cpp @@ -54,22 +54,34 @@ int sys_futex_wake(int *pointer) { } int sys_waitpid(pid_t pid, int *status, int flags, struct rusage *ru, pid_t *ret_pid) { - SignalGuard sguard; + if(ru) { + mlibc::infoLogger() << "mlibc: struct rusage in sys_waitpid is unsupported" << frg::endlog; + return ENOSYS; + } + + HelHandle cancel_handle; + HEL_CHECK(helCreateOneshotEvent(&cancel_handle)); + helix::UniqueDescriptor cancel_event{cancel_handle}; managarm::posix::CntRequest req(getSysdepsAllocator()); req.set_request_type(managarm::posix::CntReqType::WAIT); req.set_pid(pid); req.set_flags(flags); - auto [offer, send_head, recv_resp] = exchangeMsgsSync( - getPosixLane(), - helix_ng::offer( - helix_ng::sendBragiHeadOnly(req, getSysdepsAllocator()), helix_ng::recvInline() - ) + auto [offer, send_head, push_descriptor, recv_resp] = + exchangeMsgsSyncCancellable( + getPosixLane(), + cancel_handle, + helix_ng::offer( + helix_ng::sendBragiHeadOnly(req, getSysdepsAllocator()), + helix_ng::pushDescriptor(cancel_event), + helix_ng::recvInline() + ) ); HEL_CHECK(offer.error()); HEL_CHECK(send_head.error()); + HEL_CHECK(push_descriptor.error()); HEL_CHECK(recv_resp.error()); managarm::posix::SvrResponse resp(getSysdepsAllocator()); @@ -77,6 +89,10 @@ int sys_waitpid(pid_t pid, int *status, int flags, struct rusage *ru, pid_t *ret if (resp.error() == managarm::posix::Errors::ILLEGAL_ARGUMENTS) { return EINVAL; } + if (resp.error() == managarm::posix::Errors::INTERRUPTED) { + mlibc::infoLogger() << "returning EINT" << frg::endlog; + return EINTR; + } __ensure(resp.error() == managarm::posix::Errors::SUCCESS); if (status) *status = resp.mode();