svn commit: trunk/busybox: coreutils e2fsprogs include libbb loginu etc...

vda at busybox.net vda at busybox.net
Wed Mar 12 23:19:35 UTC 2008


Author: vda
Date: 2008-03-12 16:19:35 -0700 (Wed, 12 Mar 2008)
New Revision: 21323

Log:
libbb: introduse and use signal_[no_]SA_RESTART_empty_mask and sigaction_set

signal_SA_RESTART_empty_mask                           -      65     +65
signal_no_SA_RESTART_empty_mask                        -      54     +54
dd_main                                             1325    1369     +44
sigaction_set                                          -      19     +19
dname_enc                                            373     377      +4
UNSPEC_print                                          64      66      +2
setsignal                                            296     294      -2
bb_signals_recursive                                  95      92      -3
bb_askpass                                           367     361      -6
inetd_main                                          1810    1797     -13
rx_main                                              912     883     -29
sigdelset                                             32       -     -32
__sigdelset                                           32       -     -32
__GI_sigdelset                                        32       -     -32
sighup_handler                                        84      37     -47
arping_main                                         1844    1797     -47
fsck_main                                           1869    1807     -62
run_list                                            1917    1844     -73
vlock_main                                           492     409     -83
progressmeter                                        883     798     -85
handle_incoming_and_exit                            2737    2651     -86
------------------------------------------------------------------------------
(add/remove: 3/3 grow/shrink: 3/12 up/down: 188/-632)        Total: -444 bytes



Modified:
   trunk/busybox/coreutils/dd.c
   trunk/busybox/e2fsprogs/fsck.c
   trunk/busybox/include/libbb.h
   trunk/busybox/libbb/bb_askpass.c
   trunk/busybox/libbb/signals.c
   trunk/busybox/loginutils/vlock.c
   trunk/busybox/miscutils/devfsd.c
   trunk/busybox/miscutils/rx.c
   trunk/busybox/networking/arping.c
   trunk/busybox/networking/httpd.c
   trunk/busybox/networking/inetd.c
   trunk/busybox/networking/wget.c
   trunk/busybox/shell/ash.c
   trunk/busybox/shell/hush.c


Changeset:
Modified: trunk/busybox/coreutils/dd.c
===================================================================
--- trunk/busybox/coreutils/dd.c	2008-03-12 23:13:50 UTC (rev 21322)
+++ trunk/busybox/coreutils/dd.c	2008-03-12 23:19:35 UTC (rev 21323)
@@ -121,9 +121,6 @@
 		off_t count;
 		off_t seek, skip;
 		const char *infile, *outfile;
-#if ENABLE_FEATURE_DD_SIGNAL_HANDLING
-		struct sigaction sigact;
-#endif
 	} Z;
 #define flags   (Z.flags  )
 #define oc      (Z.oc     )
@@ -132,17 +129,13 @@
 #define skip    (Z.skip   )
 #define infile  (Z.infile )
 #define outfile (Z.outfile)
-#define sigact  (Z.sigact )
 
 	memset(&Z, 0, sizeof(Z));
 	INIT_G();
 	//fflush(NULL); - is this needed because of NOEXEC?
 
 #if ENABLE_FEATURE_DD_SIGNAL_HANDLING
-	sigact.sa_handler = dd_output_status;
-	sigact.sa_flags = SA_RESTART;
-	/*sigemptyset(&sigact.sa_mask); - memset did it */
-	sigaction(SIGUSR1, &sigact, NULL);
+	signal_SA_RESTART_empty_mask(SIGUSR1, dd_output_status);
 #endif
 
 	for (n = 1; n < argc; n++) {

Modified: trunk/busybox/e2fsprogs/fsck.c
===================================================================
--- trunk/busybox/e2fsprogs/fsck.c	2008-03-12 23:13:50 UTC (rev 21322)
+++ trunk/busybox/e2fsprogs/fsck.c	2008-03-12 23:19:35 UTC (rev 21323)
@@ -1164,12 +1164,9 @@
 	int interactive;
 	const char *fstab;
 	struct fs_info *fs;
-	struct sigaction sa;
 
-	memset(&sa, 0, sizeof(sa));
-	sa.sa_handler = signal_cancel;
-	sigaction(SIGINT, &sa, NULL);
-	sigaction(SIGTERM, &sa, NULL);
+	signal_no_SA_RESTART_empty_mask(SIGINT, signal_cancel);
+	signal_no_SA_RESTART_empty_mask(SIGTERM, signal_cancel);
 
 	setbuf(stdout, NULL);
 

Modified: trunk/busybox/include/libbb.h
===================================================================
--- trunk/busybox/include/libbb.h	2008-03-12 23:13:50 UTC (rev 21322)
+++ trunk/busybox/include/libbb.h	2008-03-12 23:19:35 UTC (rev 21323)
@@ -275,6 +275,7 @@
 
 char *xmalloc_follow_symlinks(const char *path);
 
+
 enum {
 	/* bb_signals(BB_SIGS_FATAL, handler) catches all signals which
 	 * otherwise would kill us, except for those resulting from bugs:
@@ -306,6 +307,12 @@
  * and in a way that while signal handler is run, no other signals
  * will be blocked: */
 void bb_signals_recursive(int sigs, void (*f)(int));
+/* syscalls like read() will be interrupted with EINTR: */
+void signal_no_SA_RESTART_empty_mask(int sig, void (*handler)(int));
+/* syscalls like read() won't be interrupted (though select/poll will be): */
+void signal_SA_RESTART_empty_mask(int sig, void (*handler)(int));
+/* Will do sigaction(signum, act, NULL): */
+int sigaction_set(int signum, const struct sigaction *act);
 void sig_block(int);
 void sig_unblock(int);
 /* UNUSED: void sig_blocknone(void); */

Modified: trunk/busybox/libbb/bb_askpass.c
===================================================================
--- trunk/busybox/libbb/bb_askpass.c	2008-03-12 23:13:50 UTC (rev 21322)
+++ trunk/busybox/libbb/bb_askpass.c	2008-03-12 23:19:35 UTC (rev 21323)
@@ -45,7 +45,7 @@
 	sa.sa_handler = askpass_timeout;
 	sigaction(SIGINT, &sa, &oldsa);
 	if (timeout) {
-		sigaction(SIGALRM, &sa, NULL);
+		sigaction_set(SIGALRM, &sa);
 		alarm(timeout);
 	}
 
@@ -68,7 +68,7 @@
 	if (timeout) {
 		alarm(0);
 	}
-	sigaction(SIGINT, &oldsa, NULL);
+	sigaction_set(SIGINT, &oldsa);
 
 	tcsetattr(STDIN_FILENO, TCSANOW, &oldtio);
 	bb_putchar('\n');

Modified: trunk/busybox/libbb/signals.c
===================================================================
--- trunk/busybox/libbb/signals.c	2008-03-12 23:13:50 UTC (rev 21322)
+++ trunk/busybox/libbb/signals.c	2008-03-12 23:19:35 UTC (rev 21323)
@@ -11,6 +11,12 @@
 
 #include "libbb.h"
 
+/* Saves 2 bytes on x86! Oh my... */
+int sigaction_set(int signum, const struct sigaction *act)
+{
+	return sigaction(signum, act, NULL);
+}
+
 void bb_signals(int sigs, void (*f)(int))
 {
 	int sig_no = 0;
@@ -40,7 +46,7 @@
 	while (sigs) {
 		if (sigs & bit) {
 			sigs &= ~bit;
-			sigaction(sig_no, &sa, NULL);
+			sigaction_set(sig_no, &sa);
 		}
 		sig_no++;
 		bit <<= 1;
@@ -87,3 +93,23 @@
 	raise(sig);
 	_exit(1); /* Should not reach it */
 }
+
+void signal_SA_RESTART_empty_mask(int sig, void (*handler)(int))
+{
+	struct sigaction sa;
+	memset(&sa, 0, sizeof(sa));
+	/*sigemptyset(&sa.sa_mask);*/
+	sa.sa_flags = SA_RESTART;
+	sa.sa_handler = handler;
+	sigaction_set(sig, &sa);
+}
+
+void signal_no_SA_RESTART_empty_mask(int sig, void (*handler)(int))
+{
+	struct sigaction sa;
+	memset(&sa, 0, sizeof(sa));
+	/*sigemptyset(&sa.sa_mask);*/
+	/*sa.sa_flags = 0;*/
+	sa.sa_handler = handler;
+	sigaction_set(sig, &sa);
+}

Modified: trunk/busybox/loginutils/vlock.c
===================================================================
--- trunk/busybox/loginutils/vlock.c	2008-03-12 23:13:50 UTC (rev 21322)
+++ trunk/busybox/loginutils/vlock.c	2008-03-12 23:19:35 UTC (rev 21323)
@@ -34,7 +34,6 @@
 int vlock_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int vlock_main(int argc, char **argv)
 {
-	struct sigaction sa;
 	struct vt_mode vtm;
 	struct termios term;
 	struct termios oterm;
@@ -63,17 +62,11 @@
 
 	/* We will use SIGUSRx for console switch control: */
 	/* 1: set handlers */
-	sigemptyset(&sa.sa_mask);
-	sa.sa_flags = SA_RESTART;
-	sa.sa_handler = release_vt;
-	sigaction(SIGUSR1, &sa, NULL);
-	sa.sa_handler = acquire_vt;
-	sigaction(SIGUSR2, &sa, NULL);
+	signal_SA_RESTART_empty_mask(SIGUSR1, release_vt);
+	signal_SA_RESTART_empty_mask(SIGUSR2, acquire_vt);
 	/* 2: unmask them */
-	sigprocmask(SIG_SETMASK, NULL, &sa.sa_mask);
-	sigdelset(&sa.sa_mask, SIGUSR1);
-	sigdelset(&sa.sa_mask, SIGUSR2);
-	sigprocmask(SIG_SETMASK, &sa.sa_mask, NULL);
+	sig_unblock(SIGUSR1);
+	sig_unblock(SIGUSR2);
 
 	/* Revert stdin/out to our controlling tty
 	 * (or die if we have none) */

Modified: trunk/busybox/miscutils/devfsd.c
===================================================================
--- trunk/busybox/miscutils/devfsd.c	2008-03-12 23:13:50 UTC (rev 21322)
+++ trunk/busybox/miscutils/devfsd.c	2008-03-12 23:19:35 UTC (rev 21323)
@@ -390,8 +390,8 @@
 	sigemptyset(&new_action.sa_mask);
 	new_action.sa_flags = 0;
 	new_action.sa_handler = signal_handler;
-	sigaction(SIGHUP, &new_action, NULL);
-	sigaction(SIGUSR1, &new_action, NULL);
+	sigaction_set(SIGHUP, &new_action);
+	sigaction_set(SIGUSR1, &new_action);
 
 	printf("%s v%s started for %s\n", applet_name, DEVFSD_VERSION, mount_point);
 

Modified: trunk/busybox/miscutils/rx.c
===================================================================
--- trunk/busybox/miscutils/rx.c	2008-03-12 23:13:50 UTC (rev 21322)
+++ trunk/busybox/miscutils/rx.c	2008-03-12 23:19:35 UTC (rev 21323)
@@ -220,7 +220,6 @@
 int rx_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int rx_main(int argc, char **argv)
 {
-	struct sigaction act;
 	struct termios tty, orig_tty;
 	int termios_err;
 	int file_fd;
@@ -243,9 +242,7 @@
 	}
 
 	/* No SA_RESTART: we want ALRM to interrupt read() */
-	memset(&act, 0, sizeof(act));
-	act.sa_handler = sigalrm_handler;
-	sigaction(SIGALRM, &act, NULL);
+	signal_no_SA_RESTART_empty_mask(SIGALRM, sigalrm_handler);
 
 	n = receive(file_fd);
 

Modified: trunk/busybox/networking/arping.c
===================================================================
--- trunk/busybox/networking/arping.c	2008-03-12 23:13:50 UTC (rev 21322)
+++ trunk/busybox/networking/arping.c	2008-03-12 23:19:35 UTC (rev 21323)
@@ -377,19 +377,9 @@
 		printf(" from %s via %s\n", inet_ntoa(src), device);
 	}
 
-	{
-		struct sigaction sa;
+	signal_SA_RESTART_empty_mask(SIGINT,  (void (*)(int))finish);
+	signal_SA_RESTART_empty_mask(SIGALRM, (void (*)(int))catcher);
 
-		memset(&sa, 0, sizeof(sa));
-		sa.sa_flags = SA_RESTART;
-
-		sa.sa_handler = (void (*)(int)) finish;
-		sigaction(SIGINT, &sa, NULL);
-
-		sa.sa_handler = (void (*)(int)) catcher;
-		sigaction(SIGALRM, &sa, NULL);
-	}
-
 	catcher();
 
 	packet = xmalloc(4096);

Modified: trunk/busybox/networking/httpd.c
===================================================================
--- trunk/busybox/networking/httpd.c	2008-03-12 23:13:50 UTC (rev 21322)
+++ trunk/busybox/networking/httpd.c	2008-03-12 23:19:35 UTC (rev 21323)
@@ -1788,7 +1788,6 @@
 	char *header_ptr = header_ptr;
 	Htaccess_Proxy *proxy_entry;
 #endif
-	struct sigaction sa;
 #if ENABLE_FEATURE_HTTPD_BASIC_AUTH
 	int credentials = -1;  /* if not required this is Ok */
 #endif
@@ -1819,11 +1818,7 @@
 	}
 
 	/* Install timeout handler */
-	memset(&sa, 0, sizeof(sa));
-	sa.sa_handler = exit_on_signal;
-	/* sigemptyset(&sa.sa_mask); - memset should be enough */
-	/*sa.sa_flags = 0; - no SA_RESTART */
-	sigaction(SIGALRM, &sa, NULL);
+	signal_no_SA_RESTART_empty_mask(SIGALRM, exit_on_signal);
 	alarm(HEADER_READ_TIMEOUT);
 
 	if (!get_line()) /* EOF or error or empty line */
@@ -2247,15 +2242,9 @@
 #if ENABLE_FEATURE_HTTPD_RELOAD_CONFIG_SIGHUP
 static void sighup_handler(int sig)
 {
-	struct sigaction sa;
-
 	parse_conf(default_path_httpd_conf, sig == SIGHUP ? SIGNALED_PARSE : FIRST_PARSE);
 
-	memset(&sa, 0, sizeof(sa));
-	sa.sa_handler = sighup_handler;
-	/*sigemptyset(&sa.sa_mask); - memset should be enough */
-	sa.sa_flags = SA_RESTART;
-	sigaction(SIGHUP, &sa, NULL);
+	signal_SA_RESTART_empty_mask(SIGHUP, sighup_handler);
 }
 #endif
 

Modified: trunk/busybox/networking/inetd.c
===================================================================
--- trunk/busybox/networking/inetd.c	2008-03-12 23:13:50 UTC (rev 21322)
+++ trunk/busybox/networking/inetd.c	2008-03-12 23:19:35 UTC (rev 21323)
@@ -1179,15 +1179,15 @@
 	sigaddset(&sa.sa_mask, SIGCHLD);
 	sigaddset(&sa.sa_mask, SIGHUP);
 	sa.sa_handler = retry_network_setup;
-	sigaction(SIGALRM, &sa, NULL);
+	sigaction_set(SIGALRM, &sa);
 	sa.sa_handler = reread_config_file;
-	sigaction(SIGHUP, &sa, NULL);
+	sigaction_set(SIGHUP, &sa);
 	sa.sa_handler = reap_child;
-	sigaction(SIGCHLD, &sa, NULL);
+	sigaction_set(SIGCHLD, &sa);
 	sa.sa_handler = clean_up_and_exit;
-	sigaction(SIGTERM, &sa, NULL);
+	sigaction_set(SIGTERM, &sa);
 	sa.sa_handler = clean_up_and_exit;
-	sigaction(SIGINT, &sa, NULL);
+	sigaction_set(SIGINT, &sa);
 	sa.sa_handler = SIG_IGN;
 	sigaction(SIGPIPE, &sa, &saved_pipe_handler);
 
@@ -1382,7 +1382,7 @@
 			 * for nowait stream children */
 			for (sep2 = serv_list; sep2; sep2 = sep2->se_next)
 				maybe_close(sep2->se_fd);
-			sigaction(SIGPIPE, &saved_pipe_handler, NULL);
+			sigaction_set(SIGPIPE, &saved_pipe_handler);
 			unblock_sigs(&omask);
 			BB_EXECVP(sep->se_program, sep->se_argv);
 			bb_perror_msg("exec %s", sep->se_program);

Modified: trunk/busybox/networking/wget.c
===================================================================
--- trunk/busybox/networking/wget.c	2008-03-12 23:13:50 UTC (rev 21322)
+++ trunk/busybox/networking/wget.c	2008-03-12 23:19:35 UTC (rev 21323)
@@ -144,13 +144,8 @@
 		transferred = 0;
 		fputc('\n', stderr);
 	} else {
-		if (flag == -1) {
-			/* first call to progressmeter */
-			struct sigaction sa;
-			sa.sa_handler = progressmeter;
-			sigemptyset(&sa.sa_mask);
-			sa.sa_flags = SA_RESTART;
-			sigaction(SIGALRM, &sa, NULL);
+		if (flag == -1) { /* first call to progressmeter */
+			signal_SA_RESTART_empty_mask(SIGALRM, progressmeter);
 		}
 		alarm(1);
 	}

Modified: trunk/busybox/shell/ash.c
===================================================================
--- trunk/busybox/shell/ash.c	2008-03-12 23:13:50 UTC (rev 21322)
+++ trunk/busybox/shell/ash.c	2008-03-12 23:19:35 UTC (rev 21323)
@@ -3340,7 +3340,7 @@
 	*t = action;
 	act.sa_flags = 0;
 	sigfillset(&act.sa_mask);
-	sigaction(signo, &act, NULL);
+	sigaction_set(signo, &act);
 }
 
 /* mode flags for set_curjob */

Modified: trunk/busybox/shell/hush.c
===================================================================
--- trunk/busybox/shell/hush.c	2008-03-12 23:13:50 UTC (rev 21322)
+++ trunk/busybox/shell/hush.c	2008-03-12 23:19:35 UTC (rev 21323)
@@ -699,16 +699,6 @@
 
 #if ENABLE_HUSH_JOB
 
-/* move to libbb? */
-static void signal_SA_RESTART(int sig, void (*handler)(int))
-{
-	struct sigaction sa;
-	sa.sa_handler = handler;
-	sa.sa_flags = SA_RESTART;
-	sigemptyset(&sa.sa_mask);
-	sigaction(sig, &sa, NULL);
-}
-
 /* Signals are grouped, we handle them in batches */
 static void set_fatal_sighandler(void (*handler)(int))
 {
@@ -2115,7 +2105,7 @@
 #if ENABLE_FEATURE_SH_STANDALONE
 		nofork_save.saved = 0; /* in case we will run a nofork later */
 #endif
-		signal_SA_RESTART(SIGTSTP, handler_ctrl_z);
+		signal_SA_RESTART_empty_mask(SIGTSTP, handler_ctrl_z);
 		signal(SIGINT, handler_ctrl_c);
 	}
 #endif /* JOB */




More information about the busybox-cvs mailing list