Subversion Repositories mdb

Rev

Rev 21 | Rev 55 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 21 Rev 22
Line 20... Line 20...
20
#include <stdlib.h>
20
#include <stdlib.h>
21
#include <libgen.h>
21
#include <libgen.h>
22
#include <math.h>
22
#include <math.h>
23
#include <time.h>
23
#include <time.h>
24
#include <signal.h>
24
#include <signal.h>
-
 
25
#include <wait.h>
25
#include <syslog.h>
26
#include <syslog.h>
26
#include <errno.h>
27
#include <errno.h>
27
#include <pthread.h>
28
#include <pthread.h>
28
#include <sys/stat.h>
29
#include <sys/stat.h>
29
#include <sys/types.h>
30
#include <sys/types.h>
Line 44... Line 45...
44
 
45
 
45
#ifndef SIGCLD
46
#ifndef SIGCLD
46
#   define SIGCLD SIGCHLD
47
#   define SIGCLD SIGCHLD
47
#endif
48
#endif
48
 
49
 
49
static pthread_mutex_t fastmutex_proc = PTHREAD_MUTEX_INITIALIZER;
-
 
50
static pthread_t pthr_pars, pthr_wait;
50
static pthread_t pthr_pars;
51
struct SOCKETS soc;
51
struct SOCKETS soc;
52
 
52
 
53
/* Prototypes */
53
/* Prototypes */
54
void daemon_start(int ignsigcld);
54
void daemon_start(int ignsigcld);
55
void sig_child (int x);
55
void sig_child (int x);
Line 255... Line 255...
255
	length = sizeof(client1);
255
	length = sizeof(client1);
256
	syslog (LOG_DEBUG, "Server ready: %d",s);
256
	syslog (LOG_DEBUG, "Server ready: %d",s);
257
	
257
	
258
	while (1)
258
	while (1)
259
	{
259
	{
260
		int childpid;
260
		int childpid, status;
261
 
261
 
262
		if ((s1 = accept (s, (struct sockaddr *)&client1, &length)) < 0)
262
		if ((s1 = accept (s, (struct sockaddr *)&client1, &length)) < 0)
263
		{
263
		{
264
			syslog (LOG_DAEMON, "Error in accept: %d: %s", s1, strerror(errno));
264
			syslog (LOG_DAEMON, "Error in accept: %d: %s", s1, strerror(errno));
265
			continue;
265
			continue;
Line 277... Line 277...
277
		{
277
		{
278
			/* Child process */
278
			/* Child process */
279
			processCommands((void *)&soc);
279
			processCommands((void *)&soc);
280
			exit(EXIT_SUCCESS);
280
			exit(EXIT_SUCCESS);
281
		}
281
		}
282
		
-
 
283
		close(s1);
-
 
284
		
-
 
285
		if (pthread_create(&pthr_wait, NULL, thread_wait, NULL) != 0)
-
 
286
			syslog (LOG_DAEMON,"Create of thread \"pthr_wait\" failed: %s", strerror(errno));
-
 
287
	}
-
 
288
	
-
 
289
	close (s);
-
 
290
	return NULL;
-
 
291
}
-
 
292
 
282
 
293
void *thread_wait(void *pV_data)
-
 
294
{
-
 
295
	int status;
-
 
296
 
-
 
297
	pthread_mutex_lock (&fastmutex_proc);
-
 
298
#if defined(BSD) && !defined(Linux)
283
#if defined(BSD) && !defined(Linux)
299
	while (wait3 (&status, WNOHANG, (struct rusage *)0) <= 0)
284
		while (wait3 (&status, WNOHANG, (struct rusage *)0) > 0)
300
		sleep(1);
285
			sleep(1);
301
#else
286
#else
302
	while (waitpid(-1, &status, WNOHANG) <= 0)
287
		while (waitpid(-1, &status, WNOHANG) > 0)
303
		sleep(1);
288
			sleep(1);
304
#endif
289
#endif
305
	pthread_mutex_unlock(&fastmutex_proc);
290
		close(s1);
-
 
291
	}
-
 
292
	
-
 
293
	close (s);
306
	return NULL;
294
	return NULL;
307
}
295
}