Просмотр исходного кода

- solaris fixes backported: ISA ARCH detection, sigaction instead of signal,
serctl sh ready

Andrei Pelinescu-Onciul 20 лет назад
Родитель
Сommit
8bbf553c0b
3 измененных файлов с 71 добавлено и 36 удалено
  1. 28 18
      Makefile.defs
  2. 36 12
      main.c
  3. 7 6
      scripts/sc

+ 28 - 18
Makefile.defs

@@ -41,6 +41,7 @@
 #  2005-06-01  use $(LOCALBASE) instead of /usr/{local,pkg} (andrei)
 #  2005-06-01  use $(LOCALBASE) instead of /usr/{local,pkg} (andrei)
 #  2005-06-06  ppc64 support & missing ppc optimizations section added (andrei)
 #  2005-06-06  ppc64 support & missing ppc optimizations section added (andrei)
 #  2005-07-06  gcc 4.0 optimizations support (andrei)
 #  2005-07-06  gcc 4.0 optimizations support (andrei)
+#  2005-07-25  better solaris arch detection (andrei)
 
 
 
 
 # check if already included/exported
 # check if already included/exported
@@ -61,9 +62,24 @@ EXTRAVERSION = -rc1
 
 
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
-ARCH = $(shell uname -m |sed -e s/i.86/i386/ -e s/sun4u/sparc64/  \
-			-e s/armv4l/arm/ -e "s/Power Macintosh/ppc/" -e "s/cobalt/mips2/" \
+
+ifeq ($(OS),solaris)
+	GETARCH=uname -p
+else
+	GETARCH=uname -m
+endif
+
+ARCH := $(shell $(GETARCH) |sed -e s/i.86/i386/ -e s/sun4u/sparc64/  \
+			-e s/armv4l/arm/ -e "s/Power Macintosh/ppc/" \
+			-e "s/cobalt/mips2/" \
 			-e s/amd64/x86_64/ )
 			-e s/amd64/x86_64/ )
+# fix sparc -> sparc64
+ifeq ($(ARCH),sparc)
+	ifeq ($(shell uname -m),sun4u)
+		ARCH := sparc64
+	endif
+endif
+
 OSREL = $(shell uname -r)
 OSREL = $(shell uname -r)
 
 
 # TLS support
 # TLS support
@@ -345,7 +361,7 @@ endif
 # platform dependent settings
 # platform dependent settings
 
 
 # find ld & as name (gnu or solaris)
 # find ld & as name (gnu or solaris)
-ifeq ($(ARCH), sparc64)
+ifeq ($(OS), solaris)
 ifeq ($(CC_NAME), gcc)
 ifeq ($(CC_NAME), gcc)
 		LDGCC=$(shell $(CC) -v 2>&1 | grep with-ld| \
 		LDGCC=$(shell $(CC) -v 2>&1 | grep with-ld| \
 				   sed -e 's/.*--with-ld=\([^ ][^ ]*\).*/\1/' )
 				   sed -e 's/.*--with-ld=\([^ ][^ ]*\).*/\1/' )
@@ -890,20 +906,14 @@ CFLAGS+= $(CC_EXTRA_OPTS)
 
 
 # setting LDFLAGS
 # setting LDFLAGS
 ifeq	($(CC_NAME), gcc)
 ifeq	($(CC_NAME), gcc)
-ifeq		($(ARCH), sparc64)
-ifeq			($(LDTYPE), solaris)
-					# solaris ld
-					LDFLAGS+=-O2 $(PROFILE)
-					MOD_LDFLAGS=-G $(LDFLAGS)
-else			
-					#gcc and maybe others, on solaris, with gnu ld
-					LDFLAGS+=-Wl,-O2 -Wl,-E $(PROFILE) 
-					MOD_LDFLAGS=-shared $(LDFLAGS)
-endif
-else
-			#gcc and maybe others
-			LDFLAGS+=-Wl,-O2 -Wl,-E $(PROFILE) 
-			MOD_LDFLAGS=-shared $(LDFLAGS)
+ifeq		($(LDTYPE), solaris)
+		# solaris ld
+		LDFLAGS+=-O2 $(PROFILE)
+		MOD_LDFLAGS=-G $(LDFLAGS)
+else		
+		#gcc and maybe others, => gnu ld
+		LDFLAGS+=-Wl,-O2 -Wl,-E $(PROFILE) 
+		MOD_LDFLAGS=-shared $(LDFLAGS)
 endif
 endif
 endif
 endif
 ifeq	($(CC_NAME), icc)
 ifeq	($(CC_NAME), icc)
@@ -982,7 +992,7 @@ endif
 
 
 ifeq  ($(OS), solaris)
 ifeq  ($(OS), solaris)
 	DEFS+= -DHAVE_GETIPNODEBYNAME -DHAVE_SYS_SOCKIO_H -DHAVE_SCHED_YIELD \
 	DEFS+= -DHAVE_GETIPNODEBYNAME -DHAVE_SYS_SOCKIO_H -DHAVE_SCHED_YIELD \
-			-DHAVE_ALLOCA_H
+			-DHAVE_ALLOCA_H -DUSE_SIGACTION
 	ifneq ($(found_lock_method), yes)
 	ifneq ($(found_lock_method), yes)
 		DEFS+= -DUSE_PTHREAD_MUTEX  # try pthread sems
 		DEFS+= -DUSE_PTHREAD_MUTEX  # try pthread sems
 		found_lock_method=yes
 		found_lock_method=yes

+ 36 - 12
main.c

@@ -35,7 +35,8 @@
  *  2003-04-08  init_mallocs split into init_{pkg,shm}_mallocs and 
  *  2003-04-08  init_mallocs split into init_{pkg,shm}_mallocs and 
  *               init_shm_mallocs called after cmd. line parsing (andrei)
  *               init_shm_mallocs called after cmd. line parsing (andrei)
  *  2003-04-15  added tcp_disable support (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
  *  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
  *               after daemonize (so that we won't catch anymore our own
  *               SIGCHLD generated when becoming session leader) (andrei)
  *               SIGCHLD generated when becoming session leader) (andrei)
@@ -56,6 +57,7 @@
  *               crashed childvwhich still holds the lock  (andrei)
  *               crashed childvwhich still holds the lock  (andrei)
  *  2004-12-02  removed -p, extended -l to support [proto:]address[:port],
  *  2004-12-02  removed -p, extended -l to support [proto:]address[:port],
  *               added parse_phostport, parse_proto (andrei)
  *               added parse_phostport, parse_proto (andrei)
+ *  2005-07-25  use sigaction for setting the signal handlers (andrei)
  */
  */
 
 
 
 
@@ -399,6 +401,7 @@ void cleanup(show_status)
 static void kill_all_children(int signum)
 static void kill_all_children(int signum)
 {
 {
 	int r;
 	int r;
+
 	if (own_pgid) kill(0, signum);
 	if (own_pgid) kill(0, signum);
 	else if (pt)
 	else if (pt)
 		for (r=1; r<process_count(); r++)
 		for (r=1; r<process_count(); r++)
@@ -407,6 +410,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
 /* if this handler is called, a critical timeout has occured while
  * waiting for the children to finish => we should kill everything and exit */
  * waiting for the children to finish => we should kill everything and exit */
 static void sig_alarm_kill(int signo)
 static void sig_alarm_kill(int signo)
@@ -503,17 +528,17 @@ void handle_sigs()
 #endif
 #endif
 			/* exit */
 			/* exit */
 			kill_all_children(SIGTERM);
 			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");
 				LOG(L_ERR, "ERROR: could not install SIGALARM handler\n");
 				/* continue, the process will die anyway if no
 				/* continue, the process will die anyway if no
 				 * alarm is installed which is exactly what we want */
 				 * alarm is installed which is exactly what we want */
 			}
 			}
 			alarm(60); /* 1 minute close timeout */
 			alarm(60); /* 1 minute close timeout */
 			while(wait(0) > 0); /* wait for all the children to terminate*/
 			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*/
 			cleanup(1); /* cleanup & show status*/
 			alarm(0);
 			alarm(0);
-			signal(SIGALRM, SIG_IGN);
+			set_sig_h(SIGALRM, SIG_IGN);
 			DBG("terminating due to SIGCHLD\n");
 			DBG("terminating due to SIGCHLD\n");
 			exit(0);
 			exit(0);
 			break;
 			break;
@@ -587,33 +612,32 @@ static void sig_usr(int signo)
 int install_sigs()
 int install_sigs()
 {
 {
 	/* added by jku: add exit handler */
 	/* 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");
 		DPrint("ERROR: no SIGINT signal handler can be installed\n");
 		goto error;
 		goto error;
 	}
 	}
 	/* if we debug and write to a pipe, we want to exit nicely too */
 	/* 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");
 		DPrint("ERROR: no SIGINT signal handler can be installed\n");
 		goto error;
 		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");
 		DPrint("ERROR: no SIGUSR1 signal handler can be installed\n");
 		goto error;
 		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");
 		DPrint("ERROR: no SIGCHLD signal handler can be installed\n");
 		goto error;
 		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");
 		DPrint("ERROR: no SIGTERM signal handler can be installed\n");
 		goto error;
 		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");
 		DPrint("ERROR: no SIGHUP signal handler can be installed\n");
 		goto error;
 		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");
 		DPrint("ERROR: no SIGUSR2 signal handler can be installed\n");
 		goto error;
 		goto error;
 	}
 	}

+ 7 - 6
scripts/sc

@@ -26,6 +26,7 @@ SYSLOG=1 # 0=output to console, 1=output to syslog
 STARTOPTIONS= # for example -dddd
 STARTOPTIONS= # for example -dddd
 DIR=`dirname $0`
 DIR=`dirname $0`
 SERBIN=$DIR/ser
 SERBIN=$DIR/ser
+AWK=awk
 
 
 # ser's FIFO server
 # ser's FIFO server
 if [ -z "$SER_FIFO" ]; then
 if [ -z "$SER_FIFO" ]; then
@@ -198,8 +199,8 @@ get_my_host() {
 # calculate name and domain of current user
 # calculate name and domain of current user
 set_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
 	if [ -z "$SERDOMAIN" ] ; then
 		SERDOMAIN="$SIP_DOMAIN"
 		SERDOMAIN="$SIP_DOMAIN"
@@ -286,7 +287,7 @@ filter_fl()
 {
 {
 #	tail +2
 #	tail +2
 	
 	
-	awk 'BEGIN {line=0;IGNORECASE=1;}
+	$AWK 'BEGIN {line=0;IGNORECASE=1;}
 		{line++}
 		{line++}
 		line==1 && /^200 ok/ { next }
 		line==1 && /^200 ok/ { next }
 		{ print }'
 		{ print }'
@@ -911,7 +912,7 @@ case $1 in
 			exit 1
 			exit 1
 		fi
 		fi
 		chmod a+w $path
 		chmod a+w $path
-		trap "rm $path;  clear; echo sc monitor ^C-ed; exit 1" 2
+		trap "rm $path;  clear; echo 'sc monitor ^C-ed'; exit 1" 2
 		attempt=0
 		attempt=0
 		if [ "$2" == "" ]; then
 		if [ "$2" == "" ]; then
 		    loops=-1;
 		    loops=-1;
@@ -920,7 +921,7 @@ case $1 in
 		fi
 		fi
 		clear
 		clear
 		while [ $loops -ne $attempt ] ; do
 		while [ $loops -ne $attempt ] ; do
-			attempt=$(($attempt + 1))
+			attempt=`expr $attempt + 1`
 			#clear
 			#clear
 			tput cup 0 0
 			tput cup 0 0
 			print_stats $name $path $attempt
 			print_stats $name $path $attempt
@@ -970,7 +971,7 @@ case $1 in
 		;;
 		;;
 
 
 	online)
 	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 $?
 		exit $?
 		;;
 		;;