svn commit: trunk/busybox/coreutils

vda at busybox.net vda at busybox.net
Tue Oct 2 10:17:57 UTC 2007


Author: vda
Date: 2007-10-02 03:17:56 -0700 (Tue, 02 Oct 2007)
New Revision: 20170

Log:
tail: work correctly on /proc files (Kazuo TAKADA <kztakada at sm.sony.co.jp>)



Modified:
   trunk/busybox/coreutils/tail.c


Changeset:
Modified: trunk/busybox/coreutils/tail.c
===================================================================
--- trunk/busybox/coreutils/tail.c	2007-10-02 09:57:41 UTC (rev 20169)
+++ trunk/busybox/coreutils/tail.c	2007-10-02 10:17:56 UTC (rev 20170)
@@ -47,13 +47,16 @@
 static ssize_t tail_read(int fd, char *buf, size_t count)
 {
 	ssize_t r;
-	off_t current, end;
+	off_t current;
 	struct stat sbuf;
 
-	end = current = lseek(fd, 0, SEEK_CUR);
-	if (!fstat(fd, &sbuf))
-		end = sbuf.st_size;
-	lseek(fd, end < current ? 0 : current, SEEK_SET);
+	/* (A good comment is missing here) */
+	current = lseek(fd, 0, SEEK_CUR);
+	/* /proc files report zero st_size, don't lseek them. */
+	if (fstat(fd, &sbuf) == 0 && sbuf.st_size)
+		if (sbuf.st_size < current)
+			lseek(fd, 0, SEEK_SET);
+
 	r = safe_read(fd, buf, count);
 	if (r < 0) {
 		bb_perror_msg(bb_msg_read_error);
@@ -67,8 +70,12 @@
 
 static unsigned eat_num(const char *p)
 {
-	if (*p == '-') p++;
-	else if (*p == '+') { p++; G.status = EXIT_FAILURE; }
+	if (*p == '-')
+		p++;
+	else if (*p == '+') {
+		p++;
+		G.status = EXIT_FAILURE;
+	}
 	return xatou_sfx(p, tail_suffixes);
 }
 




More information about the busybox-cvs mailing list