Browse code

core: daemonize.c: convert logs to new format

Ovidiu Sas authored on 01/10/2014 16:54:31
Showing 1 changed files
... ...
@@ -224,11 +224,11 @@ int enable_dumpable(void)
224 224
 			} else {
225 225
 				LM_DBG("core dumping has just been enabled...\n");
226 226
 				if (getrlimit(RLIMIT_CORE, &lim)<0){
227
-					LOG(L_CRIT, "cannot get the maximum core size: %s\n",
227
+					LM_CRIT( "cannot get the maximum core size: %s\n",
228 228
 							strerror(errno));
229 229
 					return -1;
230 230
 				} else {
231
-					DBG("current core file limit: %lu (max: %lu)\n",
231
+					LM_DBG("current core file limit: %lu (max: %lu)\n",
232 232
 						(unsigned long)lim.rlim_cur, (unsigned long)lim.rlim_max);
233 233
 				}
234 234
 			}
... ...
@@ -289,12 +289,12 @@ int daemonize(char*  name,  int status_wait)
289 289
 	setbuf(stdout, 0);
290 290
 	setbuf(stderr, 0);
291 291
 	if (chroot_dir&&(chroot(chroot_dir)<0)){
292
-		LOG(L_CRIT, "Cannot chroot to %s: %s\n", chroot_dir, strerror(errno));
292
+		LM_CRIT("Cannot chroot to %s: %s\n", chroot_dir, strerror(errno));
293 293
 		goto error;
294 294
 	}
295 295
 	
296 296
 	if (chdir(working_dir)<0){
297
-		LOG(L_CRIT,"cannot chdir to %s: %s\n", working_dir, strerror(errno));
297
+		LM_CRIT("cannot chdir to %s: %s\n", working_dir, strerror(errno));
298 298
 		goto error;
299 299
 	}
300 300
 
... ...
@@ -305,14 +305,14 @@ int daemonize(char*  name,  int status_wait)
305 305
 		}
306 306
 		/* fork to become!= group leader*/
307 307
 		if ((pid=fork())<0){
308
-			LOG(L_CRIT, "Cannot fork:%s\n", strerror(errno));
308
+			LM_CRIT("Cannot fork:%s\n", strerror(errno));
309 309
 			goto error;
310 310
 		}else if (pid!=0){
311 311
 			if (status_wait) {
312 312
 				if (daemon_status_wait(&pipe_status) == 0)
313 313
 					exit((int)pipe_status);
314 314
 				else{
315
-					LOG(L_ERR, "Main process exited before writing to pipe\n");
315
+					LM_ERR("Main process exited before writing to pipe\n");
316 316
 					exit(-1);
317 317
 				}
318 318
 			}
... ...
@@ -322,13 +322,13 @@ int daemonize(char*  name,  int status_wait)
322 322
 			daemon_status_no_wait(); /* clean unused read fd */
323 323
 		/* become session leader to drop the ctrl. terminal */
324 324
 		if (setsid()<0){
325
-			LOG(L_WARN, "setsid failed: %s\n",strerror(errno));
325
+			LM_WARN("setsid failed: %s\n",strerror(errno));
326 326
 		}else{
327 327
 			own_pgid=1;/* we have our own process group */
328 328
 		}
329 329
 		/* fork again to drop group  leadership */
330 330
 		if ((pid=fork())<0){
331
-			LOG(L_CRIT, "Cannot  fork:%s\n", strerror(errno));
331
+			LM_CRIT("Cannot  fork:%s\n", strerror(errno));
332 332
 			goto error;
333 333
 		}else if (pid!=0){
334 334
 			/*parent process => exit */
... ...
@@ -348,21 +348,21 @@ int daemonize(char*  name,  int status_wait)
348 348
 			}
349 349
 			fclose(pid_stream);
350 350
 			if (p==-1){
351
-				LOG(L_CRIT, "pid file %s exists, but doesn't contain a valid"
351
+				LM_CRIT("pid file %s exists, but doesn't contain a valid"
352 352
 					" pid number\n", pid_file);
353 353
 				goto error;
354 354
 			}
355 355
 			if (kill((pid_t)p, 0)==0 || errno==EPERM){
356
-				LOG(L_CRIT, "running process found in the pid file %s\n",
356
+				LM_CRIT("running process found in the pid file %s\n",
357 357
 					pid_file);
358 358
 				goto error;
359 359
 			}else{
360
-				LOG(L_WARN, "pid file contains old pid, replacing pid\n");
360
+				LM_WARN("pid file contains old pid, replacing pid\n");
361 361
 			}
362 362
 		}
363 363
 		pid=getpid();
364 364
 		if ((pid_stream=fopen(pid_file, "w"))==NULL){
365
-			LOG(L_WARN, "unable to create pid file %s: %s\n", 
365
+			LM_WARN("unable to create pid file %s: %s\n", 
366 366
 				pid_file, strerror(errno));
367 367
 			goto error;
368 368
 		}else{
... ...
@@ -382,7 +382,7 @@ int daemonize(char*  name,  int status_wait)
382 382
 			}
383 383
 			fclose(pid_stream);
384 384
 			if (p==-1){
385
-				LOG(L_CRIT, "pgid file %s exists, but doesn't contain a valid"
385
+				LM_CRIT("pgid file %s exists, but doesn't contain a valid"
386 386
 				    " pgid number\n", pgid_file);
387 387
 				goto error;
388 388
 			}
... ...
@@ -390,7 +390,7 @@ int daemonize(char*  name,  int status_wait)
390 390
 		if (own_pgid){
391 391
 			pid=getpgid(0);
392 392
 			if ((pid_stream=fopen(pgid_file, "w"))==NULL){
393
-				LOG(L_WARN, "unable to create pgid file %s: %s\n",
393
+				LM_WARN("unable to create pgid file %s: %s\n",
394 394
 					pgid_file, strerror(errno));
395 395
 				goto error;
396 396
 			}else{
... ...
@@ -402,7 +402,7 @@ int daemonize(char*  name,  int status_wait)
402 402
 				}
403 403
 			}
404 404
 		}else{
405
-			LOG(L_WARN, "we don't have our own process so we won't save"
405
+			LM_WARN("we don't have our own process so we won't save"
406 406
 					" our pgid\n");
407 407
 			unlink(pgid_file); /* just to be sure nobody will miss-use the old
408 408
 								  value*/
... ...
@@ -411,18 +411,18 @@ int daemonize(char*  name,  int status_wait)
411 411
 	
412 412
 	/* try to replace stdin, stdout & stderr with /dev/null */
413 413
 	if (freopen("/dev/null", "r", stdin)==0){
414
-		LOG(L_ERR, "unable to replace stdin with /dev/null: %s\n",
414
+		LM_ERR("unable to replace stdin with /dev/null: %s\n",
415 415
 				strerror(errno));
416 416
 		/* continue, leave it open */
417 417
 	};
418 418
 	if (freopen("/dev/null", "w", stdout)==0){
419
-		LOG(L_ERR, "unable to replace stdout with /dev/null: %s\n",
419
+		LM_ERR("unable to replace stdout with /dev/null: %s\n",
420 420
 				strerror(errno));
421 421
 		/* continue, leave it open */
422 422
 	};
423 423
 	/* close stderr only if log_stderr=0 */
424 424
 	if ((!log_stderr) &&(freopen("/dev/null", "w", stderr)==0)){
425
-		LOG(L_ERR, "unable to replace stderr with /dev/null: %s\n",
425
+		LM_ERR("unable to replace stderr with /dev/null: %s\n",
426 426
 				strerror(errno));
427 427
 		/* continue, leave it open */
428 428
 	};
... ...
@@ -453,23 +453,23 @@ int do_suid()
453 453
 	
454 454
 	if (gid){
455 455
 		if(setgid(gid)<0){
456
-			LOG(L_CRIT, "cannot change gid to %d: %s\n", gid, strerror(errno));
456
+			LM_CRIT("cannot change gid to %d: %s\n", gid, strerror(errno));
457 457
 			goto error;
458 458
 		}
459 459
 	}
460 460
 	
461 461
 	if(uid){
462 462
 		if (!(pw = getpwuid(uid))){
463
-			LOG(L_CRIT, "user lookup failed: %s\n", strerror(errno));
463
+			LM_CRIT("user lookup failed: %s\n", strerror(errno));
464 464
 			goto error;
465 465
 		}
466 466
 		if(initgroups(pw->pw_name, pw->pw_gid)<0){
467
-			LOG(L_CRIT, "cannot set supplementary groups: %s\n", 
467
+			LM_CRIT("cannot set supplementary groups: %s\n", 
468 468
 							strerror(errno));
469 469
 			goto error;
470 470
 		}
471 471
 		if(setuid(uid)<0){
472
-			LOG(L_CRIT, "cannot change uid to %d: %s\n", uid, strerror(errno));
472
+			LM_CRIT("cannot change uid to %d: %s\n", uid, strerror(errno));
473 473
 			goto error;
474 474
 		}
475 475
 	}
... ...
@@ -491,7 +491,7 @@ int increase_open_fds(int target)
491 491
 	struct rlimit orig;
492 492
 	
493 493
 	if (getrlimit(RLIMIT_NOFILE, &lim)<0){
494
-		LOG(L_CRIT, "cannot get the maximum number of file descriptors: %s\n",
494
+		LM_CRIT("cannot get the maximum number of file descriptors: %s\n",
495 495
 				strerror(errno));
496 496
 		goto error;
497 497
 	}
... ...
@@ -505,7 +505,7 @@ int increase_open_fds(int target)
505 505
 		lim.rlim_cur=target; /* increase soft limit to target */
506 506
 	}else{
507 507
 		/* more than the hard limit */
508
-		LOG(L_INFO, "trying to increase the open file limit"
508
+		LM_INFO("trying to increase the open file limit"
509 509
 				" past the hard limit (%ld -> %d)\n", 
510 510
 				(unsigned long)lim.rlim_max, target);
511 511
 		lim.rlim_max=target;
... ...
@@ -514,7 +514,7 @@ int increase_open_fds(int target)
514 514
 	DBG("increasing open file limits to: %lu/%lu\n",
515 515
 			(unsigned long)lim.rlim_cur, (unsigned long)lim.rlim_max);
516 516
 	if (setrlimit(RLIMIT_NOFILE, &lim)<0){
517
-		LOG(L_CRIT, "cannot increase the open file limit to"
517
+		LM_CRIT("cannot increase the open file limit to"
518 518
 				" %lu/%lu: %s\n",
519 519
 				(unsigned long)lim.rlim_cur, (unsigned long)lim.rlim_max,
520 520
 				strerror(errno));
... ...
@@ -524,7 +524,7 @@ int increase_open_fds(int target)
524 524
 			lim.rlim_max=orig.rlim_max;
525 525
 			lim.rlim_cur=orig.rlim_max;
526 526
 			if (setrlimit(RLIMIT_NOFILE, &lim)==0){
527
-				LOG(L_CRIT, " maximum number of file descriptors increased to"
527
+				LM_CRIT(" maximum number of file descriptors increased to"
528 528
 						" %u\n",(unsigned)orig.rlim_max);
529 529
 			}
530 530
 		}
... ...
@@ -546,7 +546,7 @@ int set_core_dump(int enable, long unsigned int size)
546 546
 	
547 547
 	if (enable){
548 548
 		if (getrlimit(RLIMIT_CORE, &lim)<0){
549
-			LOG(L_CRIT, "cannot get the maximum core size: %s\n",
549
+			LM_CRIT("cannot get the maximum core size: %s\n",
550 550
 					strerror(errno));
551 551
 			goto error;
552 552
 		}
... ...
@@ -565,10 +565,10 @@ int set_core_dump(int enable, long unsigned int size)
565 565
 			newlim.rlim_max=lim.rlim_max;
566 566
 			newlim.rlim_cur=newlim.rlim_max;
567 567
 			if (setrlimit(RLIMIT_CORE, &newlim)<0){
568
-				LOG(L_CRIT, "could increase core limits at all: %s\n",
568
+				LM_CRIT("could increase core limits at all: %s\n",
569 569
 						strerror (errno));
570 570
 			}else{
571
-				LOG(L_CRIT, "core limits increased only to %lu\n",
571
+				LM_CRIT("core limits increased only to %lu\n",
572 572
 						(unsigned long)lim.rlim_max);
573 573
 			}
574 574
 			goto error; /* it's an error we haven't got the size we wanted*/
... ...
@@ -582,7 +582,7 @@ int set_core_dump(int enable, long unsigned int size)
582 582
 		newlim.rlim_cur=0;
583 583
 		newlim.rlim_max=0;
584 584
 		if (setrlimit(RLIMIT_CORE, &newlim)<0){
585
-			LOG(L_CRIT, "failed to disable core dumps: %s\n",
585
+			LM_CRIT("failed to disable core dumps: %s\n",
586 586
 					strerror(errno));
587 587
 			goto error;
588 588
 		}
... ...
@@ -601,7 +601,7 @@ int mem_lock_pages()
601 601
 {
602 602
 #ifdef HAVE_MLOCKALL
603 603
 	if (mlockall(MCL_CURRENT|MCL_FUTURE) !=0){
604
-		LOG(L_WARN,"failed to lock the memory pages (disable swap): %s [%d]\n",
604
+		LM_WARN("failed to lock the memory pages (disable swap): %s [%d]\n",
605 605
 				strerror(errno), errno);
606 606
 		goto error;
607 607
 	}
... ...
@@ -609,7 +609,7 @@ int mem_lock_pages()
609 609
 error:
610 610
 	return -1;
611 611
 #else /* if MLOCKALL not defined return error */
612
-		LOG(L_WARN,"failed to lock the memory pages: no mlockall support\n");
612
+		LM_WARN("failed to lock the memory pages: no mlockall support\n");
613 613
 	return -1;
614 614
 #endif 
615 615
 }
... ...
@@ -635,7 +635,7 @@ int set_rt_prio(int prio, int policy)
635 635
 			sched_policy=SCHED_FIFO;
636 636
 			break;
637 637
 		default:
638
-			LOG(L_WARN, "WARNING: invalid scheduling policy,using"
638
+			LM_WARN("WARNING: invalid scheduling policy,using"
639 639
 						" SCHED_OTHER\n");
640 640
 			sched_policy=SCHED_OTHER;
641 641
 	}
... ...
@@ -643,23 +643,23 @@ int set_rt_prio(int prio, int policy)
643 643
 	max_prio=sched_get_priority_max(policy);
644 644
 	min_prio=sched_get_priority_min(policy);
645 645
 	if (prio<min_prio){
646
-		LOG(L_WARN, "scheduling priority %d too small, using minimum value"
646
+		LM_WARN("scheduling priority %d too small, using minimum value"
647 647
 					" (%d)\n", prio, min_prio);
648 648
 		prio=min_prio;
649 649
 	}else if (prio>max_prio){
650
-		LOG(L_WARN, "scheduling priority %d too big, using maximum value"
650
+		LM_WARN("scheduling priority %d too big, using maximum value"
651 651
 					" (%d)\n", prio, max_prio);
652 652
 		prio=max_prio;
653 653
 	}
654 654
 	sch_p.sched_priority=prio;
655 655
 	if (sched_setscheduler(0, sched_policy, &sch_p) != 0){
656
-		LOG(L_WARN, "could not switch to real time priority: %s [%d]\n",
656
+		LM_WARN("could not switch to real time priority: %s [%d]\n",
657 657
 					strerror(errno), errno);
658 658
 		return -1;
659 659
 	};
660 660
 	return 0;
661 661
 #else
662
-	LOG(L_WARN, "real time support not available\n");
662
+	LM_WARN("real time support not available\n");
663 663
 	return -1;
664 664
 #endif
665 665
 }