[BusyBox] tail patch

Matthias Lang matthias at corelatus.se
Thu Aug 8 03:15:04 UTC 2002


Hi,

When given a file which doesn't exist, busybox tail with the -f switch
waits forever for input to arrive. GNU tail exits immediately.

Busybox 0.60.3 tail:

  # busybox tail -f bogus_file
  tail: bogus_file: No such file or directory
  (busybox waits forever)

GNU textutils 2.0 tail:

  >tail -f bogus_file
  tail: bogus_file: No such file or directory
  tail: no files remaining
  > 

The appended patch against 0.60.3 provides a quick fix.

Another difference between GNU and busybox tail is in how STDIN is
handled in conjunction with -f. GNU tail exits when ^D is sent from
the console, busybox tail ignores the ^D. Either seems sensible.

Matt

--- ../busybox-0.60.3/tail.c	2001-10-27 01:08:05.000000000 +0200
+++ tail.c	2002-08-08 11:04:23.000000000 +0200
@@ -65,6 +65,7 @@
 	int from_top = 0, units = LINES, count = 10, sleep_period = 1;
 	int show_headers = 0, hide_headers = 0, follow = 0;
 	int *fds, nfiles = 0, status = EXIT_SUCCESS, nread, nwrite, seen = 0;
+	int nduds = 0;
 	char *s, *start, *end, buf[BUFSIZ];
 	int i, opt;
 
@@ -114,6 +115,7 @@
 			} else if ((fds[nfiles++] = open(argv[i], O_RDONLY)) < 0) {
 				perror_msg("%s", argv[i]);
 				status = EXIT_FAILURE;
+				nduds++;
 			}
 		}
 	}
@@ -224,7 +226,7 @@
 		taillen = 0;
 	}
 
-	while (follow) {
+	while (follow && nfiles > nduds) {
 		sleep(sleep_period);
 
 		for (i = 0; i < nfiles; i++) {
@@ -243,6 +245,7 @@
 			if (nread < 0) {
 				perror_msg("read");
 				status = EXIT_FAILURE;
+				nduds++;
 			}
 		}
 	}



More information about the busybox mailing list