From: Matthew Dillon Date: Tue, 11 Nov 2014 06:37:47 +0000 (-0800) Subject: kernel - Add reapctl() system call for managing sub-processes (3) -> procctl() X-Git-Tag: v4.2.0rc~1510 X-Git-Url: https://gitweb.dragonflybsd.org/~tuxillo/dragonfly.git/commitdiff_plain/fc3bc2868ad212f3b412ad13f0eaa35b3f8d458d kernel - Add reapctl() system call for managing sub-processes (3) -> procctl() * After discussions, rename reapctl() -> procctl() and adjust the API to be compatible with FreeBSD. * bapt will implement the same exact feature in FreeBSD via procctl(). --- diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc index a3bf424393..c00581a63b 100644 --- a/lib/libc/sys/Makefile.inc +++ b/lib/libc/sys/Makefile.inc @@ -84,6 +84,7 @@ MAN+= _exit.2 accept.2 access.2 acct.2 adjtime.2 \ nfssvc.2 ntp_adjtime.2 ntp_gettime.2 \ open.2 pathconf.2 pipe.2 poll.2 profil.2 pselect.2 ptrace.2 quotactl.2 \ read.2 readlink.2 reboot.2 recv.2 rename.2 revoke.2 rfork.2 rmdir.2 \ + procctl.2 \ rtprio.2 select.2 semctl.2 semget.2 semop.2 send.2 sendfile.2 \ setgroups.2 setpgid.2 setregid.2 setresuid.2 setreuid.2 setsid.2 \ setuid.2 shmat.2 shmctl.2 shmget.2 shutdown.2 \ diff --git a/lib/libc/sys/Symbol.map b/lib/libc/sys/Symbol.map index 446d73fbae..f3458e9383 100644 --- a/lib/libc/sys/Symbol.map +++ b/lib/libc/sys/Symbol.map @@ -140,7 +140,7 @@ DF306.0 { modstat; mount; mountctl; - reapctl; + procctl; mprotect; mq_close; mq_getattr; @@ -438,7 +438,7 @@ DFprivate_1.0 { __sys_modstat; __sys_mount; __sys_mountctl; - __sys_reapctl; + __sys_procctl; __sys_mprotect; __sys_mq_close; __sys_mq_getattr; @@ -721,7 +721,7 @@ DFprivate_1.0 { _modstat; _mount; _mountctl; - _reapctl; + _procctl; _mprotect; _mq_close; _mq_getattr; diff --git a/lib/libc/sys/reapctl.2 b/lib/libc/sys/procctl.2 similarity index 94% rename from lib/libc/sys/reapctl.2 rename to lib/libc/sys/procctl.2 index ac8940d478..e2a35dd642 100644 --- a/lib/libc/sys/reapctl.2 +++ b/lib/libc/sys/procctl.2 @@ -30,23 +30,25 @@ .\" SUCH DAMAGE. .\" .Dd November 9, 2014 -.Dt REAPCTL 2 +.Dt PROCCTL 2 .Os .Sh NAME -.Nm reapctl +.Nm procctl .Nd control reaping of sub-processes .Sh LIBRARY .Lb libc .Sh SYNOPSIS -.In sys/reaper.h +.In sys/procctl.h .Ft int -.Fo reapctl -.Fa "int op" -.Fa "union reaper_info *data" +.Fo procctl +.Fa "idtype_t idtype" +.Fa "id_t id" +.Fa "int cmd" +.Fa "void *data" .Fc .Sh DESCRIPTION The -.Fn reapctl +.Fn procctl system call allows a process to take-over the reaping task from init for any forked sub-process, recursively (for all children thereafter) which would otherwise reparent to init. @@ -62,15 +64,15 @@ chroots to ensure that the underlying services cannot get away from under the monitor. .Sh CONTROL OPERATIONS The following operations are defined in -.In sys/reaper.h : +.In sys/procctl.h : .Bl -tag -width indent -.It Dv REAPER_OP_ACQUIRE +.It Dv PROC_REAP_ACQUIRE Become a reaper for all sub-processes forked after the call returns. The data argument is ignored and can be NULL. -.It Dv REAPER_OP_RELEASE +.It Dv PROC_REAP_RELEASE Release reaping duties, reaping returns to normal operation. The data argument is ignored and can be NULL. -.It Dv REAPER_OP_STATUS +.It Dv PROC_REAP_STATUS Request status. The supplied data structure is loaded with the current reaper status. The data argument may be NULL, which can be used to test whether @@ -102,7 +104,7 @@ Only sufficient data to support the requested operation is read or written. .Sh ERRORS The -.Fn reapctl +.Fn procctl function will fail when one of the following occurs: .Bl -tag -width Er .It Bq Er EALREADY @@ -117,12 +119,12 @@ The operation is not supported. .Sh SEE ALSO .Sh HISTORY The -.Fn reapctl +.Fn procctl system call first appeared in .Dx 4.0 . .Sh AUTHORS .An -nosplit The -.Fn reapctl +.Fn procctl system call was written by .An Matthew Dillon . diff --git a/sys/kern/init_sysent.c b/sys/kern/init_sysent.c index 5e974b7436..cddb67cd32 100644 --- a/sys/kern/init_sysent.c +++ b/sys/kern/init_sysent.c @@ -572,5 +572,5 @@ struct sysent sysent[] = { { AS(lpathconf_args), (sy_call_t *)sys_lpathconf }, /* 533 = lpathconf */ { AS(vmm_guest_ctl_args), (sy_call_t *)sys_vmm_guest_ctl }, /* 534 = vmm_guest_ctl */ { AS(vmm_guest_sync_addr_args), (sy_call_t *)sys_vmm_guest_sync_addr }, /* 535 = vmm_guest_sync_addr */ - { AS(reapctl_args), (sy_call_t *)sys_reapctl }, /* 536 = reapctl */ + { AS(procctl_args), (sy_call_t *)sys_procctl }, /* 536 = procctl */ }; diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c index 8b6a423c18..bc8c8e602f 100644 --- a/sys/kern/kern_exit.c +++ b/sys/kern/kern_exit.c @@ -580,7 +580,7 @@ exit1(int rv) if (sig != SIGUSR1 && sig != SIGCHLD) sig = SIGCHLD; - ksignal(pp, p->p_sigparent); + ksignal(pp, sig); } else { ksignal(pp, SIGCHLD); } diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c index 344301ba4e..0cc85e4998 100644 --- a/sys/kern/kern_fork.c +++ b/sys/kern/kern_fork.c @@ -814,10 +814,10 @@ start_forked_proc(struct lwp *lp1, struct proc *p2) } /* - * reapctl (int op, union reaper *data) + * procctl (idtype_t idtype, id_t id, int cmd, void *arg) */ int -sys_reapctl(struct reapctl_args *uap) +sys_procctl(struct procctl_args *uap) { struct proc *p = curproc; struct proc *p2; @@ -825,8 +825,11 @@ sys_reapctl(struct reapctl_args *uap) union reaper_info udata; int error; - switch(uap->op) { - case REAPER_OP_ACQUIRE: + if (uap->idtype != P_PID || uap->id != (id_t)p->p_pid) + return EINVAL; + + switch(uap->cmd) { + case PROC_REAP_ACQUIRE: lwkt_gettoken(&p->p_token); reap = kmalloc(sizeof(*reap), M_REAPER, M_WAITOK|M_ZERO); if (p->p_reaper == NULL || p->p_reaper->p != p) { @@ -838,7 +841,7 @@ sys_reapctl(struct reapctl_args *uap) } lwkt_reltoken(&p->p_token); break; - case REAPER_OP_RELEASE: + case PROC_REAP_RELEASE: lwkt_gettoken(&p->p_token); release_again: reap = p->p_reaper; @@ -864,7 +867,7 @@ release_again: } lwkt_reltoken(&p->p_token); break; - case REAPER_OP_STATUS: + case PROC_REAP_STATUS: bzero(&udata, sizeof(udata)); lwkt_gettoken_shared(&p->p_token); if ((reap = p->p_reaper) != NULL && reap->p == p) { diff --git a/sys/kern/makesyscalls.sh b/sys/kern/makesyscalls.sh index efcdd85746..31a73332d5 100644 --- a/sys/kern/makesyscalls.sh +++ b/sys/kern/makesyscalls.sh @@ -100,6 +100,7 @@ s/\$//g printf "#include \n\n" > sysarg printf "#include \n\n" > sysarg printf "#include \n\n" > sysarg + printf "#include \n\n" > sysarg printf "#define\tPAD_(t)\t(sizeof(register_t) <= sizeof(t) ? \\\n" > sysarg printf "\t\t0 : sizeof(register_t) - sizeof(t))\n\n" > sysarg diff --git a/sys/kern/syscalls.c b/sys/kern/syscalls.c index 54849f03e4..f1c005b56c 100644 --- a/sys/kern/syscalls.c +++ b/sys/kern/syscalls.c @@ -544,5 +544,5 @@ const char *syscallnames[] = { "lpathconf", /* 533 = lpathconf */ "vmm_guest_ctl", /* 534 = vmm_guest_ctl */ "vmm_guest_sync_addr", /* 535 = vmm_guest_sync_addr */ - "reapctl", /* 536 = reapctl */ + "procctl", /* 536 = procctl */ }; diff --git a/sys/kern/syscalls.master b/sys/kern/syscalls.master index 560ad795ee..86f46f0a8a 100644 --- a/sys/kern/syscalls.master +++ b/sys/kern/syscalls.master @@ -742,4 +742,4 @@ 533 STD { int lpathconf(char *path, int name); } 534 STD { int vmm_guest_ctl(int op, struct vmm_guest_options *options); } 535 STD { int vmm_guest_sync_addr(long *dstaddr, long *srcaddr); } -536 STD { int reapctl(int op, union reaper_info *data); } +536 STD { int procctl(idtype_t idtype, id_t id, int cmd, void *data); } diff --git a/sys/sys/proc.h b/sys/sys/proc.h index 5b9a1102aa..14d8661300 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -63,7 +63,7 @@ #include #include #ifdef _KERNEL -#include +#include #include #endif #include diff --git a/sys/sys/reaper.h b/sys/sys/procctl.h similarity index 64% rename from sys/sys/reaper.h rename to sys/sys/procctl.h index ea10fdfba3..eec79ed29c 100644 --- a/sys/sys/reaper.h +++ b/sys/sys/procctl.h @@ -32,13 +32,42 @@ * SUCH DAMAGE. */ -#ifndef _SYS_REAPER_H_ -#define _SYS_REAPER_H_ +#ifndef _SYS_PROCCTL_H_ +#define _SYS_PROCCTL_H_ #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES) #include #endif +typedef enum idtype { + /* + * These names were mostly lifted from Solaris source code and + * still use Solaris style naming to avoid breaking any + * OpenSolaris code which has been ported to FreeBSD. There + * is no clear FreeBSD counterpart for all of the names, but + * some have a clear correspondence to FreeBSD entities. + * + * The numerical values are kept synchronized with the Solaris + * values. + */ + P_PID, /* A process identifier. */ + P_PPID, /* A parent process identifier. */ + P_PGID, /* A process group identifier. */ + P_SID, /* A session identifier. */ + P_CID, /* A scheduling class identifier. */ + P_UID, /* A user identifier. */ + P_GID, /* A group identifier. */ + P_ALL, /* All processes. */ + P_LWPID, /* An LWP identifier. */ + P_TASKID, /* A task identifier. */ + P_PROJID, /* A project identifier. */ + P_POOLID, /* A pool identifier. */ + P_JAILID, /* A zone identifier. */ + P_CTID, /* A (process) contract identifier. */ + P_CPUID, /* CPU identifier. */ + P_PSETID /* Processor set identifier. */ +} idtype_t; /* The type of id_t we are using. */ + struct reaper_status { uint32_t flags; uint32_t refs; @@ -51,11 +80,11 @@ union reaper_info { struct reaper_status status; }; -#define _REAPER_PRESENT +#define _PROCCTL_PRESENT -#define REAPER_OP_ACQUIRE 0x0001 -#define REAPER_OP_RELEASE 0x0002 -#define REAPER_OP_STATUS 0x0003 +#define PROC_REAP_ACQUIRE 0x0001 +#define PROC_REAP_RELEASE 0x0002 +#define PROC_REAP_STATUS 0x0003 #define REAPER_STAT_OWNED 0x00000001 #define REAPER_STAT_REALINIT 0x00000002 @@ -76,7 +105,7 @@ struct sysreaper { #if !defined(_KERNEL) -int reapctl(int op, union reaper_info *data); +int procctl(idtype_t idtype, id_t id, int cmd, void *arg); #endif diff --git a/sys/sys/syscall.h b/sys/sys/syscall.h index 428439c40e..02346762d2 100644 --- a/sys/sys/syscall.h +++ b/sys/sys/syscall.h @@ -376,5 +376,5 @@ #define SYS_lpathconf 533 #define SYS_vmm_guest_ctl 534 #define SYS_vmm_guest_sync_addr 535 -#define SYS_reapctl 536 +#define SYS_procctl 536 #define SYS_MAXSYSCALL 537 diff --git a/sys/sys/syscall.mk b/sys/sys/syscall.mk index c78aa30d27..8025a7ee68 100644 --- a/sys/sys/syscall.mk +++ b/sys/sys/syscall.mk @@ -300,4 +300,4 @@ MIASM = \ lpathconf.o \ vmm_guest_ctl.o \ vmm_guest_sync_addr.o \ - reapctl.o + procctl.o diff --git a/sys/sys/sysproto.h b/sys/sys/sysproto.h index 71c54e3150..22190f2249 100644 --- a/sys/sys/sysproto.h +++ b/sys/sys/sysproto.h @@ -20,6 +20,8 @@ #include +#include + #define PAD_(t) (sizeof(register_t) <= sizeof(t) ? \ 0 : sizeof(register_t) - sizeof(t)) @@ -2265,12 +2267,14 @@ struct vmm_guest_sync_addr_args { long * dstaddr; char dstaddr_[PAD_(long *)]; long * srcaddr; char srcaddr_[PAD_(long *)]; }; -struct reapctl_args { +struct procctl_args { #ifdef _KERNEL struct sysmsg sysmsg; #endif - int op; char op_[PAD_(int)]; - union reaper * data; char data_[PAD_(union reaper *)]; + idtype_t idtype; char idtype_[PAD_(idtype_t)]; + id_t id; char id_[PAD_(id_t)]; + int cmd; char cmd_[PAD_(int)]; + void * data; char data_[PAD_(void *)]; }; #ifdef COMPAT_43 @@ -2878,7 +2882,7 @@ int sys_eaccess (struct eaccess_args *); int sys_lpathconf (struct lpathconf_args *); int sys_vmm_guest_ctl (struct vmm_guest_ctl_args *); int sys_vmm_guest_sync_addr (struct vmm_guest_sync_addr_args *); -int sys_reapctl (struct reapctl_args *); +int sys_procctl (struct procctl_args *); #endif /* !_SYS_SYSPROTO_H_ */ #undef PAD_ diff --git a/sys/sys/sysunion.h b/sys/sys/sysunion.h index 4b976eea1c..1ef25cbe6d 100644 --- a/sys/sys/sysunion.h +++ b/sys/sys/sysunion.h @@ -407,5 +407,5 @@ union sysunion { struct lpathconf_args lpathconf; struct vmm_guest_ctl_args vmm_guest_ctl; struct vmm_guest_sync_addr_args vmm_guest_sync_addr; - struct reapctl_args reapctl; + struct procctl_args procctl; };