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 60
  *  2005-06-16  always record the pid in pt[process_no].pid twice: once in the
60 61
  *               parent & once in the child to avoid a short window when one
61 62
  *               of them might use it "unset" (andrei)
63
+ *  2005-07-25  use sigaction for setting the signal handlers (andrei)
62 64
  */
63 65
 
64 66
 
... ...
@@ -407,6 +409,7 @@ void cleanup(show_status)
407 409
 static void kill_all_children(int signum)
408 410
 {
409 411
 	int r;
412
+
410 413
 	if (own_pgid) kill(0, signum);
411 414
 	else if (pt)
412 415
 		for (r=1; r<process_count(); r++)
... ...
@@ -415,6 +418,28 @@ static void kill_all_children(int signum)
415 418
 
416 419
 
417 420
 
421
+#ifdef USE_SIGACTION
422
+static void (*set_sig_h(int sig, void (*handler) (int) ))(int)
423
+{
424
+	struct sigaction act;
425
+	struct sigaction old;
426
+	
427
+	memset(&act, 0, sizeof(act));
428
+	act.sa_handler=handler;
429
+	/*
430
+	sigemptyset(&act.sa_mask);
431
+	act.sa_flags=0;
432
+	*/
433
+	LOG(L_CRIT, "setting signal %d to %p\n", sig, handler);
434
+	/* sa_sigaction not set, we use sa_hanlder instead */ 
435
+	return (sigaction (sig, &act, &old)==-1)?SIG_ERR:old.sa_handler;
436
+}
437
+#else
438
+#define set_sig_h signal
439
+#endif
440
+
441
+
442
+
418 443
 /* if this handler is called, a critical timeout has occured while
419 444
  * waiting for the children to finish => we should kill everything and exit */
420 445
 static void sig_alarm_kill(int signo)
... ...
@@ -511,17 +536,17 @@ void handle_sigs()
511 536
 #endif
512 537
 			/* exit */
513 538
 			kill_all_children(SIGTERM);
514
-			if (signal(SIGALRM, sig_alarm_kill) == SIG_ERR ) {
539
+			if (set_sig_h(SIGALRM, sig_alarm_kill) == SIG_ERR ) {
515 540
 				LOG(L_ERR, "ERROR: could not install SIGALARM handler\n");
516 541
 				/* continue, the process will die anyway if no
517 542
 				 * alarm is installed which is exactly what we want */
518 543
 			}
519 544
 			alarm(60); /* 1 minute close timeout */
520 545
 			while(wait(0) > 0); /* wait for all the children to terminate*/
521
-			signal(SIGALRM, sig_alarm_abort);
546
+			set_sig_h(SIGALRM, sig_alarm_abort);
522 547
 			cleanup(1); /* cleanup & show status*/
523 548
 			alarm(0);
524
-			signal(SIGALRM, SIG_IGN);
549
+			set_sig_h(SIGALRM, SIG_IGN);
525 550
 			DBG("terminating due to SIGCHLD\n");
526 551
 			exit(0);
527 552
 			break;
... ...
@@ -595,33 +620,32 @@ static void sig_usr(int signo)
595 620
 int install_sigs()
596 621
 {
597 622
 	/* added by jku: add exit handler */
598
-	if (signal(SIGINT, sig_usr) == SIG_ERR ) {
623
+	if (set_sig_h(SIGINT, sig_usr) == SIG_ERR ) {
599 624
 		DPrint("ERROR: no SIGINT signal handler can be installed\n");
600 625
 		goto error;
601 626
 	}
602 627
 	/* if we debug and write to a pipe, we want to exit nicely too */
603
-	if (signal(SIGPIPE, sig_usr) == SIG_ERR ) {
628
+	if (set_sig_h(SIGPIPE, sig_usr) == SIG_ERR ) {
604 629
 		DPrint("ERROR: no SIGINT signal handler can be installed\n");
605 630
 		goto error;
606 631
 	}
607
-	
608
-	if (signal(SIGUSR1, sig_usr)  == SIG_ERR ) {
632
+	if (set_sig_h(SIGUSR1, sig_usr)  == SIG_ERR ) {
609 633
 		DPrint("ERROR: no SIGUSR1 signal handler can be installed\n");
610 634
 		goto error;
611 635
 	}
612
-	if (signal(SIGCHLD , sig_usr)  == SIG_ERR ) {
636
+	if (set_sig_h(SIGCHLD , sig_usr)  == SIG_ERR ) {
613 637
 		DPrint("ERROR: no SIGCHLD signal handler can be installed\n");
614 638
 		goto error;
615 639
 	}
616
-	if (signal(SIGTERM , sig_usr)  == SIG_ERR ) {
640
+	if (set_sig_h(SIGTERM , sig_usr)  == SIG_ERR ) {
617 641
 		DPrint("ERROR: no SIGTERM signal handler can be installed\n");
618 642
 		goto error;
619 643
 	}
620
-	if (signal(SIGHUP , sig_usr)  == SIG_ERR ) {
644
+	if (set_sig_h(SIGHUP , sig_usr)  == SIG_ERR ) {
621 645
 		DPrint("ERROR: no SIGHUP signal handler can be installed\n");
622 646
 		goto error;
623 647
 	}
624
-	if (signal(SIGUSR2 , sig_usr)  == SIG_ERR ) {
648
+	if (set_sig_h(SIGUSR2 , sig_usr)  == SIG_ERR ) {
625 649
 		DPrint("ERROR: no SIGUSR2 signal handler can be installed\n");
626 650
 		goto error;
627 651
 	}
... ...
@@ -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 199
 # calculate name and domain of current user
199 200
 set_user() {
200 201
 
201
-	SERUSER=`echo $1|awk -F @ '{print $1}'`
202
-	SERDOMAIN=`echo $1|awk -F @ '{print $2}'`
202
+	SERUSER=`echo $1|$AWK -F @ '{print $1}'`
203
+	SERDOMAIN=`echo $1|$AWK -F @ '{print $2}'`
203 204
 
204 205
 	if [ -z "$SERDOMAIN" ] ; then
205 206
 		SERDOMAIN="$SIP_DOMAIN"
... ...
@@ -286,7 +287,7 @@ filter_fl()
286 287
 {
287 288
 #	tail +2
288 289
 	
289
-	awk 'BEGIN {line=0;IGNORECASE=1;}
290
+	$AWK 'BEGIN {line=0;IGNORECASE=1;}
290 291
 		{line++}
291 292
 		line==1 && /^200 ok/ { next }
292 293
 		{ print }'
... ...
@@ -970,7 +971,7 @@ case $1 in
970 971
 		;;
971 972
 
972 973
 	online)
973
-		fifo_cmd ul_dump |grep aor| awk '{print $3}' | sort | sort -mu
974
+		fifo_cmd ul_dump |grep aor| $AWK '{print $3}' | sort | sort -mu
974 975
 		exit $?
975 976
 		;;
976 977