Browse code

timer.c: logging: convert LOG to LM_*

Ovidiu Sas authored on 03/10/2014 20:26:15
Showing 1 changed files
... ...
@@ -235,24 +235,23 @@ int init_timer()
235 235
 	timer_lst=shm_malloc(sizeof(struct timer_lists));
236 236
 #else
237 237
 	/* in this case get_ticks won't work! */
238
-	LOG(L_INFO, "WARNING: no shared memory support compiled in"
239
-				" get_ticks won't work\n");
238
+	LM_WARN("no shared memory support compiled in get_ticks won't work\n");
240 239
 	ticks=pkg_malloc(sizeof(ticks_t));
241 240
 	timer_lst=pkg_malloc(sizeof(struct timer_lists));
242 241
 #endif
243 242
 	if (ticks==0){
244
-		LOG(L_CRIT, "ERROR: init_timer: out of shared memory (ticks)\n");
243
+		LM_CRIT("out of shared memory (ticks)\n");
245 244
 		ret=E_OUT_OF_MEM;
246 245
 		goto error;
247 246
 	}
248 247
 	if (timer_lst==0){
249
-		LOG(L_CRIT, "ERROR: init_timer: out of shared memory (timer_lst)\n");
248
+		LM_CRIT("out of shared memory (timer_lst)\n");
250 249
 		ret=E_OUT_OF_MEM;
251 250
 		goto error;
252 251
 	}
253 252
 	running_timer=shm_malloc(sizeof(struct timer_ln*));
254 253
 	if (running_timer==0){
255
-		LOG(L_CRIT, "ERROR: init_timer: out of memory (running_timer)\n");
254
+		LM_CRIT("out of memory (running_timer)\n");
256 255
 		ret=E_OUT_OF_MEM;
257 256
 		goto error;
258 257
 	}
... ...
@@ -263,8 +262,7 @@ int init_timer()
263 263
 	prev_ticks=last_ticks=last_adj_check=*ticks;
264 264
 	*running_timer=0;
265 265
 	if (gettimeofday(&start_time, 0)<0){
266
-		LOG(L_ERR, "ERROR: init_timer: gettimeofday failed: %s [%d]\n",
267
-				strerror(errno), errno);
266
+		LM_ERR("gettimeofday failed: %s [%d]\n", strerror(errno), errno);
268 267
 		ret=-1;
269 268
 		goto error;
270 269
 	}
... ...
@@ -299,7 +297,7 @@ int init_timer()
299 299
 	slow_timer_lists=shm_malloc(sizeof(struct timer_head)*SLOW_LISTS_NO);
300 300
 	running_timer2=shm_malloc(sizeof(struct timer_ln*));
301 301
 	if ((t_idx==0)||(s_idx==0) || (slow_timer_lists==0) ||(running_timer2==0)){
302
-		LOG(L_ERR, "ERROR: init_timer: out of shared memory (slow)\n");
302
+		LM_ERR("out of shared memory (slow)\n");
303 303
 		ret=E_OUT_OF_MEM;
304 304
 		goto error;
305 305
 	}
... ...
@@ -333,8 +331,7 @@ int arm_slow_timer()
333 333
 again:
334 334
 	if (sigprocmask(SIG_BLOCK, &slow_timer_sset, 0)==-1){
335 335
 		if (errno==EINTR) goto again;
336
-		LOG(L_ERR, "ERROR: arm_slow_timer: sigprocmask failed: %s [%d]}n",
337
-				strerror(errno), errno);
336
+		LM_ERR("sigprocmask failed: %s [%d]}n", strerror(errno), errno);
338 337
 		goto error;
339 338
 	}
340 339
 #ifdef __OS_darwin
... ...
@@ -374,18 +371,16 @@ int arm_timer()
374 374
 	it.it_value=it.it_interval;
375 375
 	/* install the signal handler */
376 376
 	if (set_sig_h(SIGALRM, sig_timer) == SIG_ERR ){
377
-		LOG(L_CRIT, "ERROR: init_timer: the SIGALRM signal handler cannot"
378
-					" be installed: %s [%d]\n", strerror(errno), errno);
377
+		LM_CRIT("SIGALRM signal handler cannot be installed: %s [%d]\n",
378
+					strerror(errno), errno);
379 379
 		return -1;
380 380
 	}
381 381
 	if (setitimer(ITIMER_REAL, &it, 0) == -1){
382
-		LOG(L_CRIT, "ERROR: init_timer: setitimer failed: %s [%d]\n",
383
-					strerror(errno), errno);
382
+		LM_CRIT("setitimer failed: %s [%d]\n", strerror(errno), errno);
384 383
 		return -1;
385 384
 	}
386 385
 	if (gettimeofday(&last_time, 0)<0){
387
-		LOG(L_ERR, "ERROR: arm_timer: gettimeofday failed: %s [%d]\n",
388
-				strerror(errno), errno);
386
+		LM_ERR("gettimeofday failed: %s [%d]\n", strerror(errno), errno);
389 387
 		return -1;
390 388
 	}
391 389
 	/* initialize the config framework */
... ...
@@ -426,14 +421,13 @@ inline static void adjust_ticks(void)
426 426
 #endif /* DBG_ser_time */
427 427
 		last_adj_check=*ticks;
428 428
 		if (gettimeofday(&crt_time, 0)<0){
429
-			LOG(L_ERR, "ERROR: adjust_ticks: gettimeofday failed: %s [%d]\n",
430
-				strerror(errno), errno);
429
+			LM_ERR("gettimeofday failed: %s [%d]\n", strerror(errno), errno);
431 430
 			return; /* ignore */
432 431
 		}
433 432
 		diff_time=(long long)crt_time.tv_sec*1000000+crt_time.tv_usec-
434 433
 					((long long) last_time.tv_sec*1000000+last_time.tv_usec);
435 434
 		if (diff_time<0){
436
-			LOG(L_WARN, "WARNING: time changed backwards %ld ms ignoring...\n",
435
+			LM_WARN("time changed backwards %ld ms ignoring...\n",
437 436
 						(long)(diff_time/1000));
438 437
 			last_time=crt_time;
439 438
 			last_ticks=*ticks;
... ...
@@ -442,7 +436,7 @@ inline static void adjust_ticks(void)
442 442
 			diff_time_ticks=(ticks_t)((diff_time*TIMER_TICKS_HZ)/1000000LL);
443 443
 			delta=(s_ticks_t)(diff_time_ticks-diff_ticks_raw);
444 444
 			if (delta<-1){
445
-				LOG(L_WARN, "WARNING: our timer runs faster then real-time"
445
+				LM_WARN("our timer runs faster then real-time"
446 446
 						" (%lu ms / %u ticks our time .->"
447 447
 						 " %lu ms / %u ticks real time)\n", 
448 448
 						(unsigned long)(diff_ticks_raw*1000L/TIMER_TICKS_HZ),
... ...
@@ -599,7 +593,7 @@ int timer_add_safe(struct timer_ln* tl, ticks_t delta)
599 599
 	}
600 600
 	tl->initial_timeout=delta;
601 601
 	if ((tl->next!=0) || (tl->prev!=0)){
602
-		LOG(L_CRIT, "BUG: timer_add: called with linked timer: %p (%p, %p)\n",
602
+		LM_CRIT("timer_add: called with linked timer: %p (%p, %p)\n",
603 603
 				tl, tl->next, tl->prev);
604 604
 		ret=-1;
605 605
 		goto error;
... ...
@@ -668,7 +662,7 @@ again:
668 668
 				if (IS_IN_TIMER_SLOW()){
669 669
 					/* if somebody tries to shoot himself in the foot,
670 670
 					 * warn him and ignore the delete */
671
-					LOG(L_CRIT, "BUG: timer handle %p (s) tried to delete"
671
+					LM_CRIT("timer handle %p (s) tried to delete"
672 672
 							" itself\n", tl);
673 673
 #ifdef TIMER_DEBUG
674 674
 					LOG(timerlog, "WARN: -timer_del-: called from %s(%s):%d\n",
... ...
@@ -738,7 +732,7 @@ again:
738 738
 				if (IS_IN_TIMER()){
739 739
 					/* if somebody tries to shoot himself in the foot,
740 740
 					 * warn him and ignore the delete */
741
-					LOG(L_CRIT, "BUG: timer handle %p tried to delete"
741
+					LM_CRIT("timer handle %p tried to delete"
742 742
 							" itself\n", tl);
743 743
 #ifdef TIMER_DEBUG
744 744
 					LOG(timerlog, "WARN: -timer_del-: called from %s(%s):%d\n",
... ...
@@ -825,7 +819,7 @@ void timer_allow_del(void)
825 825
 			UNSET_RUNNING_SLOW();
826 826
 	}else 
827 827
 #endif
828
-		LOG(L_CRIT, "BUG: timer_allow_del called outside a timer handle\n");
828
+		LM_CRIT("timer_allow_del called outside a timer handle\n");
829 829
 }
830 830
 
831 831
 
... ...
@@ -856,19 +850,19 @@ inline static void timer_list_expire(ticks_t t, struct timer_head* h
856 856
 		tl=h->next;
857 857
 #ifdef TIMER_DEBUG /* FIXME: replace w/ EXTRA_DEBUG */
858 858
 		if (tl==0){
859
-			LOG(L_CRIT, "BUG: timer_list_expire: tl=%p, h=%p {%p, %p}\n",
859
+			LM_CRIT("timer_list_expire: tl=%p, h=%p {%p, %p}\n",
860 860
 					tl, h, h->next, h->prev);
861 861
 			abort();
862 862
 		}else if((tl->next==0) || (tl->prev==0)){
863
-			LOG(L_CRIT, "BUG: timer_list_expire: @%d tl=%p "
863
+			LM_CRIT("timer_list_expire: @%d tl=%p "
864 864
 					"{ %p, %p, %d, %d, %p, %p, %04x, -},"
865 865
 					" h=%p {%p, %p}\n", t, 
866 866
 					tl,  tl->next, tl->prev, tl->expire, tl->initial_timeout,
867 867
 					tl->data, tl->f, tl->flags, 
868 868
 					h, h->next, h->prev);
869
-			LOG(L_CRIT, "BUG: -timer_list_expire-: cycle %d, first %p,"
869
+			LM_CRIT("-timer_list_expire-: cycle %d, first %p,"
870 870
 						"running %p\n", i, first, *running_timer);
871
-			LOG(L_CRIT, "BUG: -timer_list_expire-: added %d times"
871
+			LM_CRIT("-timer_list_expire-: added %d times"
872 872
 						", last from: %s(%s):%d, deleted %d times"
873 873
 						", last from: %s(%s):%d, init %d times, expired %d \n",
874 874
 						tl->add_calls,
... ...
@@ -944,7 +938,7 @@ static void timer_handler(void)
944 944
 	do{
945 945
 		saved_ticks=*ticks; /* protect against time running backwards */
946 946
 		if (prev_ticks>=saved_ticks){
947
-			LOG(L_CRIT, "BUG: timer_handler: backwards or still time\n");
947
+			LM_CRIT("backwards or still time\n");
948 948
 			/* try to continue */
949 949
 			prev_ticks=saved_ticks-1;
950 950
 			break;
... ...
@@ -970,7 +964,7 @@ static void timer_handler(void)
970 970
 		if ((slow_idx_t)(*t_idx-*s_idx) < (SLOW_LISTS_NO-1U))
971 971
 			(*t_idx)++;
972 972
 		else{
973
-			LOG(L_WARN, "slow timer too slow: overflow (%d - %d = %d)\n",
973
+			LM_WARN("slow timer too slow: overflow (%d - %d = %d)\n",
974 974
 					*t_idx, *s_idx, *t_idx-*s_idx);
975 975
 			/* trying to continue */
976 976
 		}
... ...
@@ -1031,7 +1025,7 @@ int register_timer(timer_function f, void* param, unsigned int interval)
1031 1031
 
1032 1032
 	t=shm_malloc(sizeof(struct sr_timer));
1033 1033
 	if (t==0){
1034
-		LOG(L_ERR, "ERROR: register_timer: out of memory\n");
1034
+		LM_ERR("out of memory\n");
1035 1035
 		goto error;
1036 1036
 	}
1037 1037
 	t->id=timer_id++;
... ...
@@ -1040,7 +1034,7 @@ int register_timer(timer_function f, void* param, unsigned int interval)
1040 1040
 	
1041 1041
 	timer_init(&t->tl, compat_old_handler, t, 0); /* is slow */
1042 1042
 	if (timer_add(&t->tl, S_TO_TICKS(interval))!=0){
1043
-		LOG(L_ERR, "ERROR: register_timer: timer_add failed\n");
1043
+		LM_ERR("timer_add failed\n");
1044 1044
 		return -1;
1045 1045
 	}
1046 1046
 	
... ...
@@ -1055,7 +1049,7 @@ error:
1055 1055
 ticks_t get_ticks_raw()
1056 1056
 {
1057 1057
 #ifndef SHM_MEM
1058
-	LOG(L_CRIT, "WARNING: get_ticks: no shared memory support compiled in"
1058
+	LM_CRIT("no shared memory support compiled in"
1059 1059
 			", returning 0 (probably wrong)");
1060 1060
 	return 0;
1061 1061
 #endif
... ...
@@ -1068,7 +1062,7 @@ ticks_t get_ticks_raw()
1068 1068
 ticks_t get_ticks()
1069 1069
 {
1070 1070
 #ifndef SHM_MEM
1071
-	LOG(L_CRIT, "WARNING: get_ticks: no shared memory support compiled in"
1071
+	LM_CRIT("no shared memory support compiled in"
1072 1072
 			", returning 0 (probably wrong)");
1073 1073
 	return 0;
1074 1074
 #endif
... ...
@@ -1083,7 +1077,8 @@ ticks_t get_ticks()
1083 1083
  * This function is intended to be executed in a special separated process
1084 1084
  * (the "slow" timer) which will run the timer handlers of all the registered
1085 1085
  * timers not marked as "fast". The ideea is to execute the fast timers in the
1086
- * "main" timer process, as accurate as possible and defer the execution of the  * timers marked as "slow" to the "slow" timer.
1086
+ * "main" timer process, as accurate as possible and defer the execution of the
1087
+ * timers marked as "slow" to the "slow" timer.
1087 1088
  * Implementation details:
1088 1089
  *  - it waits for a signal and then wakes up and processes
1089 1090
  *    all the lists in slow_timer_lists from [s_idx, t_idx). It will
... ...
@@ -1113,8 +1108,7 @@ void slow_timer_main()
1113 1113
 #endif
1114 1114
 		if (n==-1){
1115 1115
 			if (errno==EINTR) continue; /* some other signal, ignore it */
1116
-			LOG(L_ERR, "ERROR: slow_timer_main: sigwaitinfo failed: %s [%d]\n",
1117
-					strerror(errno), errno);
1116
+			LM_ERR("sigwaitinfo failed: %s [%d]\n", strerror(errno), errno);
1118 1117
 			sleep(1);
1119 1118
 			/* try to continue */
1120 1119
 		}