Browse code

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

Andrei Pelinescu-Onciul authored on 25/07/2005 16:56:24
Showing 3 changed files
... ...
@@ -41,6 +41,7 @@
41 41
 #  2005-06-01  use $(LOCALBASE) instead of /usr/{local,pkg} (andrei)
42 42
 #  2005-06-06  ppc64 support & missing ppc optimizations section added (andrei)
43 43
 #  2005-07-06  gcc 4.0 optimizations support (andrei)
44
+#  2005-07-25  better solaris arch detection (andrei)
44 45
 
45 46
 
46 47
 # check if already included/exported
... ...
@@ -61,9 +62,24 @@ EXTRAVERSION = -rc1
61 62
 
62 63
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
63 64
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
64
-ARCH = $(shell uname -m |sed -e s/i.86/i386/ -e s/sun4u/sparc64/  \
65
-			-e s/armv4l/arm/ -e "s/Power Macintosh/ppc/" -e "s/cobalt/mips2/" \
65
+
66
+ifeq ($(OS),solaris)
67
+	GETARCH=uname -p
68
+else
69
+	GETARCH=uname -m
70
+endif
71
+
72
+ARCH := $(shell $(GETARCH) |sed -e s/i.86/i386/ -e s/sun4u/sparc64/  \
73
+			-e s/armv4l/arm/ -e "s/Power Macintosh/ppc/" \
74
+			-e "s/cobalt/mips2/" \
66 75
 			-e s/amd64/x86_64/ )
76
+# fix sparc -> sparc64
77
+ifeq ($(ARCH),sparc)
78
+	ifeq ($(shell uname -m),sun4u)
79
+		ARCH := sparc64
80
+	endif
81
+endif
82
+
67 83
 OSREL = $(shell uname -r)
68 84
 
69 85
 # TLS support
... ...
@@ -345,7 +361,7 @@ endif
345 361
 # platform dependent settings
346 362
 
347 363
 # find ld & as name (gnu or solaris)
348
-ifeq ($(ARCH), sparc64)
364
+ifeq ($(OS), solaris)
349 365
 ifeq ($(CC_NAME), gcc)
350 366
 		LDGCC=$(shell $(CC) -v 2>&1 | grep with-ld| \
351 367
 				   sed -e 's/.*--with-ld=\([^ ][^ ]*\).*/\1/' )
... ...
@@ -890,20 +906,14 @@ CFLAGS+= $(CC_EXTRA_OPTS)
890 906
 
891 907
 # setting LDFLAGS
892 908
 ifeq	($(CC_NAME), gcc)
893
-ifeq		($(ARCH), sparc64)
894
-ifeq			($(LDTYPE), solaris)
895
-					# solaris ld
896
-					LDFLAGS+=-O2 $(PROFILE)
897
-					MOD_LDFLAGS=-G $(LDFLAGS)
898
-else			
899
-					#gcc and maybe others, on solaris, with gnu ld
900
-					LDFLAGS+=-Wl,-O2 -Wl,-E $(PROFILE) 
901
-					MOD_LDFLAGS=-shared $(LDFLAGS)
902
-endif
903
-else
904
-			#gcc and maybe others
905
-			LDFLAGS+=-Wl,-O2 -Wl,-E $(PROFILE) 
906
-			MOD_LDFLAGS=-shared $(LDFLAGS)
909
+ifeq		($(LDTYPE), solaris)
910
+		# solaris ld
911
+		LDFLAGS+=-O2 $(PROFILE)
912
+		MOD_LDFLAGS=-G $(LDFLAGS)
913
+else		
914
+		#gcc and maybe others, => gnu ld
915
+		LDFLAGS+=-Wl,-O2 -Wl,-E $(PROFILE) 
916
+		MOD_LDFLAGS=-shared $(LDFLAGS)
907 917
 endif
908 918
 endif
909 919
 ifeq	($(CC_NAME), icc)
... ...
@@ -982,7 +992,7 @@ endif
982 992
 
983 993
 ifeq  ($(OS), solaris)
984 994
 	DEFS+= -DHAVE_GETIPNODEBYNAME -DHAVE_SYS_SOCKIO_H -DHAVE_SCHED_YIELD \
985
-			-DHAVE_ALLOCA_H
995
+			-DHAVE_ALLOCA_H -DUSE_SIGACTION
986 996
 	ifneq ($(found_lock_method), yes)
987 997
 		DEFS+= -DUSE_PTHREAD_MUTEX  # try pthread sems
988 998
 		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)
... ...
@@ -56,6 +57,7 @@
56 57
  *               crashed childvwhich still holds the lock  (andrei)
57 58
  *  2004-12-02  removed -p, extended -l to support [proto:]address[:port],
58 59
  *               added parse_phostport, parse_proto (andrei)
60
+ *  2005-07-25  use sigaction for setting the signal handlers (andrei)
59 61
  */
60 62
 
61 63
 
... ...
@@ -399,6 +401,7 @@ void cleanup(show_status)
399 401
 static void kill_all_children(int signum)
400 402
 {
401 403
 	int r;
404
+
402 405
 	if (own_pgid) kill(0, signum);
403 406
 	else if (pt)
404 407
 		for (r=1; r<process_count(); r++)
... ...
@@ -407,6 +410,28 @@ static void kill_all_children(int signum)
407 410
 
408 411
 
409 412
 
413
+#ifdef USE_SIGACTION
414
+static void (*set_sig_h(int sig, void (*handler) (int) ))(int)
415
+{
416
+	struct sigaction act;
417
+	struct sigaction old;
418
+	
419
+	memset(&act, 0, sizeof(act));
420
+	act.sa_handler=handler;
421
+	/*
422
+	sigemptyset(&act.sa_mask);
423
+	act.sa_flags=0;
424
+	*/
425
+	LOG(L_CRIT, "setting signal %d to %p\n", sig, handler);
426
+	/* sa_sigaction not set, we use sa_hanlder instead */ 
427
+	return (sigaction (sig, &act, &old)==-1)?SIG_ERR:old.sa_handler;
428
+}
429
+#else
430
+#define set_sig_h signal
431
+#endif
432
+
433
+
434
+
410 435
 /* if this handler is called, a critical timeout has occured while
411 436
  * waiting for the children to finish => we should kill everything and exit */
412 437
 static void sig_alarm_kill(int signo)
... ...
@@ -503,17 +528,17 @@ void handle_sigs()
503 528
 #endif
504 529
 			/* exit */
505 530
 			kill_all_children(SIGTERM);
506
-			if (signal(SIGALRM, sig_alarm_kill) == SIG_ERR ) {
531
+			if (set_sig_h(SIGALRM, sig_alarm_kill) == SIG_ERR ) {
507 532
 				LOG(L_ERR, "ERROR: could not install SIGALARM handler\n");
508 533
 				/* continue, the process will die anyway if no
509 534
 				 * alarm is installed which is exactly what we want */
510 535
 			}
511 536
 			alarm(60); /* 1 minute close timeout */
512 537
 			while(wait(0) > 0); /* wait for all the children to terminate*/
513
-			signal(SIGALRM, sig_alarm_abort);
538
+			set_sig_h(SIGALRM, sig_alarm_abort);
514 539
 			cleanup(1); /* cleanup & show status*/
515 540
 			alarm(0);
516
-			signal(SIGALRM, SIG_IGN);
541
+			set_sig_h(SIGALRM, SIG_IGN);
517 542
 			DBG("terminating due to SIGCHLD\n");
518 543
 			exit(0);
519 544
 			break;
... ...
@@ -587,33 +612,32 @@ static void sig_usr(int signo)
587 612
 int install_sigs()
588 613
 {
589 614
 	/* added by jku: add exit handler */
590
-	if (signal(SIGINT, sig_usr) == SIG_ERR ) {
615
+	if (set_sig_h(SIGINT, sig_usr) == SIG_ERR ) {
591 616
 		DPrint("ERROR: no SIGINT signal handler can be installed\n");
592 617
 		goto error;
593 618
 	}
594 619
 	/* if we debug and write to a pipe, we want to exit nicely too */
595
-	if (signal(SIGPIPE, sig_usr) == SIG_ERR ) {
620
+	if (set_sig_h(SIGPIPE, sig_usr) == SIG_ERR ) {
596 621
 		DPrint("ERROR: no SIGINT signal handler can be installed\n");
597 622
 		goto error;
598 623
 	}
599
-	
600
-	if (signal(SIGUSR1, sig_usr)  == SIG_ERR ) {
624
+	if (set_sig_h(SIGUSR1, sig_usr)  == SIG_ERR ) {
601 625
 		DPrint("ERROR: no SIGUSR1 signal handler can be installed\n");
602 626
 		goto error;
603 627
 	}
604
-	if (signal(SIGCHLD , sig_usr)  == SIG_ERR ) {
628
+	if (set_sig_h(SIGCHLD , sig_usr)  == SIG_ERR ) {
605 629
 		DPrint("ERROR: no SIGCHLD signal handler can be installed\n");
606 630
 		goto error;
607 631
 	}
608
-	if (signal(SIGTERM , sig_usr)  == SIG_ERR ) {
632
+	if (set_sig_h(SIGTERM , sig_usr)  == SIG_ERR ) {
609 633
 		DPrint("ERROR: no SIGTERM signal handler can be installed\n");
610 634
 		goto error;
611 635
 	}
612
-	if (signal(SIGHUP , sig_usr)  == SIG_ERR ) {
636
+	if (set_sig_h(SIGHUP , sig_usr)  == SIG_ERR ) {
613 637
 		DPrint("ERROR: no SIGHUP signal handler can be installed\n");
614 638
 		goto error;
615 639
 	}
616
-	if (signal(SIGUSR2 , sig_usr)  == SIG_ERR ) {
640
+	if (set_sig_h(SIGUSR2 , sig_usr)  == SIG_ERR ) {
617 641
 		DPrint("ERROR: no SIGUSR2 signal handler can be installed\n");
618 642
 		goto error;
619 643
 	}
... ...
@@ -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 }'
... ...
@@ -911,7 +912,7 @@ case $1 in
911 912
 			exit 1
912 913
 		fi
913 914
 		chmod a+w $path
914
-		trap "rm $path;  clear; echo sc monitor ^C-ed; exit 1" 2
915
+		trap "rm $path;  clear; echo 'sc monitor ^C-ed'; exit 1" 2
915 916
 		attempt=0
916 917
 		if [ "$2" == "" ]; then
917 918
 		    loops=-1;
... ...
@@ -920,7 +921,7 @@ case $1 in
920 921
 		fi
921 922
 		clear
922 923
 		while [ $loops -ne $attempt ] ; do
923
-			attempt=$(($attempt + 1))
924
+			attempt=`expr $attempt + 1`
924 925
 			#clear
925 926
 			tput cup 0 0
926 927
 			print_stats $name $path $attempt
... ...
@@ -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