Patch for prctl(2)

Richard Gooch (rgooch@atnf.CSIRO.AU)
Tue, 26 Aug 1997 20:13:57 +1000


Hi, Linus. I notice that pre-patch 2.1.52-2 does not contain the
prctl(2) patch that I sent you. I've reapplied the patch against
pre-patch 2.1.52-2 to check it's still valid, which it is. I've
included it below.
This patch allows a process to control which signal is sent to it when
its parent dies.

Regards,

Richard....

diff -urN linux-2.1.51/CREDITS linux/CREDITS
--- linux-2.1.51/CREDITS Tue Aug 19 11:52:12 1997
+++ linux/CREDITS Thu Aug 21 23:15:44 1997
@@ -486,14 +486,14 @@
E: philip@raptor.com
D: Kernel / timekeeping stuff

-N: Michael A. Griffith
-E: grif@cs.ucr.edu
-W: http://www.cs.ucr.edu/~grif
-D: Loopback speedup, qlogic scsi hacking, VT_LOCKSWITCH
-S: Department of Computer Science
-S: University of California, Riverside
-S: Riverside, California 92521-0304
-S: USA
+N: Richard E. Gooch
+E: rgooch@atnf.csiro.au
+D: parent process death signal to children
+D: prctl() syscall
+S: CSIRO Australia Telescope National Facility
+S: P.O. Box 76, Epping
+S: N.S.W., 2121
+S: Australia

N: Dmitry S. Gorodchanin
E: begemot@bgm.rosprint.net
@@ -517,6 +517,15 @@
D: kernel hacker
S: 8124 Constitution Apt. 7
S: Sterling Heights, Michigan 48313
+S: USA
+
+N: Michael A. Griffith
+E: grif@cs.ucr.edu
+W: http://www.cs.ucr.edu/~grif
+D: Loopback speedup, qlogic scsi hacking, VT_LOCKSWITCH
+S: Department of Computer Science
+S: University of California, Riverside
+S: Riverside, California 92521-0304
S: USA

N: Grant Guenther
diff -urN linux-2.1.51/arch/alpha/kernel/entry.S linux/arch/alpha/kernel/entry.S
--- linux-2.1.51/arch/alpha/kernel/entry.S Fri May 30 14:53:04 1997
+++ linux/arch/alpha/kernel/entry.S Thu Aug 21 23:21:33 1997
@@ -771,4 +771,5 @@
.quad sys_sched_get_priority_max, sys_sched_get_priority_min, sys_sched_rr_get_interval, do_entSys /* sys_afs_syscall */, sys_newuname
.quad sys_nanosleep, sys_mremap, sys_nfsservctl, sys_setresuid, sys_getresuid
.quad sys_pciconfig_read, sys_pciconfig_write, sys_query_module
+ .quad sys_prctl
.quad do_entSys, do_entSys
diff -urN linux-2.1.51/arch/i386/kernel/entry.S linux/arch/i386/kernel/entry.S
--- linux-2.1.51/arch/i386/kernel/entry.S Fri Jun 27 05:33:36 1997
+++ linux/arch/i386/kernel/entry.S Thu Aug 21 22:35:39 1997
@@ -528,6 +528,7 @@
.long SYMBOL_NAME(sys_nfsservctl)
.long SYMBOL_NAME(sys_setresgid) /* 170 */
.long SYMBOL_NAME(sys_getresgid)
- .rept NR_syscalls-171
+ .long SYMBOL_NAME(sys_prctl)
+ .rept NR_syscalls-172
.long SYMBOL_NAME(sys_ni_syscall)
.endr
diff -urN linux-2.1.51/arch/m68k/kernel/entry.S linux/arch/m68k/kernel/entry.S
--- linux-2.1.51/arch/m68k/kernel/entry.S Fri Aug 1 06:09:16 1997
+++ linux/arch/m68k/kernel/entry.S Thu Aug 21 23:24:52 1997
@@ -568,6 +568,7 @@
.long SYMBOL_NAME(sys_query_module)
.long SYMBOL_NAME(sys_poll)
.long SYMBOL_NAME(sys_nfsservctl)
+ .long SYMBOL_NAME(sys_prctl)
.rept NR_syscalls-(.-SYMBOL_NAME(sys_call_table))/4
.long SYMBOL_NAME(sys_ni_syscall)
.endr
diff -urN linux-2.1.51/arch/mips/kernel/syscalls.h linux/arch/mips/kernel/syscalls.h
--- linux-2.1.51/arch/mips/kernel/syscalls.h Tue Aug 19 11:52:12 1997
+++ linux/arch/mips/kernel/syscalls.h Thu Aug 21 23:27:49 1997
@@ -212,3 +212,4 @@
SYS(sys_getresgid, 3)
SYS(sys_setresgid, 3) /* 4190 */
SYS(sys_getresgid, 3)
+SYS(sys_prctl, 5)
diff -urN linux-2.1.51/arch/ppc/kernel/misc.S linux/arch/ppc/kernel/misc.S
--- linux-2.1.51/arch/ppc/kernel/misc.S Tue Aug 19 11:52:12 1997
+++ linux/arch/ppc/kernel/misc.S Thu Aug 21 23:32:42 1997
@@ -539,6 +539,7 @@
.long sys_query_module
.long sys_poll
.long sys_nfsservctl
+ .long sys_prctl
.long sys_debug
- .space (NR_syscalls-170)*4
+ .space (NR_syscalls-171)*4

diff -urN linux-2.1.51/arch/sparc/kernel/systbls.S linux/arch/sparc/kernel/systbls.S
--- linux-2.1.51/arch/sparc/kernel/systbls.S Wed May 14 15:41:03 1997
+++ linux/arch/sparc/kernel/systbls.S Thu Aug 21 23:37:58 1997
@@ -125,6 +125,7 @@
.long C_LABEL(sys_fdatasync)
.long C_LABEL(sys_nfsservctl)
/*255*/ .long C_LABEL(sys_aplib)
+ .long C_LABEL(sys_prctl)
.long C_LABEL(sys_nis_syscall)

/* Now the SunOS syscall table. */
@@ -219,3 +220,4 @@
.long C_LABEL(sunos_nosys), C_LABEL(sunos_nosys)
/*250*/ .long C_LABEL(sunos_nosys), C_LABEL(sunos_nosys), C_LABEL(sunos_nosys)
.long C_LABEL(sunos_nosys), C_LABEL(sunos_nosys), C_LABEL(sys_aplib)
+ .long C_LABEL(sunos_nosys)
diff -urN linux-2.1.51/arch/sparc64/kernel/systbls.S linux/arch/sparc64/kernel/systbls.S
--- linux-2.1.51/arch/sparc64/kernel/systbls.S Tue Aug 19 11:52:13 1997
+++ linux/arch/sparc64/kernel/systbls.S Thu Aug 21 23:39:26 1997
@@ -68,7 +68,7 @@
/*240*/ .word sys_munlockall, sys32_sched_setparam, sys32_sched_getparam, sys_nis_syscall, sys_nis_syscall
.word sys_nis_syscall, sys_sched_get_priority_max, sys_sched_get_priority_min, sys32_sched_rr_get_interval, sys32_nanosleep
/*250*/ .word sys32_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys32_nfsservctl
- .word sys_aplib
+ .word sys_aplib, sys_prctl

/* Now the 64-bit native Linux syscall table. */

@@ -127,7 +127,7 @@
/*240*/ .word sys_munlockall, sys_sched_setparam, sys_sched_getparam, sys_nis_syscall, sys_nis_syscall
.word sys_nis_syscall, sys_sched_get_priority_max, sys_sched_get_priority_min, sys_sched_rr_get_interval, sys_nanosleep
/*250*/ .word sys_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
- .word sys_aplib
+ .word sys_aplib, sys_prctl

/* Now the 32-bit SunOS syscall table. */

@@ -221,3 +221,4 @@
.word sunos_nosys, sunos_nosys
/*250*/ .word sunos_nosys, sunos_nosys, sunos_nosys
.word sunos_nosys, sunos_nosys, sys_aplib
+ .word sunos_nosys
diff -urN linux-2.1.51/include/asm-alpha/unistd.h linux/include/asm-alpha/unistd.h
--- linux-2.1.51/include/asm-alpha/unistd.h Fri May 30 14:53:08 1997
+++ linux/include/asm-alpha/unistd.h Thu Aug 21 23:44:55 1997
@@ -285,6 +285,7 @@
#define __NR_pciconfig_read 345
#define __NR_pciconfig_write 346
#define __NR_query_module 347
+#define __NR_prctl 348

#if defined(__LIBRARY__) && defined(__GNUC__)

diff -urN linux-2.1.51/include/asm-i386/unistd.h linux/include/asm-i386/unistd.h
--- linux-2.1.51/include/asm-i386/unistd.h Fri Jun 27 05:33:39 1997
+++ linux/include/asm-i386/unistd.h Thu Aug 21 18:27:56 1997
@@ -177,6 +177,7 @@
#define __NR_nfsservctl 169
#define __NR_setresgid 170
#define __NR_getresgid 171
+#define __NR_prctl 172

/* user-visible error numbers are in the range -1 - -122: see <asm-i386/errno.h> */

diff -urN linux-2.1.51/include/asm-m68k/unistd.h linux/include/asm-m68k/unistd.h
--- linux-2.1.51/include/asm-m68k/unistd.h Fri May 30 14:53:08 1997
+++ linux/include/asm-m68k/unistd.h Thu Aug 21 23:24:51 1997
@@ -174,6 +174,7 @@
#define __NR_query_module 167
#define __NR_poll 168
#define __NR_nfsservctl 169
+#define __NR_prctl 170

/* user-visible error numbers are in the range -1 - -122: see
<asm-m68k/errno.h> */
diff -urN linux-2.1.51/include/asm-mips/unistd.h linux/include/asm-mips/unistd.h
--- linux-2.1.51/include/asm-mips/unistd.h Fri Aug 1 06:09:18 1997
+++ linux/include/asm-mips/unistd.h Thu Aug 21 23:26:59 1997
@@ -1179,11 +1179,12 @@
#define __NR_nfsservctl (__NR_Linux + 189)
#define __NR_setresgid (__NR_Linux + 190)
#define __NR_getresgid (__NR_Linux + 191)
+#define __NR_prctl (__NR_Linux + 192)

/*
* Offset of the last Linux flavoured syscall
*/
-#define __NR_Linux_syscalls 191
+#define __NR_Linux_syscalls 192

#ifndef __LANGUAGE_ASSEMBLY__

diff -urN linux-2.1.51/include/asm-ppc/unistd.h linux/include/asm-ppc/unistd.h
--- linux-2.1.51/include/asm-ppc/unistd.h Fri Aug 1 06:09:18 1997
+++ linux/include/asm-ppc/unistd.h Thu Aug 21 23:29:03 1997
@@ -174,6 +174,7 @@
#define __NR_query_module 166
#define __NR_poll 167
#define __NR_nfsservctl 168
+#define __NR_prctl 169

#define __NR(n) #n
#define __do_syscall(n) \
diff -urN linux-2.1.51/include/asm-sparc/unistd.h linux/include/asm-sparc/unistd.h
--- linux-2.1.51/include/asm-sparc/unistd.h Fri May 30 14:53:09 1997
+++ linux/include/asm-sparc/unistd.h Thu Aug 21 23:33:53 1997
@@ -272,6 +272,7 @@
#define __NR_fdatasync 253
#define __NR_nfsservctl 254
#define __NR_aplib 255
+#define __NR_prctl 256

#define _syscall0(type,name) \
type name(void) \
diff -urN linux-2.1.51/include/asm-sparc64/unistd.h linux/include/asm-sparc64/unistd.h
--- linux-2.1.51/include/asm-sparc64/unistd.h Fri Jun 27 05:33:40 1997
+++ linux/include/asm-sparc64/unistd.h Thu Aug 21 23:38:28 1997
@@ -272,6 +272,7 @@
#define __NR_fdatasync 253
#define __NR_nfsservctl 254
#define __NR_aplib 255
+#define __NR_prctl 256

#define _syscall0(type,name) \
type name(void) \
diff -urN linux-2.1.51/include/linux/prctl.h linux/include/linux/prctl.h
--- linux-2.1.51/include/linux/prctl.h Thu Jan 1 10:00:00 1970
+++ linux/include/linux/prctl.h Thu Aug 21 18:49:33 1997
@@ -0,0 +1,9 @@
+#ifndef _LINUX_PRCTL_H
+#define _LINUX_PRCTL_H
+
+/* Values to pass as first argument to prctl() */
+
+#define PR_SET_PDEATHSIG 1 /* Second arg is a signal */
+
+
+#endif /* _LINUX_PRCTL_H */
diff -urN linux-2.1.51/include/linux/sched.h linux/include/linux/sched.h
--- linux-2.1.51/include/linux/sched.h Tue Aug 19 12:03:30 1997
+++ linux/include/linux/sched.h Thu Aug 21 20:13:05 1997
@@ -191,6 +191,7 @@
struct task_struct *next_task, *prev_task;
struct task_struct *next_run, *prev_run;
int exit_code, exit_signal;
+ int pdeath_signal; /* The signal sent when the parent dies */
/* ??? */
unsigned long personality;
int dumpable:1;
@@ -312,7 +313,7 @@
/* exec domain */&default_exec_domain, \
/* binfmt */ NULL, \
/* schedlink */ &init_task,&init_task, &init_task, &init_task, \
-/* ec,brk... */ 0,0,0,0,0, \
+/* ec,brk... */ 0,0,0,0,0,0, \
/* pid etc.. */ 0,0,0,0,0, \
/* suppl grps*/ 0, {0,}, \
/* proc links*/ &init_task,&init_task,NULL,NULL,NULL, \
diff -urN linux-2.1.51/kernel/exit.c linux/kernel/exit.c
--- linux-2.1.51/kernel/exit.c Tue Aug 5 07:50:04 1997
+++ linux/kernel/exit.c Thu Aug 21 20:13:29 1997
@@ -348,7 +348,8 @@
for_each_task(p) {
if (p->p_opptr == father) {
p->exit_signal = SIGCHLD;
- p->p_opptr = task[smp_num_cpus] ? : task[0]; /* init */
+ p->p_opptr = task[smp_num_cpus] ? : task[0]; /* init */
+ if (p->pdeath_signal) send_sig(p->pdeath_signal, p, 0);
}
}
read_unlock(&tasklist_lock);
diff -urN linux-2.1.51/kernel/fork.c linux/kernel/fork.c
--- linux-2.1.51/kernel/fork.c Tue Aug 19 11:52:16 1997
+++ linux/kernel/fork.c Thu Aug 21 20:13:38 1997
@@ -473,6 +473,7 @@
/* ok, now we should be set up.. */
p->swappable = 1;
p->exit_signal = clone_flags & CSIGNAL;
+ p->pdeath_signal = 0;

/*
* "share" dynamic priority between parent and child, thus the
diff -urN linux-2.1.51/kernel/sys.c linux/kernel/sys.c
--- linux-2.1.51/kernel/sys.c Mon Jul 14 14:20:11 1997
+++ linux/kernel/sys.c Thu Aug 21 22:43:48 1997
@@ -25,6 +25,7 @@
#include <linux/smp_lock.h>
#include <linux/notifier.h>
#include <linux/reboot.h>
+#include <linux/prctl.h>

#include <asm/uaccess.h>
#include <asm/io.h>
@@ -1119,4 +1120,26 @@
{
mask = xchg(&current->fs->umask, mask & S_IRWXUGO);
return mask;
+}
+
+asmlinkage int sys_prctl(int option, unsigned long arg2, unsigned long arg3,
+ unsigned long arg4, unsigned long arg5)
+{
+ int error = 0;
+ int sig;
+
+ switch (option) {
+ case PR_SET_PDEATHSIG:
+ sig = arg2;
+ if (sig > _NSIG) {
+ error = -EINVAL;
+ break;
+ }
+ current->pdeath_signal = sig;
+ break;
+ default:
+ error = -EINVAL;
+ break;
+ }
+ return error;
}