svn commit: trunk/busybox: editors networking sysklogd

vda at busybox.net vda at busybox.net
Thu Oct 11 10:10:15 UTC 2007


Author: vda
Date: 2007-10-11 03:10:15 -0700 (Thu, 11 Oct 2007)
New Revision: 20222

Log:
vi: don't wait 50 ms before reading ESC sequences
inetd,syslogd: use safe_read instead of open-coded EINTR handling
syslogd: bail out if you see null read from Unix socket
(should never happen, but if it does, spinning forever
and eating 100% CPU is not a good idea)



Modified:
   trunk/busybox/editors/vi.c
   trunk/busybox/networking/inetd.c
   trunk/busybox/sysklogd/syslogd.c


Changeset:
Modified: trunk/busybox/editors/vi.c
===================================================================
--- trunk/busybox/editors/vi.c	2007-10-11 10:07:24 UTC (rev 20221)
+++ trunk/busybox/editors/vi.c	2007-10-11 10:10:15 UTC (rev 20222)
@@ -2152,7 +2152,7 @@
 	char c;
 	int n;
 	struct esc_cmds {
-		const char *seq;
+		const char seq[4];
 		char val;
 	};
 
@@ -2178,6 +2178,7 @@
 		{"OQ", VI_K_FUN2},     // Function Key F2
 		{"OR", VI_K_FUN3},     // Function Key F3
 		{"OS", VI_K_FUN4},     // Function Key F4
+		// careful: these have no terminating NUL!
 		{"[15~", VI_K_FUN5},   // Function Key F5
 		{"[17~", VI_K_FUN6},   // Function Key F6
 		{"[18~", VI_K_FUN7},   // Function Key F7
@@ -2198,12 +2199,9 @@
 	n = readed_for_parse;
 	// get input from User- are there already input chars in Q?
 	if (n <= 0) {
- ri0:
 		// the Q is empty, wait for a typed char
-		n = read(0, readbuffer, MAX_LINELEN - 1);
+		n = safe_read(0, readbuffer, MAX_LINELEN - 1);
 		if (n < 0) {
-			if (errno == EINTR)
-				goto ri0;	// interrupted sys call
 			if (errno == EBADF || errno == EFAULT || errno == EINVAL
 					|| errno == EIO)
 				editing = 0;
@@ -2219,11 +2217,10 @@
 			struct pollfd pfd[1];
 			pfd[0].fd = 0;
 			pfd[0].events = POLLIN;
-			// Wait 50 ms
 			// keep reading while there are input chars and room in buffer
-			while (safe_poll(pfd, 1, 50) > 0 && n <= (MAX_LINELEN - 5)) {
+			while (safe_poll(pfd, 1, 0) > 0 && n <= (MAX_LINELEN - 5)) {
 				// read the rest of the ESC string
-				int r = read(0, readbuffer + n, MAX_LINELEN - n);
+				int r = safe_read(0, readbuffer + n, MAX_LINELEN - n);
 				if (r > 0)
 					n += r;
 			}
@@ -2236,7 +2233,7 @@
 		const struct esc_cmds *eindex;
 
 		for (eindex = esccmds; eindex < &esccmds[ESCCMDS_COUNT]; eindex++) {
-			int cnt = strlen(eindex->seq);
+			int cnt = strnlen(eindex->seq, 4);
 
 			if (n <= cnt)
 				continue;
@@ -2397,7 +2394,7 @@
 	p = text_hole_make(p, size);
 	if (p == NULL)
 		goto fi0;
-	cnt = read(fd, p, size);
+	cnt = safe_read(fd, p, size);
 	if (cnt < 0) {
 		psbs("\"%s\" %s", fn, strerror(errno));
 		p = text_hole_delete(p, p + size - 1);	// un-do buffer insert
@@ -3961,7 +3958,7 @@
 		printf("\n\n%d: \'%c\' %s\n\n\n%s[Hit return to continue]%s",
 			totalcmds, last_input_char, msg, SOs, SOn);
 		fflush(stdout);
-		while (read(0, d, 1) > 0) {
+		while (safe_read(0, d, 1) > 0) {
 			if (d[0] == '\n' || d[0] == '\r')
 				break;
 		}

Modified: trunk/busybox/networking/inetd.c
===================================================================
--- trunk/busybox/networking/inetd.c	2007-10-11 10:07:24 UTC (rev 20221)
+++ trunk/busybox/networking/inetd.c	2007-10-11 10:10:15 UTC (rev 20222)
@@ -1638,8 +1638,7 @@
 
 	inetd_setproctitle(sep->se_service, s);
 	while (1) {
-		errno = 0;
-		if (read(s, buffer, sizeof(buffer)) <= 0 && errno != EINTR)
+		if (safe_read(s, buffer, sizeof(buffer)) <= 0)
 			exit(0);
 	}
 }

Modified: trunk/busybox/sysklogd/syslogd.c
===================================================================
--- trunk/busybox/sysklogd/syslogd.c	2007-10-11 10:07:24 UTC (rev 20221)
+++ trunk/busybox/sysklogd/syslogd.c	2007-10-11 10:10:15 UTC (rev 20222)
@@ -527,12 +527,10 @@
 	for (;;) {
 		size_t sz;
 
-		sz = read(sock_fd, G.recvbuf, MAX_READ - 1);
+		sz = safe_read(sock_fd, G.recvbuf, MAX_READ - 1);
 		if (sz <= 0) {
-			if (sz == 0)
-				continue; /* EOF from unix socket??? */
-			if (errno == EINTR) /* alarm may have happened */
-				continue;
+			//if (sz == 0)
+			//	continue; /* EOF from unix socket??? */
 			bb_perror_msg_and_die("read from /dev/log");
 		}
 




More information about the busybox-cvs mailing list