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 262
 	prev_ticks=last_ticks=last_adj_check=*ticks;
264 263
 	*running_timer=0;
265 264
 	if (gettimeofday(&start_time, 0)<0){
266
-		LOG(L_ERR, "ERROR: init_timer: gettimeofday failed: %s [%d]\n",
267
-				strerror(errno), errno);
265
+		LM_ERR("gettimeofday failed: %s [%d]\n", strerror(errno), errno);
268 266
 		ret=-1;
269 267
 		goto error;
270 268
 	}
... ...
@@ -299,7 +297,7 @@ int init_timer()
299 297
 	slow_timer_lists=shm_malloc(sizeof(struct timer_head)*SLOW_LISTS_NO);
300 298
 	running_timer2=shm_malloc(sizeof(struct timer_ln*));
301 299
 	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");
300
+		LM_ERR("out of shared memory (slow)\n");
303 301
 		ret=E_OUT_OF_MEM;
304 302
 		goto error;
305 303
 	}
... ...
@@ -333,8 +331,7 @@ int arm_slow_timer()
333 331
 again:
334 332
 	if (sigprocmask(SIG_BLOCK, &slow_timer_sset, 0)==-1){
335 333
 		if (errno==EINTR) goto again;
336
-		LOG(L_ERR, "ERROR: arm_slow_timer: sigprocmask failed: %s [%d]}n",
337
-				strerror(errno), errno);
334
+		LM_ERR("sigprocmask failed: %s [%d]}n", strerror(errno), errno);
338 335
 		goto error;
339 336
 	}
340 337
 #ifdef __OS_darwin
... ...
@@ -374,18 +371,16 @@ int arm_timer()
374 371
 	it.it_value=it.it_interval;
375 372
 	/* install the signal handler */
376 373
 	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);
374
+		LM_CRIT("SIGALRM signal handler cannot be installed: %s [%d]\n",
375
+					strerror(errno), errno);
379 376
 		return -1;
380 377
 	}
381 378
 	if (setitimer(ITIMER_REAL, &it, 0) == -1){
382
-		LOG(L_CRIT, "ERROR: init_timer: setitimer failed: %s [%d]\n",
383
-					strerror(errno), errno);
379
+		LM_CRIT("setitimer failed: %s [%d]\n", strerror(errno), errno);
384 380
 		return -1;
385 381
 	}
386 382
 	if (gettimeofday(&last_time, 0)<0){
387
-		LOG(L_ERR, "ERROR: arm_timer: gettimeofday failed: %s [%d]\n",
388
-				strerror(errno), errno);
383
+		LM_ERR("gettimeofday failed: %s [%d]\n", strerror(errno), errno);
389 384
 		return -1;
390 385
 	}
391 386
 	/* initialize the config framework */
... ...
@@ -426,14 +421,13 @@ inline static void adjust_ticks(void)
426 421
 #endif /* DBG_ser_time */
427 422
 		last_adj_check=*ticks;
428 423
 		if (gettimeofday(&crt_time, 0)<0){
429
-			LOG(L_ERR, "ERROR: adjust_ticks: gettimeofday failed: %s [%d]\n",
430
-				strerror(errno), errno);
424
+			LM_ERR("gettimeofday failed: %s [%d]\n", strerror(errno), errno);
431 425
 			return; /* ignore */
432 426
 		}
433 427
 		diff_time=(long long)crt_time.tv_sec*1000000+crt_time.tv_usec-
434 428
 					((long long) last_time.tv_sec*1000000+last_time.tv_usec);
435 429
 		if (diff_time<0){
436
-			LOG(L_WARN, "WARNING: time changed backwards %ld ms ignoring...\n",
430
+			LM_WARN("time changed backwards %ld ms ignoring...\n",
437 431
 						(long)(diff_time/1000));
438 432
 			last_time=crt_time;
439 433
 			last_ticks=*ticks;
... ...
@@ -442,7 +436,7 @@ inline static void adjust_ticks(void)
442 436
 			diff_time_ticks=(ticks_t)((diff_time*TIMER_TICKS_HZ)/1000000LL);
443 437
 			delta=(s_ticks_t)(diff_time_ticks-diff_ticks_raw);
444 438
 			if (delta<-1){
445
-				LOG(L_WARN, "WARNING: our timer runs faster then real-time"
439
+				LM_WARN("our timer runs faster then real-time"
446 440
 						" (%lu ms / %u ticks our time .->"
447 441
 						 " %lu ms / %u ticks real time)\n", 
448 442
 						(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 593
 	}
600 594
 	tl->initial_timeout=delta;
601 595
 	if ((tl->next!=0) || (tl->prev!=0)){
602
-		LOG(L_CRIT, "BUG: timer_add: called with linked timer: %p (%p, %p)\n",
596
+		LM_CRIT("timer_add: called with linked timer: %p (%p, %p)\n",
603 597
 				tl, tl->next, tl->prev);
604 598
 		ret=-1;
605 599
 		goto error;
... ...
@@ -668,7 +662,7 @@ again:
668 662
 				if (IS_IN_TIMER_SLOW()){
669 663
 					/* if somebody tries to shoot himself in the foot,
670 664
 					 * warn him and ignore the delete */
671
-					LOG(L_CRIT, "BUG: timer handle %p (s) tried to delete"
665
+					LM_CRIT("timer handle %p (s) tried to delete"
672 666
 							" itself\n", tl);
673 667
 #ifdef TIMER_DEBUG
674 668
 					LOG(timerlog, "WARN: -timer_del-: called from %s(%s):%d\n",
... ...
@@ -738,7 +732,7 @@ again:
738 732
 				if (IS_IN_TIMER()){
739 733
 					/* if somebody tries to shoot himself in the foot,
740 734
 					 * warn him and ignore the delete */
741
-					LOG(L_CRIT, "BUG: timer handle %p tried to delete"
735
+					LM_CRIT("timer handle %p tried to delete"
742 736
 							" itself\n", tl);
743 737
 #ifdef TIMER_DEBUG
744 738
 					LOG(timerlog, "WARN: -timer_del-: called from %s(%s):%d\n",
... ...
@@ -825,7 +819,7 @@ void timer_allow_del(void)
825 819
 			UNSET_RUNNING_SLOW();
826 820
 	}else 
827 821
 #endif
828
-		LOG(L_CRIT, "BUG: timer_allow_del called outside a timer handle\n");
822
+		LM_CRIT("timer_allow_del called outside a timer handle\n");
829 823
 }
830 824
 
831 825
 
... ...
@@ -856,19 +850,19 @@ inline static void timer_list_expire(ticks_t t, struct timer_head* h
856 850
 		tl=h->next;
857 851
 #ifdef TIMER_DEBUG /* FIXME: replace w/ EXTRA_DEBUG */
858 852
 		if (tl==0){
859
-			LOG(L_CRIT, "BUG: timer_list_expire: tl=%p, h=%p {%p, %p}\n",
853
+			LM_CRIT("timer_list_expire: tl=%p, h=%p {%p, %p}\n",
860 854
 					tl, h, h->next, h->prev);
861 855
 			abort();
862 856
 		}else if((tl->next==0) || (tl->prev==0)){
863
-			LOG(L_CRIT, "BUG: timer_list_expire: @%d tl=%p "
857
+			LM_CRIT("timer_list_expire: @%d tl=%p "
864 858
 					"{ %p, %p, %d, %d, %p, %p, %04x, -},"
865 859
 					" h=%p {%p, %p}\n", t, 
866 860
 					tl,  tl->next, tl->prev, tl->expire, tl->initial_timeout,
867 861
 					tl->data, tl->f, tl->flags, 
868 862
 					h, h->next, h->prev);
869
-			LOG(L_CRIT, "BUG: -timer_list_expire-: cycle %d, first %p,"
863
+			LM_CRIT("-timer_list_expire-: cycle %d, first %p,"
870 864
 						"running %p\n", i, first, *running_timer);
871
-			LOG(L_CRIT, "BUG: -timer_list_expire-: added %d times"
865
+			LM_CRIT("-timer_list_expire-: added %d times"
872 866
 						", last from: %s(%s):%d, deleted %d times"
873 867
 						", last from: %s(%s):%d, init %d times, expired %d \n",
874 868
 						tl->add_calls,
... ...
@@ -944,7 +938,7 @@ static void timer_handler(void)
944 938
 	do{
945 939
 		saved_ticks=*ticks; /* protect against time running backwards */
946 940
 		if (prev_ticks>=saved_ticks){
947
-			LOG(L_CRIT, "BUG: timer_handler: backwards or still time\n");
941
+			LM_CRIT("backwards or still time\n");
948 942
 			/* try to continue */
949 943
 			prev_ticks=saved_ticks-1;
950 944
 			break;
... ...
@@ -970,7 +964,7 @@ static void timer_handler(void)
970 964
 		if ((slow_idx_t)(*t_idx-*s_idx) < (SLOW_LISTS_NO-1U))
971 965
 			(*t_idx)++;
972 966
 		else{
973
-			LOG(L_WARN, "slow timer too slow: overflow (%d - %d = %d)\n",
967
+			LM_WARN("slow timer too slow: overflow (%d - %d = %d)\n",
974 968
 					*t_idx, *s_idx, *t_idx-*s_idx);
975 969
 			/* trying to continue */
976 970
 		}
... ...
@@ -1031,7 +1025,7 @@ int register_timer(timer_function f, void* param, unsigned int interval)
1031 1025
 
1032 1026
 	t=shm_malloc(sizeof(struct sr_timer));
1033 1027
 	if (t==0){
1034
-		LOG(L_ERR, "ERROR: register_timer: out of memory\n");
1028
+		LM_ERR("out of memory\n");
1035 1029
 		goto error;
1036 1030
 	}
1037 1031
 	t->id=timer_id++;
... ...
@@ -1040,7 +1034,7 @@ int register_timer(timer_function f, void* param, unsigned int interval)
1040 1034
 	
1041 1035
 	timer_init(&t->tl, compat_old_handler, t, 0); /* is slow */
1042 1036
 	if (timer_add(&t->tl, S_TO_TICKS(interval))!=0){
1043
-		LOG(L_ERR, "ERROR: register_timer: timer_add failed\n");
1037
+		LM_ERR("timer_add failed\n");
1044 1038
 		return -1;
1045 1039
 	}
1046 1040
 	
... ...
@@ -1055,7 +1049,7 @@ error:
1055 1049
 ticks_t get_ticks_raw()
1056 1050
 {
1057 1051
 #ifndef SHM_MEM
1058
-	LOG(L_CRIT, "WARNING: get_ticks: no shared memory support compiled in"
1052
+	LM_CRIT("no shared memory support compiled in"
1059 1053
 			", returning 0 (probably wrong)");
1060 1054
 	return 0;
1061 1055
 #endif
... ...
@@ -1068,7 +1062,7 @@ ticks_t get_ticks_raw()
1068 1062
 ticks_t get_ticks()
1069 1063
 {
1070 1064
 #ifndef SHM_MEM
1071
-	LOG(L_CRIT, "WARNING: get_ticks: no shared memory support compiled in"
1065
+	LM_CRIT("no shared memory support compiled in"
1072 1066
 			", returning 0 (probably wrong)");
1073 1067
 	return 0;
1074 1068
 #endif
... ...
@@ -1083,7 +1077,8 @@ ticks_t get_ticks()
1083 1077
  * This function is intended to be executed in a special separated process
1084 1078
  * (the "slow" timer) which will run the timer handlers of all the registered
1085 1079
  * 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.
1080
+ * "main" timer process, as accurate as possible and defer the execution of the
1081
+ * timers marked as "slow" to the "slow" timer.
1087 1082
  * Implementation details:
1088 1083
  *  - it waits for a signal and then wakes up and processes
1089 1084
  *    all the lists in slow_timer_lists from [s_idx, t_idx). It will
... ...
@@ -1113,8 +1108,7 @@ void slow_timer_main()
1113 1108
 #endif
1114 1109
 		if (n==-1){
1115 1110
 			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);
1111
+			LM_ERR("sigwaitinfo failed: %s [%d]\n", strerror(errno), errno);
1118 1112
 			sleep(1);
1119 1113
 			/* try to continue */
1120 1114
 		}