Subversion Repositories heating

Rev

Rev 54 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 54 Rev 56
Line 100... Line 100...
100
		core_limits.rlim_cur = core_limits.rlim_max = RLIM_INFINITY;
100
		core_limits.rlim_cur = core_limits.rlim_max = RLIM_INFINITY;
101
		setrlimit(RLIMIT_CORE, &core_limits);
101
		setrlimit(RLIMIT_CORE, &core_limits);
102
	}
102
	}
103
	// We no longer need the configuration data here, so we remove them.
103
	// We no longer need the configuration data here, so we remove them.
104
	delete (cfg);
104
	delete (cfg);
-
 
105
	/* Prepare the thread attributes */
-
 
106
	if (pthread_attr_init(&pattr) != 0)
-
 
107
	{
-
 
108
		syslog(LOG_DAEMON,"Error getting thread attributes.");
-
 
109
		return 0;
-
 
110
	}
-
 
111
 
-
 
112
	if (pthread_attr_setdetachstate(&pattr, PTHREAD_CREATE_DETACHED) != 0)
-
 
113
	{
-
 
114
		syslog(LOG_DAEMON,"Error setting thread attributes.");
-
 
115
		return 0;
-
 
116
	}
-
 
117
	
105
	// Now start our Thread
118
	// Now start our Thread
106
	if (pthread_create(&pthr_pars, NULL, pthr_parser, (void *)0) != 0)
119
	if (pthread_create(&pthr_pars, NULL, pthr_parser, (void *)0) != 0)
107
	{
120
	{
108
		syslog (LOG_DAEMON,"Create of thread \"pthr_parser\" failed!");
121
		syslog (LOG_DAEMON,"Create of thread \"pthr_parser\" failed!");
109
		return 2;
122
		return 2;
110
	}
123
	}
-
 
124
 
-
 
125
	pthread_join(pthr_pars, NULL);			// Wait for just started thread to end
111
	
126
 
112
	while (1)
127
/*	while (1)
113
		sleep(3600);
128
		sleep(3600);
114
	
129
*/
115
	return 0;
130
	return 0;
116
}
131
}
117
 
132
 
118
/*
133
/*
119
 * Detach application from console and make it a daemon.
134
 * Detach application from console and make it a daemon.
Line 290... Line 305...
290
	else if ((serviceInfo = getservbyname ("heating", "tcp")))
305
	else if ((serviceInfo = getservbyname ("heating", "tcp")))
291
		server1.sin_port = serviceInfo->s_port;
306
		server1.sin_port = serviceInfo->s_port;
292
	else
307
	else
293
	{
308
	{
294
		syslog(LOG_DAEMON,"Error: No TCP port defined!");
309
		syslog(LOG_DAEMON,"Error: No TCP port defined!");
295
		exit(EXIT_FAILURE);
310
		pthread_exit(NULL);
296
	}
311
	}
297
 
312
 
298
	server1.sin_family = AF_INET;
313
	server1.sin_family = AF_INET;
299
	server1.sin_addr.s_addr = INADDR_ANY;
314
	server1.sin_addr.s_addr = INADDR_ANY;
300
	s = socket(AF_INET,SOCK_STREAM,0);
315
	s = socket(AF_INET,SOCK_STREAM,0);
301
 
316
 
302
	if (s < 0)
317
	if (s < 0)
303
	{
318
	{
304
		syslog (LOG_DAEMON, "Error in socket: %s",strerror(errno));
319
		syslog (LOG_DAEMON, "Error in socket: %s",strerror(errno));
305
		exit(EXIT_FAILURE);
320
		pthread_exit(NULL);
306
	}
321
	}
307
 
322
 
308
	if (bind (s, (struct sockaddr *)&server1, sizeof (server1)) < 0)
323
	if (bind (s, (struct sockaddr *)&server1, sizeof (server1)) < 0)
309
	{
324
	{
310
		syslog (LOG_DAEMON, "Error in bind: %s", strerror(errno));
325
		syslog (LOG_DAEMON, "Error in bind: %s", strerror(errno));
311
		exit(EXIT_FAILURE);
326
		pthread_exit(NULL);
312
	}
327
	}
313
 
328
 
314
	if (listen (s, 5) < 0)
329
	if (listen (s, 5) < 0)
315
	{
330
	{
316
		syslog (LOG_DAEMON, "Error in listen: %s", strerror(errno));
331
		syslog (LOG_DAEMON, "Error in listen: %s", strerror(errno));
317
		exit(EXIT_FAILURE);
332
		pthread_exit(NULL);
318
	}
333
	}
319
 
334
 
320
	length = sizeof(client1);
335
	length = sizeof(client1);
321
 
336
 
322
	if (Configure.debug)
337
	if (Configure.debug)
323
		syslog (LOG_DEBUG, "Server ready: %d",s);
338
		syslog (LOG_DEBUG, "Server ready: %d",s);
324
	// Initialize and start the probe
339
	// Initialize and start the probe
325
	if (heat == nullptr)
340
	if (heat == nullptr)
326
		heat = new heating();
341
		heat = new heating();
327
 
342
 
328
	if (pthread_create(&pthr_heat, NULL, pthr_Heat, (void *)0) != 0)
343
	if (pthread_create(&pthr_heat, &pattr, pthr_Heat, (void *)0) != 0)
329
	{
344
	{
330
		syslog (LOG_DAEMON,"Create of thread \"pthr_heat\" failed!");
345
		syslog (LOG_DAEMON,"Create of thread \"pthr_heat\" failed!");
331
		close (s);
346
		close (s);
332
		exit(EXIT_FAILURE);
347
		pthread_exit(NULL);
333
	}
348
	}
334
	
349
	
335
	if (Configure.debug)
350
	if (Configure.debug)
336
		syslog(LOG_DEBUG, "Heating was initialized and is polling ...");
351
		syslog(LOG_DEBUG, "Heating was initialized and is polling ...");
337
	
352
	
Line 351... Line 366...
351
		soc.ip[0] = 0;
366
		soc.ip[0] = 0;
352
		soc.sockfd = s;
367
		soc.sockfd = s;
353
		soc.newfd = s1;
368
		soc.newfd = s1;
354
		
369
		
355
		// This thread will parse the commands comming to this daemon.
370
		// This thread will parse the commands comming to this daemon.
356
		if (pthread_create(&pthr_process, NULL, processCommands, (void *)&soc) != 0)
371
		if (pthread_create(&pthr_process, &pattr, processCommands, (void *)&soc) != 0)
357
		{
372
		{
358
			syslog (LOG_DAEMON,"Create of thread \"processCommands\" failed!");
373
			syslog (LOG_DAEMON,"Create of thread \"processCommands\" failed!");
359
			close(s1);
374
			close(s1);
360
			soc.newfd = 0;
375
			soc.newfd = 0;
361
		}
376
		}
Line 363... Line 378...
363
 
378
 
364
	close (s);
379
	close (s);
365
	soc.sockfd = 0;
380
	soc.sockfd = 0;
366
	delete heat;
381
	delete heat;
367
	heat = nullptr;
382
	heat = nullptr;
368
	return NULL;
383
	pthread_exit(NULL);
369
}
384
}
370
 
385
 
371
void *processCommands(void *pV_data)
386
void *processCommands(void *pV_data)
372
{
387
{
373
char ch, buf[128];
388
char ch, buf[128];