bug#1052: [BusyBox] bug#1052: "tail -10" fails; "tail -9" and "tail -n 9" work

Matt Kraai kraai at alumni.carnegiemellon.edu
Mon Oct 9 20:17:49 UTC 2000


On Mon, Oct 09, 2000 at 02:03:57PM -0500, David Douthitt wrote:
> Package: busybox
> Version: 0.47
> 
> Here is a transcript...
> 
> # tail -9 messages
> 
> Oct  9 12:07:03 red kern.debug VFS: Disk change detected on device 
> fd(2,44)
> 
> Oct  9 12:21:52 red syslog.info -- MARK --
> Oct  9 12:41:52 red syslog.info -- MARK --
> Oct  9 13:01:52 red syslog.info -- MARK --
> Oct  9 13:21:52 red syslog.info -- MARK --
> Oct  9 13:41:52 red syslog.info -- MARK --
> Oct  9 14:01:52 red syslog.info -- MARK --
> # tail -10 messages
> tail: Unrecognised number 'tail'
> # tail -n 10 messages
> Oct  9 12:05:39 red kern.debug VFS: Disk change detected on device 
> fd(2,44)
> 
> Oct  9 12:07:03 red kern.debug VFS: Disk change detected on device 
> fd(2,44)
> 
> Oct  9 12:21:52 red syslog.info -- MARK --
> Oct  9 12:41:52 red syslog.info -- MARK --
> Oct  9 13:01:52 red syslog.info -- MARK --
> Oct  9 13:21:52 red syslog.info -- MARK --
> Oct  9 13:41:52 red syslog.info -- MARK --
> Oct  9 14:01:52 red syslog.info -- MARK --
> #

I believe that tail is able to handle any option of the form -[0-9] but
nothing of the form -[0-9][0-9]+.  The problem is that the entire option
is refered to as argv[optind-1].  This works for single digit options,
as optind is incremented so that this works.  However, for multi-digit
options optind is not incremented so this refers to the previous option
parameter, in your case the name of the executable.  I have attached a
patch which should fix it (though it reparses the number once for each
digit).

Matt
-------------- next part --------------
--- tail.c.orig	Mon Oct  9 13:08:07 2000
+++ tail.c	Mon Oct  9 13:13:36 2000
@@ -171,7 +171,7 @@
 {
 	int show_headers = 1;
 	int test;
-	int opt;
+	int opt, oldoptind = optind;
 	char follow=0;
 	int sleep_int=1;
 	int *fd;
@@ -183,7 +183,7 @@
 		switch (opt) {
 			case '1':case '2':case '3':case '4':case '5':
 			case '6':case '7':case '8':case '9':case '0':
-				checknumbers(argv[optind-1]);
+				checknumbers(argv[oldoptind]);
 				break;
 
 #ifndef BB_FEATURE_SIMPLE_TAIL
@@ -245,6 +245,7 @@
 			errorMsg("\nUnknown arg: %c.\n\n",optopt);
 			usage(tail_usage);
 		}
+		oldoptind = optind;
 	}
 	while (optind <= argc) {
 		if(optind==argc) {


More information about the busybox mailing list