1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00

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>
This commit is contained in:
Volker Lendecke 2014-03-03 11:57:18 +00:00 committed by Michael Adam
parent ccc187ff5e
commit 7e12bfc6a8

View File

@ -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");