New libary functions.

Cleanup of halt.c.
This commit is contained in:
Jorrit Herder 2005-10-12 15:10:14 +00:00
parent 7842d4fb26
commit eb5ed13fd3
10 changed files with 101 additions and 23 deletions

View file

@ -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,16 +117,16 @@ char **argv;
default:
while (waitpid(pid, NULL, 0) != pid) {}
}
/* 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);
}
/* 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);
sync();
reboot(flag, monitor_code, strlen(monitor_code));

View file

@ -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

11
lib/other/_getnpid.c Normal file
View file

@ -0,0 +1,11 @@
#include <lib.h>
#define getnpid _getnpid
#include <unistd.h>
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 */
}

14
lib/other/_getnprocnr.c Normal file
View file

@ -0,0 +1,14 @@
#include <lib.h>
#define getnprocnr _getnprocnr
#include <unistd.h>
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 */
}

14
lib/other/_getpprocnr.c Normal file
View file

@ -0,0 +1,14 @@
#include <lib.h>
#define getpprocnr _getpprocnr
#include <unistd.h>
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 */
}

View file

@ -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 */
}

View file

@ -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

7
lib/syscall/getnpid.s Normal file
View file

@ -0,0 +1,7 @@
.sect .text
.extern __getnpid
.define _getnpid
.align 2
_getnpid:
jmp __getnpid

7
lib/syscall/getnprocnr.s Normal file
View file

@ -0,0 +1,7 @@
.sect .text
.extern __getnprocnr
.define _getnprocnr
.align 2
_getnprocnr:
jmp __getnprocnr

7
lib/syscall/getpprocnr.s Normal file
View file

@ -0,0 +1,7 @@
.sect .text
.extern __getpprocnr
.define _getpprocnr
.align 2
_getpprocnr:
jmp __getpprocnr