aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2005-01-04 22:30:15 +0000
committerrsc <devnull@localhost>2005-01-04 22:30:15 +0000
commit48bfee4e5b72db021da3538c97ef68ce2308f12b (patch)
tree39631b3b4f042d0f52ec5d61d715775aca465702 /src
parentc7acb53e0384f6b091fdfea3c74c4034d9f4cf1b (diff)
downloadplan9port-48bfee4e5b72db021da3538c97ef68ce2308f12b.tar.gz
plan9port-48bfee4e5b72db021da3538c97ef68ce2308f12b.tar.bz2
plan9port-48bfee4e5b72db021da3538c97ef68ce2308f12b.zip
in with the new
Diffstat (limited to 'src')
-rw-r--r--src/lib9/_p9proc-Linux.c5
-rw-r--r--src/lib9/_p9proc-getpid.c113
-rw-r--r--src/lib9/_p9proc.c113
-rw-r--r--src/lib9/execl.c29
4 files changed, 29 insertions, 231 deletions
diff --git a/src/lib9/_p9proc-Linux.c b/src/lib9/_p9proc-Linux.c
deleted file mode 100644
index 902a9579..00000000
--- a/src/lib9/_p9proc-Linux.c
+++ /dev/null
@@ -1,5 +0,0 @@
-#ifdef __Linux26__
-#include "_p9proc-pthread.c"
-#else
-#include "_p9proc-getpid.c"
-#endif
diff --git a/src/lib9/_p9proc-getpid.c b/src/lib9/_p9proc-getpid.c
deleted file mode 100644
index 9543bf24..00000000
--- a/src/lib9/_p9proc-getpid.c
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * This needs to be callable from a signal handler, so it has been
- * written to avoid locks. The only lock is the one used to acquire
- * an entry in the table, and we make sure that acquiring is done
- * when not in a handler. Lookup and delete do not need locks.
- * It's a scan-forward hash table. To avoid breaking chains,
- * T ((void*)-1) is used as a non-breaking nil.
- */
-
-#include <u.h>
-#include <libc.h>
-#include "9proc.h"
-
-enum { PIDHASH = 1021 };
-
-#define T ((void*)-1)
-static Uproc *alluproc[PIDHASH];
-static int allupid[PIDHASH];
-static Lock uproclock;
-
-void
-_clearuproc(void)
-{
- int i;
-
- /* called right after fork - no locking needed */
- for(i=0; i<PIDHASH; i++)
- if(alluproc[i] != T && alluproc[i] != 0)
- free(alluproc[i]);
- memset(alluproc, 0, sizeof alluproc);
- memset(allupid, 0, sizeof allupid);
-}
-
-Uproc*
-_p9uproc(int inhandler)
-{
- int i, h, pid;
- Uproc *up;
-
- /* for now, assume getpid is fast or cached */
- pid = getpid();
-
- /*
- * this part - the lookup - needs to run without locks
- * so that it can safely be called from within the notify handler.
- * notify calls _p9uproc, and fork and rfork call _p9uproc
- * in both parent and child, so if we're in a signal handler,
- * we should find something in the table.
- */
- h = pid%PIDHASH;
- for(i=0; i<PIDHASH; i++){
- up = alluproc[h];
- if(up == nil)
- break;
- if(allupid[h] == pid)
- return up;
- if(++h == PIDHASH)
- h = 0;
- }
-
- if(inhandler){
- fprint(2, "%s: did not find uproc for pid %d in signal handler\n", argv0, pid);
- abort();
- }
-
- /* need to allocate */
- while((up = mallocz(sizeof(Uproc), 1)) == nil)
- sleep(1000);
-
- /* fprint(2, "alloc uproc for pid %d\n", pid); */
- up->pid = pid;
- lock(&uproclock);
- h = pid%PIDHASH;
- for(i=0; i<PIDHASH; i++){
- if(alluproc[h]==T || alluproc[h]==nil){
- alluproc[h] = up;
- allupid[h] = pid;
- unlock(&uproclock);
- return up;
- }
- if(++h == PIDHASH)
- h = 0;
- }
- unlock(&uproclock);
-
- /* out of pids! */
- sysfatal("too many processes in uproc table");
- return nil;
-}
-
-void
-_p9uprocdie(void)
-{
- Uproc *up;
- int pid, i, h;
-
- pid = getpid();
- /* fprint(2, "reap uproc for pid %d\n", pid); */
- h = pid%PIDHASH;
- for(i=0; i<PIDHASH; i++){
- up = alluproc[h];
- if(up == nil)
- break;
- if(up == T)
- continue;
- if(allupid[h] == pid){
- up = alluproc[h];
- alluproc[h] = T;
- free(up);
- allupid[h] = 0;
- }
- }
-}
diff --git a/src/lib9/_p9proc.c b/src/lib9/_p9proc.c
deleted file mode 100644
index 9543bf24..00000000
--- a/src/lib9/_p9proc.c
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * This needs to be callable from a signal handler, so it has been
- * written to avoid locks. The only lock is the one used to acquire
- * an entry in the table, and we make sure that acquiring is done
- * when not in a handler. Lookup and delete do not need locks.
- * It's a scan-forward hash table. To avoid breaking chains,
- * T ((void*)-1) is used as a non-breaking nil.
- */
-
-#include <u.h>
-#include <libc.h>
-#include "9proc.h"
-
-enum { PIDHASH = 1021 };
-
-#define T ((void*)-1)
-static Uproc *alluproc[PIDHASH];
-static int allupid[PIDHASH];
-static Lock uproclock;
-
-void
-_clearuproc(void)
-{
- int i;
-
- /* called right after fork - no locking needed */
- for(i=0; i<PIDHASH; i++)
- if(alluproc[i] != T && alluproc[i] != 0)
- free(alluproc[i]);
- memset(alluproc, 0, sizeof alluproc);
- memset(allupid, 0, sizeof allupid);
-}
-
-Uproc*
-_p9uproc(int inhandler)
-{
- int i, h, pid;
- Uproc *up;
-
- /* for now, assume getpid is fast or cached */
- pid = getpid();
-
- /*
- * this part - the lookup - needs to run without locks
- * so that it can safely be called from within the notify handler.
- * notify calls _p9uproc, and fork and rfork call _p9uproc
- * in both parent and child, so if we're in a signal handler,
- * we should find something in the table.
- */
- h = pid%PIDHASH;
- for(i=0; i<PIDHASH; i++){
- up = alluproc[h];
- if(up == nil)
- break;
- if(allupid[h] == pid)
- return up;
- if(++h == PIDHASH)
- h = 0;
- }
-
- if(inhandler){
- fprint(2, "%s: did not find uproc for pid %d in signal handler\n", argv0, pid);
- abort();
- }
-
- /* need to allocate */
- while((up = mallocz(sizeof(Uproc), 1)) == nil)
- sleep(1000);
-
- /* fprint(2, "alloc uproc for pid %d\n", pid); */
- up->pid = pid;
- lock(&uproclock);
- h = pid%PIDHASH;
- for(i=0; i<PIDHASH; i++){
- if(alluproc[h]==T || alluproc[h]==nil){
- alluproc[h] = up;
- allupid[h] = pid;
- unlock(&uproclock);
- return up;
- }
- if(++h == PIDHASH)
- h = 0;
- }
- unlock(&uproclock);
-
- /* out of pids! */
- sysfatal("too many processes in uproc table");
- return nil;
-}
-
-void
-_p9uprocdie(void)
-{
- Uproc *up;
- int pid, i, h;
-
- pid = getpid();
- /* fprint(2, "reap uproc for pid %d\n", pid); */
- h = pid%PIDHASH;
- for(i=0; i<PIDHASH; i++){
- up = alluproc[h];
- if(up == nil)
- break;
- if(up == T)
- continue;
- if(allupid[h] == pid){
- up = alluproc[h];
- alluproc[h] = T;
- free(up);
- allupid[h] = 0;
- }
- }
-}
diff --git a/src/lib9/execl.c b/src/lib9/execl.c
new file mode 100644
index 00000000..988d2072
--- /dev/null
+++ b/src/lib9/execl.c
@@ -0,0 +1,29 @@
+#include <u.h>
+#include <libc.h>
+
+int
+execl(char *prog, ...)
+{
+ int i;
+ va_list arg;
+ char **argv;
+
+ va_start(arg, prog);
+ for(i=0; va_arg(arg, char*) != nil; i++)
+ ;
+ va_end(arg);
+
+ argv = malloc((i+1)*sizeof(char*));
+ if(argv == nil)
+ return -1;
+
+ va_start(arg, prog);
+ for(i=0; (argv[i] = va_arg(arg, char*)) != nil; i++)
+ ;
+ va_end(arg);
+
+ exec(prog, argv);
+ free(argv);
+ return -1;
+}
+