diff options
author | Volker Lendecke <vl@samba.org> | 2014-03-03 11:57:18 +0000 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2014-03-03 14:31:33 +0100 |
commit | 7e12bfc6a8fe97da907525ae90288e37c4fa7a7f (patch) | |
tree | d61d7d6a13254c3c0a0668d017a06786e023b5fd /source3/lib | |
parent | ccc187ff5e6cbc411476c5f5e68cc6bb1fe35818 (diff) | |
download | samba-7e12bfc6a8fe97da907525ae90288e37c4fa7a7f.tar.gz samba-7e12bfc6a8fe97da907525ae90288e37c4fa7a7f.tar.xz samba-7e12bfc6a8fe97da907525ae90288e37c4fa7a7f.zip |
pthreadpool: Add test for fork crash
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Kamen Mazdrashki <kamenim@samba.org>
Reviewed-by: Simo Sorce <simo@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
Diffstat (limited to 'source3/lib')
-rw-r--r-- | source3/lib/pthreadpool/tests.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/source3/lib/pthreadpool/tests.c b/source3/lib/pthreadpool/tests.c index 95d37b6f170..170cedf07f7 100644 --- a/source3/lib/pthreadpool/tests.c +++ b/source3/lib/pthreadpool/tests.c @@ -5,6 +5,8 @@ #include <stdlib.h> #include <pthread.h> #include <unistd.h> +#include <sys/types.h> +#include <sys/wait.h> #include "pthreadpool.h" static int test_init(void) @@ -318,6 +320,46 @@ static int test_threaded_addjob(int num_pools, int num_threads, int poolsize, return 0; } +static int test_fork(void) +{ + struct pthreadpool *p; + pid_t child, waited; + int status, ret; + + ret = pthreadpool_init(1, &p); + if (ret != 0) { + fprintf(stderr, "pthreadpool_init failed: %s\n", + strerror(ret)); + return -1; + } + ret = pthreadpool_destroy(p); + if (ret != 0) { + fprintf(stderr, "pthreadpool_destroy failed: %s\n", + strerror(ret)); + return -1; + } + + child = fork(); + if (child < 0) { + perror("fork failed"); + return -1; + } + if (child == 0) { + exit(0); + } + waited = wait(&status); + if (waited == -1) { + perror("wait failed"); + return -1; + } + if (waited != child) { + fprintf(stderr, "expected child %d, got %d\n", + (int)child, (int)waited); + return -1; + } + return 0; +} + int main(void) { int ret; @@ -328,6 +370,12 @@ int main(void) return 1; } + ret = test_fork(); + if (ret != 0) { + fprintf(stderr, "test_fork failed\n"); + return 1; + } + ret = test_jobs(10, 10000); if (ret != 0) { fprintf(stderr, "test_jobs failed\n"); |