diff options
| author | Sam Varshavchik | 2020-10-28 21:25:13 -0400 | 
|---|---|---|
| committer | Sam Varshavchik | 2020-10-28 21:25:13 -0400 | 
| commit | 0d4feee51d2c360c8f061c823b441afefddd07df (patch) | |
| tree | 57ee4374955a641250b523292363404f920b185a /waitlib/testwait.c | |
| parent | 6441fb0adc939f73f75fc1b03ee7f42bd57a1b2b (diff) | |
| download | courier-libs-0d4feee51d2c360c8f061c823b441afefddd07df.tar.bz2 | |
Fix LTO problem on Fedora
Diffstat (limited to 'waitlib/testwait.c')
| -rw-r--r-- | waitlib/testwait.c | 29 | 
1 files changed, 16 insertions, 13 deletions
| diff --git a/waitlib/testwait.c b/waitlib/testwait.c index 6020c36..a720e49 100644 --- a/waitlib/testwait.c +++ b/waitlib/testwait.c @@ -17,17 +17,13 @@  #define	NUMCHILDREN	100		/* Start 100 child processes */  #define	INITCHILDREN	10		/* Start with these many child procs */ -pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; -pthread_cond_t cond = PTHREAD_COND_INITIALIZER; - -static unsigned started, finished; +static unsigned started; +static int reap_pipefd[2];  static void reap_child(pid_t p, int dummy)  { -	pthread_mutex_lock(&mutex); -	++finished; -	pthread_cond_signal(&cond); -	pthread_mutex_unlock(&mutex); +	if (write(reap_pipefd[1], "", 1) < 0) +		; /* shut up gcc */  }  static RETSIGTYPE sighandler(int sig) @@ -65,8 +61,9 @@ int	main()  int	pipefd[2];  int	pipefd2[2];  char	c; +unsigned finished=0; -	if (pipe(pipefd) || pipe(pipefd2)) +	if (pipe(reap_pipefd) || pipe(pipefd) || pipe(pipefd2))  	{  		perror("pipe");  		exit(1); @@ -74,7 +71,7 @@ char	c;  	signal(SIGCHLD, sighandler); -	started=finished=0; +	started=0;  	while (started < INITCHILDREN)  	{  		if (start_child() == 0) @@ -99,11 +96,17 @@ char	c;  			_exit(0);  	alarm(30); -	pthread_mutex_lock(&mutex);  	while (finished < started)  	{ -		pthread_cond_wait(&cond, &mutex); +		char c; +		int n=read(reap_pipefd[0], &c, 1); + +		if (n <= 0) +		{ +			fprintf(stderr, "pipe error\n"); +			exit(1); +		} +		++finished;  	} -	pthread_mutex_unlock(&mutex);  	exit(0);  } | 
