]> Zhao Yanbai Git Server - minix.git/commitdiff
New libary functions.
authorJorrit Herder <jnherder@minix3.org>
Wed, 12 Oct 2005 15:10:14 +0000 (15:10 +0000)
committerJorrit Herder <jnherder@minix3.org>
Wed, 12 Oct 2005 15:10:14 +0000 (15:10 +0000)
Cleanup of halt.c.

commands/reboot/halt.c
lib/other/Makefile
lib/other/_getnpid.c [new file with mode: 0644]
lib/other/_getnprocnr.c [new file with mode: 0644]
lib/other/_getpprocnr.c [new file with mode: 0644]
lib/other/_getprocnr.c
lib/syscall/Makefile
lib/syscall/getnpid.s [new file with mode: 0644]
lib/syscall/getnprocnr.s [new file with mode: 0644]
lib/syscall/getpprocnr.s [new file with mode: 0644]

index 13a43708f098f9640ef2bd85287c0e061cc096f3..38d36a9eee15af1861dcf606e5de552e5332f284 100755 (executable)
@@ -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();
 
index d03376e8141c0f46a4e6410c7a6d2b267131ce5f..42291caac13524a4e42eb957585d40c5a236e597 100755 (executable)
@@ -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 (file)
index 0000000..f9c03c2
--- /dev/null
@@ -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 */
+}
diff --git a/lib/other/_getnprocnr.c b/lib/other/_getnprocnr.c
new file mode 100644 (file)
index 0000000..0dde289
--- /dev/null
@@ -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 */
+}
+
diff --git a/lib/other/_getpprocnr.c b/lib/other/_getpprocnr.c
new file mode 100644 (file)
index 0000000..7ff8500
--- /dev/null
@@ -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 */
+}
+
index 3b1b924462b57751565b40f16dd57400e7655c5e..fa920c85f3e234df8a1f4a06c2732999158dea68 100644 (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 */
 }
 
index 50a3e1cc3ef1513c8c936ccbea952abbd01657e0..1a27b8ea3d69237d6f67c5bd775696b735b1e8a4 100755 (executable)
@@ -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 (file)
index 0000000..4547f01
--- /dev/null
@@ -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 (file)
index 0000000..482187b
--- /dev/null
@@ -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 (file)
index 0000000..009e063
--- /dev/null
@@ -0,0 +1,7 @@
+.sect .text
+.extern        __getpprocnr
+.define        _getpprocnr
+.align 2
+
+_getpprocnr:
+       jmp     __getpprocnr