From owner-svn-src-all@FreeBSD.ORG Tue Oct 28 10:33:32 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id A9713F80; Tue, 28 Oct 2014 10:33:32 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 860AB69D; Tue, 28 Oct 2014 10:33:32 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s9SAXWsN070880; Tue, 28 Oct 2014 10:33:32 GMT (envelope-from bapt@FreeBSD.org) Received: (from bapt@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s9SAXWdZ070878; Tue, 28 Oct 2014 10:33:32 GMT (envelope-from bapt@FreeBSD.org) Message-Id: <201410281033.s9SAXWdZ070878@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: bapt set sender to bapt@FreeBSD.org using -f From: Baptiste Daroussin Date: Tue, 28 Oct 2014 10:33:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r273769 - head/usr.bin/timeout X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Oct 2014 10:33:32 -0000 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)