mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:17:36 +00:00
Kernel+LibC: Add sys$waitid(), and make sys$waitpid() wrap it
sys$waitid() takes an explicit description of whether it's waiting for a single process with the given PID, all of the children, a group, etc., and returns its info as a siginfo_t. It also doesn't automatically imply WEXITED, which clears up the confusion in the kernel.
This commit is contained in:
parent
a6cb7f759e
commit
b3a24d732d
5 changed files with 140 additions and 55 deletions
|
@ -38,7 +38,52 @@ pid_t wait(int* wstatus)
|
|||
|
||||
pid_t waitpid(pid_t waitee, int* wstatus, int options)
|
||||
{
|
||||
int rc = syscall(SC_waitpid, waitee, wstatus, options);
|
||||
siginfo_t siginfo;
|
||||
idtype_t idtype;
|
||||
id_t id;
|
||||
|
||||
if (waitee < -1) {
|
||||
idtype = P_PGID;
|
||||
id = -waitee;
|
||||
} else if (waitee == -1) {
|
||||
idtype = P_ALL;
|
||||
id = 0;
|
||||
} else if (waitee == 0) {
|
||||
idtype = P_PGID;
|
||||
id = getgid();
|
||||
} else {
|
||||
idtype = P_PID;
|
||||
id = waitee;
|
||||
}
|
||||
|
||||
int rc = waitid(idtype, id, &siginfo, options | WEXITED);
|
||||
|
||||
if (rc < 0)
|
||||
return rc;
|
||||
|
||||
if (wstatus) {
|
||||
switch (siginfo.si_code) {
|
||||
case CLD_EXITED:
|
||||
*wstatus = siginfo.si_status << 8;
|
||||
break;
|
||||
case CLD_KILLED:
|
||||
*wstatus = siginfo.si_status;
|
||||
break;
|
||||
case CLD_STOPPED:
|
||||
*wstatus = siginfo.si_status << 8 | 0x7f;
|
||||
break;
|
||||
default:
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
return siginfo.si_pid;
|
||||
}
|
||||
|
||||
int waitid(idtype_t idtype, id_t id, siginfo_t* infop, int options)
|
||||
{
|
||||
Syscall::SC_waitid_params params { idtype, id, infop, options };
|
||||
int rc = syscall(SC_waitid, ¶ms);
|
||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <signal.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
|
@ -35,7 +36,7 @@ __BEGIN_DECLS
|
|||
#define WSTOPSIG(status) WEXITSTATUS(status)
|
||||
#define WTERMSIG(status) ((status)&0x7f)
|
||||
#define WIFEXITED(status) (WTERMSIG(status) == 0)
|
||||
#define WIFSTOPPED(status) (((status) & 0xff) == 0x7f)
|
||||
#define WIFSTOPPED(status) (((status)&0xff) == 0x7f)
|
||||
#define WIFSIGNALED(status) (((char)(((status)&0x7f) + 1) >> 1) > 0)
|
||||
|
||||
#define WNOHANG 1
|
||||
|
@ -52,5 +53,6 @@ typedef enum {
|
|||
|
||||
pid_t waitpid(pid_t, int* wstatus, int options);
|
||||
pid_t wait(int* wstatus);
|
||||
int waitid(idtype_t idtype, id_t id, siginfo_t* infop, int options);
|
||||
|
||||
__END_DECLS
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue