Subversion Repositories mdb

Rev

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

Rev 22 Rev 55
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
#ifndef __APPLE__
25
#include <wait.h>
26
#include <wait.h>
-
 
27
#endif
26
#include <syslog.h>
28
#include <syslog.h>
27
#include <errno.h>
29
#include <errno.h>
28
#include <pthread.h>
30
#include <pthread.h>
29
#include <sys/stat.h>
31
#include <sys/stat.h>
30
#include <sys/types.h>
32
#include <sys/types.h>
Line 45... Line 47...
45
 
47
 
46
#ifndef SIGCLD
48
#ifndef SIGCLD
47
#   define SIGCLD SIGCHLD
49
#   define SIGCLD SIGCHLD
48
#endif
50
#endif
49
 
51
 
50
static pthread_t pthr_pars;
52
static pthread_t pthr_pars, pthr_cmds;
51
struct SOCKETS soc;
53
struct SOCKETS soc;
52
 
54
 
53
/* Prototypes */
55
/* Prototypes */
54
void daemon_start(int ignsigcld);
56
void daemon_start(int ignsigcld);
55
void sig_child (int x);
57
void sig_child (int x);
Line 255... Line 257...
255
	length = sizeof(client1);
257
	length = sizeof(client1);
256
	syslog (LOG_DEBUG, "Server ready: %d",s);
258
	syslog (LOG_DEBUG, "Server ready: %d",s);
257
	
259
	
258
	while (1)
260
	while (1)
259
	{
261
	{
260
		int childpid, status;
262
/*		int childpid, status; */
261
 
263
 
262
		if ((s1 = accept (s, (struct sockaddr *)&client1, &length)) < 0)
264
		if ((s1 = accept (s, (struct sockaddr *)&client1, &length)) < 0)
263
		{
265
		{
264
			syslog (LOG_DAEMON, "Error in accept: %d: %s", s1, strerror(errno));
266
			syslog (LOG_DAEMON, "Error in accept: %d: %s", s1, strerror(errno));
265
			continue;
267
			continue;
Line 268... Line 270...
268
		inet_ntop(AF_INET, &(client1.sin_addr), str, INET_ADDRSTRLEN);
270
		inet_ntop(AF_INET, &(client1.sin_addr), str, INET_ADDRSTRLEN);
269
		syslog (LOG_INFO, "Connected to client %s", str);
271
		syslog (LOG_INFO, "Connected to client %s", str);
270
		soc.sockfd = s;
272
		soc.sockfd = s;
271
		soc.newfd = s1;
273
		soc.newfd = s1;
272
 
274
 
-
 
275
		/* start a new thread to parse the commands */
-
 
276
		if (pthread_create(&pthr_cmds, NULL, processCommands, (void *)&soc) != 0)
-
 
277
		{
-
 
278
			syslog (LOG_DAEMON,"Creation of thread \"pthr_cmds\" failed!");
-
 
279
			close(s1);
-
 
280
			close(s);
-
 
281
			return NULL;
-
 
282
		}
-
 
283
 
273
		if ((childpid = fork()) < 0)
284
/*		if ((childpid = fork()) < 0)
274
			syslog(LOG_DAEMON, "Can't fork a child: %s", strerror(errno));
285
			syslog(LOG_DAEMON, "Can't fork a child: %s", strerror(errno));
275
 
286
 
276
		if (childpid == 0)
287
		if (childpid == 0)
277
		{
288
		{
278
			/* Child process */
289
			/ Child process /
279
			processCommands((void *)&soc);
290
			processCommands((void *)&soc);
280
			exit(EXIT_SUCCESS);
291
			exit(EXIT_SUCCESS);
281
		}
292
		}
282
 
293
 
283
#if defined(BSD) && !defined(Linux)
294
#if defined(BSD) && !defined(Linux)
Line 285... Line 296...
285
			sleep(1);
296
			sleep(1);
286
#else
297
#else
287
		while (waitpid(-1, &status, WNOHANG) > 0)
298
		while (waitpid(-1, &status, WNOHANG) > 0)
288
			sleep(1);
299
			sleep(1);
289
#endif
300
#endif
290
		close(s1);
301
		close(s1); */
291
	}
302
	}
292
	
303
	
293
	close (s);
304
	close (s);
294
	return NULL;
305
	return NULL;
295
}
306
}