tmore tests - plan9port - [fork] Plan 9 from user space
 (HTM) git clone git://src.adamsgaard.dk/plan9port
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit f6127ed2092be2bf08481766a2c23dee6b955437
 (DIR) parent ed01060152eba67eaa0f16605563c2de333d938d
 (HTM) Author: rsc <devnull@localhost>
       Date:   Tue,  4 Jan 2005 22:15:53 +0000
       
       more tests
       
       Diffstat:
         A src/libthread/test/rdaemon.c        |      96 +++++++++++++++++++++++++++++++
         M src/libthread/test/tdaemon.c        |       9 +++++++--
         A src/libthread/test/texit.c          |      18 ++++++++++++++++++
         M src/libthread/test/tprimes.c        |       8 ++++++++
         M src/libthread/test/tspawnloop.c     |       2 +-
       
       5 files changed, 130 insertions(+), 3 deletions(-)
       ---
 (DIR) diff --git a/src/libthread/test/rdaemon.c b/src/libthread/test/rdaemon.c
       t@@ -0,0 +1,96 @@
       +#include <stdlib.h>
       +#include <stdio.h>
       +#include <unistd.h>
       +#include <sys/wait.h>
       +#include <pthread.h>
       +
       +#undef waitpid
       +#undef pipe
       +#undef wait
       +
       +static int sigpid;
       +static void
       +sigenable(int sig, int enabled)
       +{
       +        sigset_t mask;
       +        sigemptyset(&mask);
       +        sigaddset(&mask, sig);
       +        sigprocmask(enabled ? SIG_UNBLOCK : SIG_BLOCK, &mask, 0);
       +}
       +
       +static void
       +child(void)
       +{
       +        int status, pid;
       +printf("wait %d in %d\n", sigpid, getpid());
       +        pid = waitpid(sigpid, &status, __WALL);
       +        if(pid < 0)
       +                perror("wait");
       +        else if(WIFEXITED(status))
       +                 _exit(WEXITSTATUS(status));
       +printf("pid %d if %d %d\n", pid, WIFEXITED(status), WEXITSTATUS(status));
       +        _exit(97);
       +}
       +
       +static void
       +sigpass(int sig)
       +{
       +        if(sig == SIGCHLD){
       +print("sig\n");
       +                child();
       +        }else
       +                kill(sigpid, sig);
       +}
       +
       +void
       +_threadsetupdaemonize(void)
       +{
       +        int i, n, pid;
       +        int p[2];
       +        char buf[20];
       +
       +        sigpid = 1;
       +
       +        if(pipe(p) < 0)
       +                abort();
       +
       +        signal(SIGCHLD, sigpass);
       +        switch(pid = fork()){
       +        case -1:
       +                abort();
       +        default:
       +                close(p[1]);
       +                break;
       +        case 0:
       +                close(p[0]);
       +                return;
       +        }
       +
       +        sigpid = pid;
       +
       +        read(p[0], buf, sizeof buf-1);
       +print("pipe\n");
       +        child();
       +}
       +
       +void*
       +sleeper(void *v)
       +{
       +        pthread_mutex_t m;
       +        pthread_cond_t c;
       +
       +        pthread_mutex_init(&m, 0);
       +        pthread_cond_init(&c, 0);
       +        pthread_cond_wait(&c, &m);
       +        return 0;
       +}
       +
       +void
       +main(int argc, char **argv)
       +{
       +        pthread_t pid;
       +
       +        _threadsetupdaemonize();
       +        pthread_create(&pid, 0, sleeper, 0);
       +        exit(1);
       +}
 (DIR) diff --git a/src/libthread/test/tdaemon.c b/src/libthread/test/tdaemon.c
       t@@ -3,9 +3,14 @@
        #include <thread.h>
        
        void
       -threadmain(int argc, char **argv)
       +proc(void *v)
        {
       -        threaddaemonize();
                sleep(5*1000);
                print("still running\n");
        }
       +
       +void
       +threadmain(int argc, char **argv)
       +{
       +        proccreate(proc, nil, 32768);
       +}
 (DIR) diff --git a/src/libthread/test/texit.c b/src/libthread/test/texit.c
       t@@ -0,0 +1,18 @@
       +#include <u.h>
       +#include <libc.h>
       +#include <thread.h>
       +
       +void
       +f(void *v)
       +{
       +        USED(v);
       +
       +        recvp(chancreate(sizeof(void*), 0));
       +}
       +
       +void
       +threadmain(int argc, char **argv)
       +{
       +        proccreate(f, nil, 32000);
       +        exit(1);
       +}
 (DIR) diff --git a/src/libthread/test/tprimes.c b/src/libthread/test/tprimes.c
       t@@ -9,6 +9,7 @@ enum
        
        int max = 10000;
        int (*mk)(void (*fn)(void*), void *arg, uint stack);
       +void printmsg(void*, char*);
        
        void
        countthread(void *v)
       t@@ -55,6 +56,7 @@ threadmain(int argc, char **argv)
                Channel *c;
                int nbuf;
        
       +        notify(printmsg);
                nbuf = 0;
                mk = threadcreate;
                ARGBEGIN{
       t@@ -79,3 +81,9 @@ threadmain(int argc, char **argv)
                mk(filterthread, c, STACK);
                recvp(chancreate(sizeof(void*), 0));
        }
       +
       +void
       +printmsg(void *v, char *msg)
       +{
       +        print("note: %s\n", msg);
       +}
 (DIR) diff --git a/src/libthread/test/tspawnloop.c b/src/libthread/test/tspawnloop.c
       t@@ -18,7 +18,7 @@ execproc(void *v)
                args[2] = nil;
                threadexec(nil, fd, args[0], args);
        }
       -        
       +
        void
        threadmain(int argc, char **argv)
        {