thermferm/thermferm.c

changeset 235
885ad8d52126
parent 234
b69438db19ec
child 238
a0f1deb65889
equal deleted inserted replaced
234:b69438db19ec 235:885ad8d52126
234 if (debug) 234 if (debug)
235 fprintf(stdout, "mbsePi-apps thermferm v%s starting\n", VERSION); 235 fprintf(stdout, "mbsePi-apps thermferm v%s starting\n", VERSION);
236 236
237 if (rdconfig()) { 237 if (rdconfig()) {
238 fprintf(stderr, "Error reading configuration\n"); 238 fprintf(stderr, "Error reading configuration\n");
239 syslog(LOG_NOTICE, "halted"); 239 syslog(LOG_WARNING, "Error reading configuration: halted");
240 return 1; 240 return 1;
241 } 241 }
242 242
243 /* 243 /*
244 * Catch all the signals we can, and ignore the rest. Note that SIGKILL can't be ignored 244 * Catch all the signals we can, and ignore the rest. Note that SIGKILL can't be ignored
274 * that the child will not be a process group leader. Otherwise, 274 * that the child will not be a process group leader. Otherwise,
275 * if the child were to open a terminal, it would become 275 * if the child were to open a terminal, it would become
276 * associated with that terminal as its control terminal. 276 * associated with that terminal as its control terminal.
277 */ 277 */
278 if ((pgrp = setpgid(0, 0)) == -1) { 278 if ((pgrp = setpgid(0, 0)) == -1) {
279 syslog(LOG_NOTICE, "setpgpid failed"); 279 syslog(LOG_WARNING, "setpgpid failed");
280 } 280 }
281 281
282 frk = fork(); 282 frk = fork();
283 switch (frk) { 283 switch (frk) {
284 case -1: 284 case -1:
285 syslog(LOG_NOTICE, "Daemon fork failed: %s", strerror(errno)); 285 syslog(LOG_WARNING, "Daemon fork failed: %s", strerror(errno));
286 syslog(LOG_NOTICE, "Finished, rc=1");
287 #ifdef HAVE_WIRINGPI_H 286 #ifdef HAVE_WIRINGPI_H
288 stopLCD(); 287 stopLCD();
289 #endif 288 #endif
290 exit(1); 289 exit(1);
291 case 0: /* 290 case 0: /*
292 * Run the daemon 291 * Run the daemon
293 */ 292 */
294 fclose(stdin); 293 fclose(stdin);
295 if (open("/dev/null", O_RDONLY) != 0) { 294 if (open("/dev/null", O_RDONLY) != 0) {
296 syslog(LOG_NOTICE, "Reopen of stdin to /dev/null failed"); 295 syslog(LOG_WARNING, "Reopen of stdin to /dev/null failed");
297 _exit(2); 296 _exit(2);
298 } 297 }
299 fclose(stdout); 298 fclose(stdout);
300 if (open("/dev/null", O_WRONLY | O_APPEND | O_CREAT,0600) != 1) { 299 if (open("/dev/null", O_WRONLY | O_APPEND | O_CREAT,0600) != 1) {
301 syslog(LOG_NOTICE, "Reopen of stdout to /dev/null failed"); 300 syslog(LOG_WARNING, "Reopen of stdout to /dev/null failed");
302 _exit(2); 301 _exit(2);
303 } 302 }
304 fclose(stderr); 303 fclose(stderr);
305 if (open("/dev/null", O_WRONLY | O_APPEND | O_CREAT,0600) != 2) { 304 if (open("/dev/null", O_WRONLY | O_APPEND | O_CREAT,0600) != 2) {
306 syslog(LOG_NOTICE, "Reopen of stderr to /dev/null failed"); 305 syslog(LOG_WARNING, "Reopen of stderr to /dev/null failed");
307 _exit(2); 306 _exit(2);
308 } 307 }
309 mypid = getpid(); 308 mypid = getpid();
310 rc = server(); 309 rc = server();
311 break; 310 break;
344 #endif 343 #endif
345 int current_step, valid_step, time_until_now; 344 int current_step, valid_step, time_until_now;
346 float previous_target; 345 float previous_target;
347 346
348 if (lockprog((char *)"thermferm")) { 347 if (lockprog((char *)"thermferm")) {
349 syslog(LOG_NOTICE, "Can't lock"); 348 syslog(LOG_WARNING, "Can't lock");
350 return 1; 349 return 1;
351 } 350 }
352 351
353 rc = devices_detect(); 352 rc = devices_detect();
354 if (rc) { 353 if (rc) {
361 #else 360 #else
362 rc = pthread_create(&threads[t], NULL, my_devices_loop, (void *)t ); 361 rc = pthread_create(&threads[t], NULL, my_devices_loop, (void *)t );
363 #endif 362 #endif
364 if (rc) { 363 if (rc) {
365 fprintf(stderr, "my_devices_loop thread didn't start rc=%d\n", rc); 364 fprintf(stderr, "my_devices_loop thread didn't start rc=%d\n", rc);
366 syslog(LOG_NOTICE, "my_devices_loop thread didn't start rc=%d", rc); 365 syslog(LOG_WARNING, "my_devices_loop thread didn't start rc=%d", rc);
367 #ifndef HAVE_WIRINGPI_H 366 #ifndef HAVE_WIRINGPI_H
368 } else { 367 } else {
369 t++; 368 t++;
370 #endif 369 #endif
371 } 370 }
375 #else 374 #else
376 rc = pthread_create(&threads[t], NULL, my_server_loop, (void *)t ); 375 rc = pthread_create(&threads[t], NULL, my_server_loop, (void *)t );
377 #endif 376 #endif
378 if (rc) { 377 if (rc) {
379 fprintf(stderr, "my_server_loop thread didn't start rc=%d\n", rc); 378 fprintf(stderr, "my_server_loop thread didn't start rc=%d\n", rc);
380 syslog(LOG_NOTICE, "my_server_loop thread didn't start rc=%d", rc); 379 syslog(LOG_WARNING, "my_server_loop thread didn't start rc=%d", rc);
381 #ifndef HAVE_WIRINGPI_H 380 #ifndef HAVE_WIRINGPI_H
382 } else { 381 } else {
383 t++; 382 t++;
384 #endif 383 #endif
385 } 384 }
386 385
387 #ifdef HAVE_WIRINGPI_H 386 #ifdef HAVE_WIRINGPI_H
388 rc = piThreadCreate(my_panel_loop); 387 rc = piThreadCreate(my_panel_loop);
389 if (rc) { 388 if (rc) {
390 fprintf(stderr, "my_panel_loop thread didn't start rc=%d\n", rc); 389 fprintf(stderr, "my_panel_loop thread didn't start rc=%d\n", rc);
391 syslog(LOG_NOTICE, "my_panel_loop thread didn't start rc=%d", rc); 390 syslog(LOG_WARNING, "my_panel_loop thread didn't start rc=%d", rc);
392 } 391 }
393 #endif 392 #endif
394 393
395 /* 394 /*
396 * Initialize units for processing 395 * Initialize units for processing

mercurial