From: Jorrit Herder Date: Wed, 12 Oct 2005 15:10:14 +0000 (+0000) Subject: New libary functions. X-Git-Tag: v3.1.2a~632 X-Git-Url: http://zhaoyanbai.com/repos/man.dig.html?a=commitdiff_plain;h=eb5ed13fd3ab614812ab877f7d3905f2ccf966b4;p=minix.git New libary functions. Cleanup of halt.c. --- diff --git a/commands/reboot/halt.c b/commands/reboot/halt.c index 13a43708f..38d36a9ee 100755 --- a/commands/reboot/halt.c +++ b/commands/reboot/halt.c @@ -99,18 +99,12 @@ char **argv; write_log(); - if (fast) { - /* But not too fast... */ - signal(SIGTERM, SIG_IGN); - kill(1, SIGTERM); - printf("Sending SIGTERM to all processes ...\n"); - kill(-1, SIGTERM); - sleep(1); - } else { - /* Run the shutdown scripts. */ - signal(SIGHUP, SIG_IGN); - signal(SIGTERM, SIG_IGN); + signal(SIGHUP, SIG_IGN); + signal(SIGTERM, SIG_IGN); + /* Skip this part for fast shut down. */ + if (! fast) { + /* Run the shutdown scripts. */ switch ((pid = fork())) { case -1: fprintf(stderr, "%s: can't fork(): %s\n", prog, strerror(errno)); @@ -123,15 +117,15 @@ char **argv; default: while (waitpid(pid, NULL, 0) != pid) {} } + } - /* Tell init to stop spawning getty's. */ - kill(1, SIGTERM); + /* Tell init to stop spawning getty's. */ + kill(1, SIGTERM); - /* Give everybody a chance to die peacefully. */ - printf("Sending SIGTERM to all processes ...\n"); - kill(-1, SIGTERM); - sleep(2); - } + /* Give everybody a chance to die peacefully. */ + printf("Sending SIGTERM to all processes ...\n"); + kill(-1, SIGTERM); + sleep(2); sync(); diff --git a/lib/other/Makefile b/lib/other/Makefile index d03376e81..42291caac 100755 --- a/lib/other/Makefile +++ b/lib/other/Makefile @@ -18,6 +18,9 @@ OBJECTS = \ $(LIBRARY)(_svrctl.o) \ $(LIBRARY)(_getsysinfo.o) \ $(LIBRARY)(_getprocnr.o) \ + $(LIBRARY)(_getpprocnr.o) \ + $(LIBRARY)(_getnprocnr.o) \ + $(LIBRARY)(_getnpid.o) \ $(LIBRARY)(_devctl.o) \ $(LIBRARY)(_findproc.o) \ $(LIBRARY)(asynchio.o) \ @@ -97,9 +100,18 @@ $(LIBRARY)(_svrctl.o): _svrctl.c $(LIBRARY)(_devctl.o): _devctl.c $(CC1) _devctl.c +$(LIBRARY)(_getnpid.o): _getnpid.c + $(CC1) _getnpid.c + $(LIBRARY)(_getprocnr.o): _getprocnr.c $(CC1) _getprocnr.c +$(LIBRARY)(_getpprocnr.o): _getpprocnr.c + $(CC1) _getpprocnr.c + +$(LIBRARY)(_getnprocnr.o): _getnprocnr.c + $(CC1) _getnprocnr.c + $(LIBRARY)(_findproc.o): _findproc.c $(CC1) _findproc.c diff --git a/lib/other/_getnpid.c b/lib/other/_getnpid.c new file mode 100644 index 000000000..f9c03c27e --- /dev/null +++ b/lib/other/_getnpid.c @@ -0,0 +1,11 @@ +#include +#define getnpid _getnpid +#include + +PUBLIC pid_t getnpid(int proc_nr) +{ + message m; + m.m1_i1 = proc_nr; /* search pid for this process */ + if (_syscall(MM, GETPID, &m) < 0) return ( (pid_t) -1); + return( (pid_t) m.m2_i2); /* return search result */ +} diff --git a/lib/other/_getnprocnr.c b/lib/other/_getnprocnr.c new file mode 100644 index 000000000..0dde28922 --- /dev/null +++ b/lib/other/_getnprocnr.c @@ -0,0 +1,14 @@ +#include +#define getnprocnr _getnprocnr +#include + + +PUBLIC int getnprocnr(pid_t pid) +{ + message m; + m.m1_i1 = pid; /* pass pid >=0 to search for */ + m.m1_i2 = 0; /* don't pass name to search for */ + if (_syscall(PM_PROC_NR, GETPROCNR, &m) < 0) return(-1); + return(m.m1_i1); /* return search result */ +} + diff --git a/lib/other/_getpprocnr.c b/lib/other/_getpprocnr.c new file mode 100644 index 000000000..7ff85005a --- /dev/null +++ b/lib/other/_getpprocnr.c @@ -0,0 +1,14 @@ +#include +#define getpprocnr _getpprocnr +#include + + +PUBLIC int getpprocnr() +{ + message m; + m.m1_i1 = -1; /* don't pass pid to search for */ + m.m1_i2 = 0; /* don't pass name to search for */ + if (_syscall(PM_PROC_NR, GETPROCNR, &m) < 0) return(-1); + return(m.m1_i2); /* return parent process number */ +} + diff --git a/lib/other/_getprocnr.c b/lib/other/_getprocnr.c index 3b1b92446..fa920c85f 100644 --- a/lib/other/_getprocnr.c +++ b/lib/other/_getprocnr.c @@ -6,9 +6,9 @@ PUBLIC int getprocnr() { message m; - m.m1_i1 = -1; /* get own process number */ - m.m1_i2 = 0; /* get own process number */ - if (_syscall(MM, GETPROCNR, &m) < 0) return(-1); - return(m.m1_i1); + m.m1_i1 = -1; /* don't pass pid to search for */ + m.m1_i2 = 0; /* don't pass name to search for */ + if (_syscall(PM_PROC_NR, GETPROCNR, &m) < 0) return(-1); + return(m.m1_i1); /* return own process number */ } diff --git a/lib/syscall/Makefile b/lib/syscall/Makefile index 50a3e1cc3..1a27b8ea3 100755 --- a/lib/syscall/Makefile +++ b/lib/syscall/Makefile @@ -44,9 +44,12 @@ OBJECTS = \ $(LIBRARY)(getgroups.o) \ $(LIBRARY)(getpgrp.o) \ $(LIBRARY)(getpid.o) \ + $(LIBRARY)(getnpid.o) \ $(LIBRARY)(getppid.o) \ $(LIBRARY)(getuid.o) \ $(LIBRARY)(getprocnr.o) \ + $(LIBRARY)(getpprocnr.o) \ + $(LIBRARY)(getnprocnr.o) \ $(LIBRARY)(getsysinfo.o) \ $(LIBRARY)(findproc.o) \ $(LIBRARY)(ioctl.o) \ @@ -226,6 +229,9 @@ $(LIBRARY)(getpgrp.o): getpgrp.s $(LIBRARY)(getpid.o): getpid.s $(CC1) getpid.s +$(LIBRARY)(getnpid.o): getnpid.s + $(CC1) getnpid.s + $(LIBRARY)(getppid.o): getppid.s $(CC1) getppid.s @@ -235,6 +241,12 @@ $(LIBRARY)(getsysinfo.o): getsysinfo.s $(LIBRARY)(getprocnr.o): getprocnr.s $(CC1) getprocnr.s +$(LIBRARY)(getnprocnr.o): getnprocnr.s + $(CC1) getnprocnr.s + +$(LIBRARY)(getpprocnr.o): getpprocnr.s + $(CC1) getpprocnr.s + $(LIBRARY)(findproc.o): findproc.s $(CC1) findproc.s diff --git a/lib/syscall/getnpid.s b/lib/syscall/getnpid.s new file mode 100644 index 000000000..4547f01fc --- /dev/null +++ b/lib/syscall/getnpid.s @@ -0,0 +1,7 @@ +.sect .text +.extern __getnpid +.define _getnpid +.align 2 + +_getnpid: + jmp __getnpid diff --git a/lib/syscall/getnprocnr.s b/lib/syscall/getnprocnr.s new file mode 100644 index 000000000..482187b3e --- /dev/null +++ b/lib/syscall/getnprocnr.s @@ -0,0 +1,7 @@ +.sect .text +.extern __getnprocnr +.define _getnprocnr +.align 2 + +_getnprocnr: + jmp __getnprocnr diff --git a/lib/syscall/getpprocnr.s b/lib/syscall/getpprocnr.s new file mode 100644 index 000000000..009e063fb --- /dev/null +++ b/lib/syscall/getpprocnr.s @@ -0,0 +1,7 @@ +.sect .text +.extern __getpprocnr +.define _getpprocnr +.align 2 + +_getpprocnr: + jmp __getpprocnr