Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 28 Oct 2014 10:33:32 +0000 (UTC)
From:      Baptiste Daroussin <bapt@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r273769 - head/usr.bin/timeout
Message-ID:  <201410281033.s9SAXWdZ070878@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: bapt
Date: Tue Oct 28 10:33:31 2014
New Revision: 273769
URL: https://svnweb.freebsd.org/changeset/base/273769

Log:
  Improve compatibility with GNU timeout
  
  According to the coreutils regression testsuite for timeout(1)
  It is expect to exit with a status being:
  125 in case an invalid duration or signal is passed in arguments
  126 in case an invalid command is passed in arguments
  127 in case the command passed in arguments does not exists.
  
  While here document this behaviour in the man page

Modified:
  head/usr.bin/timeout/timeout.1
  head/usr.bin/timeout/timeout.c

Modified: head/usr.bin/timeout/timeout.1
==============================================================================
--- head/usr.bin/timeout/timeout.1	Tue Oct 28 10:25:59 2014	(r273768)
+++ head/usr.bin/timeout/timeout.1	Tue Oct 28 10:33:31 2014	(r273769)
@@ -24,7 +24,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd July 19, 2014
+.Dd Oct 28, 2014
 .Dt TIMEOUT 1
 .Os
 .Sh NAME
@@ -108,7 +108,22 @@ is not set, an exit status of 124 is ret
 .Pp
 If
 .Ar command
-exits after receiving a signal, the exit status returned is the signal number plus 128.
+exits after receiving a signal, the exit status returned is the signal number
+plus 128.
+.Pp
+If
+.Ar command
+is an invalid command, the exit status returned is 126.
+.Pp
+If
+.Ar command
+is a non existing command, the exit status returned is 127.
+.Pp
+If an invalid parameter is passed to
+.Fl s
+or
+.Fl k ,
+the exit status return is 125.
 .Sh SEE ALSO
 .Xr kill 1 ,
 .Xr signal 3

Modified: head/usr.bin/timeout/timeout.c
==============================================================================
--- head/usr.bin/timeout/timeout.c	Tue Oct 28 10:25:59 2014	(r273768)
+++ head/usr.bin/timeout/timeout.c	Tue Oct 28 10:33:31 2014	(r273769)
@@ -68,7 +68,7 @@ parse_duration(const char *duration)
 
 	ret = strtod(duration, &end);
 	if (ret == 0 && end == duration)
-		errx(EXIT_FAILURE, "invalid duration");
+		errx(125, "invalid duration");
 
 	if (end == NULL || *end == '\0')
 		return (ret);
@@ -89,11 +89,11 @@ parse_duration(const char *duration)
 		ret *= 60 * 60 * 24;
 		break;
 	default:
-		errx(EX_USAGE, "invalid duration");
+		errx(125, "invalid duration");
 	}
 
 	if (ret < 0 || ret >= 100000000UL)
-		errx(EX_USAGE, "invalid duration");
+		errx(125, "invalid duration");
 
 	return (ret);
 }
@@ -116,7 +116,7 @@ parse_signal(const char *str)
 			return (i);
 	}
 
-	errx(EX_USAGE, "invalid signal");
+	errx(125, "invalid signal");
 }
 
 static void
@@ -260,8 +260,12 @@ main(int argc, char **argv)
 		signal(SIGTTOU, SIG_DFL);
 
 		error = execvp(argv[0], argv);
-		if (error == -1)
-			err(EX_UNAVAILABLE, "exec()");
+		if (error == -1) {
+			if (errno == ENOENT)
+				err(127, "exec(%s)", argv[0]);
+			else
+				err(126, "exec(%s)", argv[0]);
+		}
 	}
 
 	if (sigprocmask(SIG_BLOCK, &signals.sa_mask, NULL) == -1)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201410281033.s9SAXWdZ070878>