Selaa lähdekoodia

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

Andrei Pelinescu-Onciul 20 vuotta sitten
vanhempi
commit
02dae965aa
3 muutettua tiedostoa jossa 42 lisäystä ja 17 poistoa
  1. 1 1
      Makefile.defs
  2. 36 12
      main.c
  3. 5 4
      scripts/sc

+ 1 - 1
Makefile.defs

@@ -1019,7 +1019,7 @@ endif
 
 ifeq  ($(OS), solaris)
 	DEFS+= -DHAVE_GETIPNODEBYNAME -DHAVE_SYS_SOCKIO_H -DHAVE_SCHED_YIELD \
-			-DHAVE_ALLOCA_H
+			-DHAVE_ALLOCA_H -DUSE_SIGACTION
 	ifneq ($(found_lock_method), yes)
 		DEFS+= -DUSE_PTHREAD_MUTEX  # try pthread sems
 		found_lock_method=yes

+ 36 - 12
main.c

@@ -35,7 +35,8 @@
  *  2003-04-08  init_mallocs split into init_{pkg,shm}_mallocs and 
  *               init_shm_mallocs called after cmd. line parsing (andrei)
  *  2003-04-15  added tcp_disable support (andrei)
- *  2003-05-09  closelog() before openlog to force opening a new fd (needed on solaris) (andrei)
+ *  2003-05-09  closelog() before openlog to force opening a new fd 
+ *               (needed on solaris) (andrei)
  *  2003-06-11  moved all signal handlers init. in install_sigs and moved it
  *               after daemonize (so that we won't catch anymore our own
  *               SIGCHLD generated when becoming session leader) (andrei)
@@ -59,6 +60,7 @@
  *  2005-06-16  always record the pid in pt[process_no].pid twice: once in the
  *               parent & once in the child to avoid a short window when one
  *               of them might use it "unset" (andrei)
+ *  2005-07-25  use sigaction for setting the signal handlers (andrei)
  */
 
 
@@ -407,6 +409,7 @@ void cleanup(show_status)
 static void kill_all_children(int signum)
 {
 	int r;
+
 	if (own_pgid) kill(0, signum);
 	else if (pt)
 		for (r=1; r<process_count(); r++)
@@ -415,6 +418,28 @@ static void kill_all_children(int signum)
 
 
 
+#ifdef USE_SIGACTION
+static void (*set_sig_h(int sig, void (*handler) (int) ))(int)
+{
+	struct sigaction act;
+	struct sigaction old;
+	
+	memset(&act, 0, sizeof(act));
+	act.sa_handler=handler;
+	/*
+	sigemptyset(&act.sa_mask);
+	act.sa_flags=0;
+	*/
+	LOG(L_CRIT, "setting signal %d to %p\n", sig, handler);
+	/* sa_sigaction not set, we use sa_hanlder instead */ 
+	return (sigaction (sig, &act, &old)==-1)?SIG_ERR:old.sa_handler;
+}
+#else
+#define set_sig_h signal
+#endif
+
+
+
 /* if this handler is called, a critical timeout has occured while
  * waiting for the children to finish => we should kill everything and exit */
 static void sig_alarm_kill(int signo)
@@ -511,17 +536,17 @@ void handle_sigs()
 #endif
 			/* exit */
 			kill_all_children(SIGTERM);
-			if (signal(SIGALRM, sig_alarm_kill) == SIG_ERR ) {
+			if (set_sig_h(SIGALRM, sig_alarm_kill) == SIG_ERR ) {
 				LOG(L_ERR, "ERROR: could not install SIGALARM handler\n");
 				/* continue, the process will die anyway if no
 				 * alarm is installed which is exactly what we want */
 			}
 			alarm(60); /* 1 minute close timeout */
 			while(wait(0) > 0); /* wait for all the children to terminate*/
-			signal(SIGALRM, sig_alarm_abort);
+			set_sig_h(SIGALRM, sig_alarm_abort);
 			cleanup(1); /* cleanup & show status*/
 			alarm(0);
-			signal(SIGALRM, SIG_IGN);
+			set_sig_h(SIGALRM, SIG_IGN);
 			DBG("terminating due to SIGCHLD\n");
 			exit(0);
 			break;
@@ -595,33 +620,32 @@ static void sig_usr(int signo)
 int install_sigs()
 {
 	/* added by jku: add exit handler */
-	if (signal(SIGINT, sig_usr) == SIG_ERR ) {
+	if (set_sig_h(SIGINT, sig_usr) == SIG_ERR ) {
 		DPrint("ERROR: no SIGINT signal handler can be installed\n");
 		goto error;
 	}
 	/* if we debug and write to a pipe, we want to exit nicely too */
-	if (signal(SIGPIPE, sig_usr) == SIG_ERR ) {
+	if (set_sig_h(SIGPIPE, sig_usr) == SIG_ERR ) {
 		DPrint("ERROR: no SIGINT signal handler can be installed\n");
 		goto error;
 	}
-	
-	if (signal(SIGUSR1, sig_usr)  == SIG_ERR ) {
+	if (set_sig_h(SIGUSR1, sig_usr)  == SIG_ERR ) {
 		DPrint("ERROR: no SIGUSR1 signal handler can be installed\n");
 		goto error;
 	}
-	if (signal(SIGCHLD , sig_usr)  == SIG_ERR ) {
+	if (set_sig_h(SIGCHLD , sig_usr)  == SIG_ERR ) {
 		DPrint("ERROR: no SIGCHLD signal handler can be installed\n");
 		goto error;
 	}
-	if (signal(SIGTERM , sig_usr)  == SIG_ERR ) {
+	if (set_sig_h(SIGTERM , sig_usr)  == SIG_ERR ) {
 		DPrint("ERROR: no SIGTERM signal handler can be installed\n");
 		goto error;
 	}
-	if (signal(SIGHUP , sig_usr)  == SIG_ERR ) {
+	if (set_sig_h(SIGHUP , sig_usr)  == SIG_ERR ) {
 		DPrint("ERROR: no SIGHUP signal handler can be installed\n");
 		goto error;
 	}
-	if (signal(SIGUSR2 , sig_usr)  == SIG_ERR ) {
+	if (set_sig_h(SIGUSR2 , sig_usr)  == SIG_ERR ) {
 		DPrint("ERROR: no SIGUSR2 signal handler can be installed\n");
 		goto error;
 	}

+ 5 - 4
scripts/sc

@@ -26,6 +26,7 @@ SYSLOG=1 # 0=output to console, 1=output to syslog
 STARTOPTIONS= # for example -dddd
 DIR=`dirname $0`
 SERBIN=$DIR/ser
+AWK=awk
 
 # ser's FIFO server
 if [ -z "$SER_FIFO" ]; then
@@ -198,8 +199,8 @@ get_my_host() {
 # calculate name and domain of current user
 set_user() {
 
-	SERUSER=`echo $1|awk -F @ '{print $1}'`
-	SERDOMAIN=`echo $1|awk -F @ '{print $2}'`
+	SERUSER=`echo $1|$AWK -F @ '{print $1}'`
+	SERDOMAIN=`echo $1|$AWK -F @ '{print $2}'`
 
 	if [ -z "$SERDOMAIN" ] ; then
 		SERDOMAIN="$SIP_DOMAIN"
@@ -286,7 +287,7 @@ filter_fl()
 {
 #	tail +2
 	
-	awk 'BEGIN {line=0;IGNORECASE=1;}
+	$AWK 'BEGIN {line=0;IGNORECASE=1;}
 		{line++}
 		line==1 && /^200 ok/ { next }
 		{ print }'
@@ -970,7 +971,7 @@ case $1 in
 		;;
 
 	online)
-		fifo_cmd ul_dump |grep aor| awk '{print $3}' | sort | sort -mu
+		fifo_cmd ul_dump |grep aor| $AWK '{print $3}' | sort | sort -mu
 		exit $?
 		;;