svn commit: trunk/busybox: archival archival/libunarchive include l etc...

vda at busybox.net vda at busybox.net
Sat May 26 16:44:21 UTC 2007


Author: vda
Date: 2007-05-26 09:44:20 -0700 (Sat, 26 May 2007)
New Revision: 18695

Log:
xpipe: introduce (saves ~170 bytes)
udhcp/signalpipe.c: use pipe instead of socketpair.



Modified:
   trunk/busybox/archival/libunarchive/open_transformer.c
   trunk/busybox/archival/tar.c
   trunk/busybox/include/libbb.h
   trunk/busybox/libbb/xfuncs.c
   trunk/busybox/networking/udhcp/signalpipe.c
   trunk/busybox/runit/runsv.c
   trunk/busybox/runit/runsvdir.c
   trunk/busybox/shell/hush.c
   trunk/busybox/shell/lash.c


Changeset:
Modified: trunk/busybox/archival/libunarchive/open_transformer.c
===================================================================
--- trunk/busybox/archival/libunarchive/open_transformer.c	2007-05-26 11:59:01 UTC (rev 18694)
+++ trunk/busybox/archival/libunarchive/open_transformer.c	2007-05-26 16:44:20 UTC (rev 18695)
@@ -17,9 +17,7 @@
 	int fd_pipe[2];
 	int pid;
 
-	if (pipe(fd_pipe) != 0) {
-		bb_perror_msg_and_die("can't create pipe");
-	}
+	xpipe(fd_pipe);
 
 	pid = fork();
 	if (pid == -1) {

Modified: trunk/busybox/archival/tar.c
===================================================================
--- trunk/busybox/archival/tar.c	2007-05-26 11:59:01 UTC (rev 18694)
+++ trunk/busybox/archival/tar.c	2007-05-26 16:44:20 UTC (rev 18695)
@@ -507,8 +507,8 @@
 		volatile int vfork_exec_errno = 0;
 		const char *zip_exec = (gzip == 1) ? "gzip" : "bzip2";
 
-		if (pipe(gzipDataPipe) < 0 || pipe(gzipStatusPipe) < 0)
-			bb_perror_msg_and_die("pipe");
+		xpipe(gzipDataPipe);
+		xpipe(gzipStatusPipe);
 
 		signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */
 

Modified: trunk/busybox/include/libbb.h
===================================================================
--- trunk/busybox/include/libbb.h	2007-05-26 11:59:01 UTC (rev 18694)
+++ trunk/busybox/include/libbb.h	2007-05-26 16:44:20 UTC (rev 18695)
@@ -261,10 +261,10 @@
 int xopen3(const char *pathname, int flags, int mode);
 int open_or_warn(const char *pathname, int flags);
 int open3_or_warn(const char *pathname, int flags, int mode);
+void xpipe(int filedes[2]);
 off_t xlseek(int fd, off_t offset, int whence);
 off_t fdlength(int fd);
 
-
 int xsocket(int domain, int type, int protocol);
 void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen);
 void xlisten(int s, int backlog);

Modified: trunk/busybox/libbb/xfuncs.c
===================================================================
--- trunk/busybox/libbb/xfuncs.c	2007-05-26 11:59:01 UTC (rev 18694)
+++ trunk/busybox/libbb/xfuncs.c	2007-05-26 16:44:20 UTC (rev 18695)
@@ -106,7 +106,7 @@
 {
 	FILE *fp = fopen(path, mode);
 	if (fp == NULL)
-		bb_perror_msg_and_die("cannot open '%s'", path);
+		bb_perror_msg_and_die("can't open '%s'", path);
 	return fp;
 }
 
@@ -117,7 +117,7 @@
 
 	ret = open(pathname, flags, mode);
 	if (ret < 0) {
-		bb_perror_msg_and_die("cannot open '%s'", pathname);
+		bb_perror_msg_and_die("can't open '%s'", pathname);
 	}
 	return ret;
 }
@@ -135,7 +135,7 @@
 
 	ret = open(pathname, flags, mode);
 	if (ret < 0) {
-		bb_perror_msg("cannot open '%s'", pathname);
+		bb_perror_msg("can't open '%s'", pathname);
 	}
 	return ret;
 }
@@ -146,21 +146,27 @@
 	return open3_or_warn(pathname, flags, 0666);
 }
 
+void xpipe(int filedes[2])
+{
+	if (pipe(filedes))
+		bb_perror_msg_and_die("can't create pipe");
+}
+
 void xunlink(const char *pathname)
 {
 	if (unlink(pathname))
-		bb_perror_msg_and_die("cannot remove file '%s'", pathname);
+		bb_perror_msg_and_die("can't remove file '%s'", pathname);
 }
 
 // Turn on nonblocking I/O on a fd
 int ndelay_on(int fd)
 {
-	return fcntl(fd,F_SETFL,fcntl(fd,F_GETFL,0) | O_NONBLOCK);
+	return fcntl(fd, F_SETFL, fcntl(fd,F_GETFL,0) | O_NONBLOCK);
 }
 
 int ndelay_off(int fd)
 {
-	return fcntl(fd,F_SETFL,fcntl(fd,F_GETFL,0) & ~O_NONBLOCK);
+	return fcntl(fd, F_SETFL, fcntl(fd,F_GETFL,0) & ~O_NONBLOCK);
 }
 
 // "Renumber" opened fd
@@ -169,7 +175,7 @@
 	if (from == to)
 		return;
 	if (dup2(from, to) != to)
-		bb_perror_msg_and_die("cannot duplicate file descriptor");
+		bb_perror_msg_and_die("can't duplicate file descriptor");
 	close(from);
 }
 
@@ -199,7 +205,7 @@
 void die_if_ferror(FILE *fp, const char *fn)
 {
 	if (ferror(fp)) {
-		/* doesn't set useful errno */
+		/* ferror doesn't set useful errno */
 		bb_error_msg_and_die("%s: I/O error", fn);
 	}
 }
@@ -520,7 +526,7 @@
 
 	dp = opendir(path);
 	if (!dp)
-		bb_perror_msg("cannot open '%s'", path);
+		bb_perror_msg("can't open '%s'", path);
 	return dp;
 }
 
@@ -531,7 +537,7 @@
 
 	dp = opendir(path);
 	if (!dp)
-		bb_perror_msg_and_die("cannot open '%s'", path);
+		bb_perror_msg_and_die("can't open '%s'", path);
 	return dp;
 }
 
@@ -568,10 +574,8 @@
 	if (listen(s, backlog)) bb_perror_msg_and_die("listen");
 }
 
-/* Die with an error message if we the sendto failed.
- * Return bytes sent otherwise
- */
-
+/* Die with an error message if sendto failed.
+ * Return bytes sent otherwise  */
 ssize_t xsendto(int s, const  void *buf, size_t len, const struct sockaddr *to,
 				socklen_t tolen)
 {

Modified: trunk/busybox/networking/udhcp/signalpipe.c
===================================================================
--- trunk/busybox/networking/udhcp/signalpipe.c	2007-05-26 11:59:01 UTC (rev 18694)
+++ trunk/busybox/networking/udhcp/signalpipe.c	2007-05-26 16:44:20 UTC (rev 18695)
@@ -27,7 +27,8 @@
 
 static void signal_handler(int sig)
 {
-	if (send(signal_pipe[1], &sig, sizeof(sig), MSG_DONTWAIT) < 0)
+	unsigned char ch = sig; /* use char, avoid dealing with partial writes */
+	if (write(signal_pipe[1], &ch, 1) != 1)
 		bb_perror_msg("cannot send signal");
 }
 
@@ -36,11 +37,11 @@
  * and installs the signal handler */
 void udhcp_sp_setup(void)
 {
-// BTW, why socketpair and not just pipe?
-	if (socketpair(AF_UNIX, SOCK_STREAM, 0, signal_pipe))
-		bb_perror_msg_and_die("socketpair");
+	/* was socketpair, but it needs AF_UNIX in kernel */
+	xpipe(signal_pipe);
 	fcntl(signal_pipe[0], F_SETFD, FD_CLOEXEC);
 	fcntl(signal_pipe[1], F_SETFD, FD_CLOEXEC);
+	fcntl(signal_pipe[1], F_SETFL, O_NONBLOCK);
 	signal(SIGUSR1, signal_handler);
 	signal(SIGUSR2, signal_handler);
 	signal(SIGTERM, signal_handler);
@@ -67,12 +68,12 @@
  * your signal on success */
 int udhcp_sp_read(fd_set *rfds)
 {
-	int sig;
+	unsigned char sig;
 
 	if (!FD_ISSET(signal_pipe[0], rfds))
 		return 0;
 
-	if (read(signal_pipe[0], &sig, sizeof(sig)) < 0)
+	if (read(signal_pipe[0], &sig, 1) != 1)
 		return -1;
 
 	return sig;

Modified: trunk/busybox/runit/runsv.c
===================================================================
--- trunk/busybox/runit/runsv.c	2007-05-26 11:59:01 UTC (rev 18694)
+++ trunk/busybox/runit/runsv.c	2007-05-26 16:44:20 UTC (rev 18695)
@@ -420,7 +420,7 @@
 	if (!argv[1] || argv[2]) usage();
 	dir = argv[1];
 
-	if (pipe(selfpipe) == -1) fatal_cannot("create selfpipe");
+	xpipe(selfpipe);
 	coe(selfpipe[0]);
 	coe(selfpipe[1]);
 	ndelay_on(selfpipe[0]);
@@ -456,8 +456,7 @@
 			taia_now(&svd[1].start);
 			if (stat("log/down", &s) != -1)
 				svd[1].want = W_DOWN;
-			if (pipe(logpipe) == -1)
-				fatal_cannot("create log pipe");
+			xpipe(logpipe);
 			coe(logpipe[0]);
 			coe(logpipe[1]);
 		}

Modified: trunk/busybox/runit/runsvdir.c
===================================================================
--- trunk/busybox/runit/runsvdir.c	2007-05-26 11:59:01 UTC (rev 18694)
+++ trunk/busybox/runit/runsvdir.c	2007-05-26 16:44:20 UTC (rev 18695)
@@ -184,7 +184,7 @@
 		warnx("log must have at least seven characters");
 		return 0;
 	}
-	if (pipe(logpipe) == -1) {
+	if (pipe(logpipe)) {
 		warnx("cannot create pipe for log");
 		return -1;
 	}

Modified: trunk/busybox/shell/hush.c
===================================================================
--- trunk/busybox/shell/hush.c	2007-05-26 11:59:01 UTC (rev 18694)
+++ trunk/busybox/shell/hush.c	2007-05-26 16:44:20 UTC (rev 18695)
@@ -1800,8 +1800,7 @@
 
 		/* pipes are inserted between pairs of commands */
 		if ((i + 1) < pi->num_progs) {
-			if (pipe(pipefds) < 0)
-				bb_perror_msg_and_die("pipe");
+			pipe(pipefds);
 			nextout = pipefds[1];
 		} else {
 			nextout = 1;
@@ -3134,8 +3133,7 @@
 	FILE *pf;
 	int pid, channel[2];
 
-	if (pipe(channel) < 0)
-		bb_perror_msg_and_die("pipe");
+	xpipe(channel);
 #if BB_MMU
 	pid = fork();
 #else

Modified: trunk/busybox/shell/lash.c
===================================================================
--- trunk/busybox/shell/lash.c	2007-05-26 11:59:01 UTC (rev 18694)
+++ trunk/busybox/shell/lash.c	2007-05-26 16:44:20 UTC (rev 18695)
@@ -1222,8 +1222,7 @@
 
 		nextout = 1;
 		if ((i + 1) < newjob->num_progs) {
-			if (pipe(pipefds) < 0)
-				bb_perror_msg_and_die("pipe");
+			xpipe(pipefds);
 			nextout = pipefds[1];
 		} else if (outpipe[1] != -1) {
 			nextout = outpipe[1];




More information about the busybox-cvs mailing list