Browse code

- solaris fix: sigaction() instead of signal()

Andrei Pelinescu-Onciul authored on 25/07/2005 16:28:38
Showing 3 changed files
... ...
@@ -1019,7 +1019,7 @@ endif
1019 1019
 
1020 1020
 ifeq  ($(OS), solaris)
1021 1021
 	DEFS+= -DHAVE_GETIPNODEBYNAME -DHAVE_SYS_SOCKIO_H -DHAVE_SCHED_YIELD \
1022
-			-DHAVE_ALLOCA_H
1022
+			-DHAVE_ALLOCA_H -DUSE_SIGACTION
1023 1023
 	ifneq ($(found_lock_method), yes)
1024 1024
 		DEFS+= -DUSE_PTHREAD_MUTEX  # try pthread sems
1025 1025
 		found_lock_method=yes
... ...
@@ -35,7 +35,8 @@
35 35
  *  2003-04-08  init_mallocs split into init_{pkg,shm}_mallocs and 
36 36
  *               init_shm_mallocs called after cmd. line parsing (andrei)
37 37
  *  2003-04-15  added tcp_disable support (andrei)
38
- *  2003-05-09  closelog() before openlog to force opening a new fd (needed on solaris) (andrei)
38
+ *  2003-05-09  closelog() before openlog to force opening a new fd 
39
+ *               (needed on solaris) (andrei)
39 40
  *  2003-06-11  moved all signal handlers init. in install_sigs and moved it
40 41
  *               after daemonize (so that we won't catch anymore our own
41 42
  *               SIGCHLD generated when becoming session leader) (andrei)
... ...
@@ -59,6 +60,7 @@
59 59
  *  2005-06-16  always record the pid in pt[process_no].pid twice: once in the
60 60
  *               parent & once in the child to avoid a short window when one
61 61
  *               of them might use it "unset" (andrei)
62
+ *  2005-07-25  use sigaction for setting the signal handlers (andrei)
62 63
  */
63 64
 
64 65
 
... ...
@@ -407,6 +409,7 @@ void cleanup(show_status)
407 407
 static void kill_all_children(int signum)
408 408
 {
409 409
 	int r;
410
+
410 411
 	if (own_pgid) kill(0, signum);
411 412
 	else if (pt)
412 413
 		for (r=1; r<process_count(); r++)
... ...
@@ -415,6 +418,28 @@ static void kill_all_children(int signum)
415 415
 
416 416
 
417 417
 
418
+#ifdef USE_SIGACTION
419
+static void (*set_sig_h(int sig, void (*handler) (int) ))(int)
420
+{
421
+	struct sigaction act;
422
+	struct sigaction old;
423
+	
424
+	memset(&act, 0, sizeof(act));
425
+	act.sa_handler=handler;
426
+	/*
427
+	sigemptyset(&act.sa_mask);
428
+	act.sa_flags=0;
429
+	*/
430
+	LOG(L_CRIT, "setting signal %d to %p\n", sig, handler);
431
+	/* sa_sigaction not set, we use sa_hanlder instead */ 
432
+	return (sigaction (sig, &act, &old)==-1)?SIG_ERR:old.sa_handler;
433
+}
434
+#else
435
+#define set_sig_h signal
436
+#endif
437
+
438
+
439
+
418 440
 /* if this handler is called, a critical timeout has occured while
419 441
  * waiting for the children to finish => we should kill everything and exit */
420 442
 static void sig_alarm_kill(int signo)
... ...
@@ -511,17 +536,17 @@ void handle_sigs()
511 511
 #endif
512 512
 			/* exit */
513 513
 			kill_all_children(SIGTERM);
514
-			if (signal(SIGALRM, sig_alarm_kill) == SIG_ERR ) {
514
+			if (set_sig_h(SIGALRM, sig_alarm_kill) == SIG_ERR ) {
515 515
 				LOG(L_ERR, "ERROR: could not install SIGALARM handler\n");
516 516
 				/* continue, the process will die anyway if no
517 517
 				 * alarm is installed which is exactly what we want */
518 518
 			}
519 519
 			alarm(60); /* 1 minute close timeout */
520 520
 			while(wait(0) > 0); /* wait for all the children to terminate*/
521
-			signal(SIGALRM, sig_alarm_abort);
521
+			set_sig_h(SIGALRM, sig_alarm_abort);
522 522
 			cleanup(1); /* cleanup & show status*/
523 523
 			alarm(0);
524
-			signal(SIGALRM, SIG_IGN);
524
+			set_sig_h(SIGALRM, SIG_IGN);
525 525
 			DBG("terminating due to SIGCHLD\n");
526 526
 			exit(0);
527 527
 			break;
... ...
@@ -595,33 +620,32 @@ static void sig_usr(int signo)
595 595
 int install_sigs()
596 596
 {
597 597
 	/* added by jku: add exit handler */
598
-	if (signal(SIGINT, sig_usr) == SIG_ERR ) {
598
+	if (set_sig_h(SIGINT, sig_usr) == SIG_ERR ) {
599 599
 		DPrint("ERROR: no SIGINT signal handler can be installed\n");
600 600
 		goto error;
601 601
 	}
602 602
 	/* if we debug and write to a pipe, we want to exit nicely too */
603
-	if (signal(SIGPIPE, sig_usr) == SIG_ERR ) {
603
+	if (set_sig_h(SIGPIPE, sig_usr) == SIG_ERR ) {
604 604
 		DPrint("ERROR: no SIGINT signal handler can be installed\n");
605 605
 		goto error;
606 606
 	}
607
-	
608
-	if (signal(SIGUSR1, sig_usr)  == SIG_ERR ) {
607
+	if (set_sig_h(SIGUSR1, sig_usr)  == SIG_ERR ) {
609 608
 		DPrint("ERROR: no SIGUSR1 signal handler can be installed\n");
610 609
 		goto error;
611 610
 	}
612
-	if (signal(SIGCHLD , sig_usr)  == SIG_ERR ) {
611
+	if (set_sig_h(SIGCHLD , sig_usr)  == SIG_ERR ) {
613 612
 		DPrint("ERROR: no SIGCHLD signal handler can be installed\n");
614 613
 		goto error;
615 614
 	}
616
-	if (signal(SIGTERM , sig_usr)  == SIG_ERR ) {
615
+	if (set_sig_h(SIGTERM , sig_usr)  == SIG_ERR ) {
617 616
 		DPrint("ERROR: no SIGTERM signal handler can be installed\n");
618 617
 		goto error;
619 618
 	}
620
-	if (signal(SIGHUP , sig_usr)  == SIG_ERR ) {
619
+	if (set_sig_h(SIGHUP , sig_usr)  == SIG_ERR ) {
621 620
 		DPrint("ERROR: no SIGHUP signal handler can be installed\n");
622 621
 		goto error;
623 622
 	}
624
-	if (signal(SIGUSR2 , sig_usr)  == SIG_ERR ) {
623
+	if (set_sig_h(SIGUSR2 , sig_usr)  == SIG_ERR ) {
625 624
 		DPrint("ERROR: no SIGUSR2 signal handler can be installed\n");
626 625
 		goto error;
627 626
 	}
... ...
@@ -26,6 +26,7 @@ SYSLOG=1 # 0=output to console, 1=output to syslog
26 26
 STARTOPTIONS= # for example -dddd
27 27
 DIR=`dirname $0`
28 28
 SERBIN=$DIR/ser
29
+AWK=awk
29 30
 
30 31
 # ser's FIFO server
31 32
 if [ -z "$SER_FIFO" ]; then
... ...
@@ -198,8 +199,8 @@ get_my_host() {
198 198
 # calculate name and domain of current user
199 199
 set_user() {
200 200
 
201
-	SERUSER=`echo $1|awk -F @ '{print $1}'`
202
-	SERDOMAIN=`echo $1|awk -F @ '{print $2}'`
201
+	SERUSER=`echo $1|$AWK -F @ '{print $1}'`
202
+	SERDOMAIN=`echo $1|$AWK -F @ '{print $2}'`
203 203
 
204 204
 	if [ -z "$SERDOMAIN" ] ; then
205 205
 		SERDOMAIN="$SIP_DOMAIN"
... ...
@@ -286,7 +287,7 @@ filter_fl()
286 286
 {
287 287
 #	tail +2
288 288
 	
289
-	awk 'BEGIN {line=0;IGNORECASE=1;}
289
+	$AWK 'BEGIN {line=0;IGNORECASE=1;}
290 290
 		{line++}
291 291
 		line==1 && /^200 ok/ { next }
292 292
 		{ print }'
... ...
@@ -970,7 +971,7 @@ case $1 in
970 970
 		;;
971 971
 
972 972
 	online)
973
-		fifo_cmd ul_dump |grep aor| awk '{print $3}' | sort | sort -mu
973
+		fifo_cmd ul_dump |grep aor| $AWK '{print $3}' | sort | sort -mu
974 974
 		exit $?
975 975
 		;;
976 976