Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin PR/49053: Kamil Rytarowski: Import timeout(1) from F...



details:   https://anonhg.NetBSD.org/src/rev/5c7f94027096
branches:  trunk
changeset: 331116:5c7f94027096
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Aug 01 14:01:30 2014 +0000

description:
PR/49053: Kamil Rytarowski: Import timeout(1) from FreeBSD

diffstat:

 usr.bin/Makefile          |   5 ++-
 usr.bin/timeout/Makefile  |   3 +-
 usr.bin/timeout/timeout.1 |  16 +++++++++++++++
 usr.bin/timeout/timeout.c |  48 +++++++++++++++++++++++++++++++++++-----------
 4 files changed, 57 insertions(+), 15 deletions(-)

diffs (160 lines):

diff -r 2697c2d3e4fd -r 5c7f94027096 usr.bin/Makefile
--- a/usr.bin/Makefile  Fri Aug 01 13:50:55 2014 +0000
+++ b/usr.bin/Makefile  Fri Aug 01 14:01:30 2014 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.217 2014/04/15 22:09:27 ginsbach Exp $
+#      $NetBSD: Makefile,v 1.218 2014/08/01 14:01:30 christos Exp $
 #      from: @(#)Makefile      8.3 (Berkeley) 1/7/94
 
 .include <bsd.own.mk>
@@ -26,7 +26,8 @@
        rup ruptime rusers rwall rwho \
        script sdiff sdpquery sed seq shar shlock \
        showmount shuffle sockstat sort spell split stat su systat \
-       tabs tail talk tcopy tee telnet tftp tic time tip touch tpfmt tput \
+       tabs tail talk tcopy tee telnet tftp tic time timeout tip touch \
+       tpfmt tput \
        tr true tset tsort tty ul uname unexpand unifdef \
        uniq units unvis unzip usbhidaction usbhidctl users utoppya \
        uudecode uuencode uuidgen vacation vgrind videoctl vis \
diff -r 2697c2d3e4fd -r 5c7f94027096 usr.bin/timeout/Makefile
--- a/usr.bin/timeout/Makefile  Fri Aug 01 13:50:55 2014 +0000
+++ b/usr.bin/timeout/Makefile  Fri Aug 01 14:01:30 2014 +0000
@@ -1,5 +1,6 @@
+# $NetBSD: Makefile,v 1.2 2014/08/01 14:01:30 christos Exp $
 # $FreeBSD: head/usr.bin/timeout/Makefile 268745 2014-07-16 09:55:36Z bapt $
-
+WARNS=6
 PROG=  timeout
 
 .include <bsd.prog.mk>
diff -r 2697c2d3e4fd -r 5c7f94027096 usr.bin/timeout/timeout.1
--- a/usr.bin/timeout/timeout.1 Fri Aug 01 13:50:55 2014 +0000
+++ b/usr.bin/timeout/timeout.1 Fri Aug 01 14:01:30 2014 +0000
@@ -1,3 +1,5 @@
+.\"    $NetBSD: timeout.1,v 1.2 2014/08/01 14:01:30 christos Exp $
+.\"
 .\" Copyright (c) 2014 Baptiste Daroussin <bapt%FreeBSD.org@localhost>
 .\" All rights reserved.
 .\"
@@ -112,3 +114,17 @@
 .Sh SEE ALSO
 .Xr kill 1 ,
 .Xr signal 3
+.Sh HISTORY
+A
+.Nm
+utility appeared in a development branch of
+.Fx 11
+and was imported into
+.Nx 7 .
+The
+.Fx
+work is compatible with GNU
+.Xr timeout 1
+by Padraig Brady, from GNU Coreutils 8.21. The
+.Xr timeout 1
+utility first appeared in GNU Coreutils 7.0.
diff -r 2697c2d3e4fd -r 5c7f94027096 usr.bin/timeout/timeout.c
--- a/usr.bin/timeout/timeout.c Fri Aug 01 13:50:55 2014 +0000
+++ b/usr.bin/timeout/timeout.c Fri Aug 01 14:01:30 2014 +0000
@@ -1,3 +1,5 @@
+/* $NetBSD: timeout.c,v 1.2 2014/08/01 14:01:30 christos Exp $ */
+
 /*-
  * Copyright (c) 2014 Baptiste Daroussin <bapt%FreeBSD.org@localhost>
  * Copyright (c) 2014 Vsevolod Stakhov <vsevolod%FreeBSD.org@localhost>
@@ -26,7 +28,13 @@
  */
 
 #include <sys/cdefs.h>
+#if !defined(lint)
+#if 0
 __FBSDID("$FreeBSD: head/usr.bin/timeout/timeout.c 268763 2014-07-16 13:52:05Z bapt $");
+#else
+__RCSID("$NetBSD: timeout.c,v 1.2 2014/08/01 14:01:30 christos Exp $");
+#endif
+#endif /* not lint */
 
 #include <sys/time.h>
 #include <sys/wait.h>
@@ -34,6 +42,7 @@
 #include <err.h>
 #include <errno.h>
 #include <getopt.h>
+#include <limits.h>
 #include <signal.h>
 #include <stdbool.h>
 #include <stdio.h>
@@ -49,7 +58,7 @@
 static sig_atomic_t sig_alrm = 0;
 static sig_atomic_t sig_ign = 0;
 
-static void
+static void __dead
 usage(void)
 {
 
@@ -101,21 +110,34 @@
 static int
 parse_signal(const char *str)
 {
-       int sig, i;
-       const char *errstr;
+       long sig;
+       int i;
+       char *ep;
 
-       sig = strtonum(str, 0, sys_nsig, &errstr);
-
-       if (errstr == NULL)
-               return (sig);
-       if (strncasecmp(str, "SIG", 3) == 0)
+       if (strncasecmp(str, "SIG", 3) == 0) {
                str += 3;
 
-       for (i = 1; i < sys_nsig; i++) {
-               if (strcasecmp(str, sys_signame[i]) == 0)
-                       return (i);
+               for (i = 1; i < sys_nsig; i++) {
+                       if (strcasecmp(str, sys_signame[i]) == 0)
+                               return (i);
+               }
+
+               goto err;
        }
 
+       errno = 0;
+       sig = strtol(str, &ep, 10);
+
+       if (str[0] == '\0' || *ep != '\0')
+               goto err;
+       if (errno == ERANGE && (sig == INT_MAX || sig == INT_MIN))
+               goto err;
+       if (sig >= sys_nsig || sig < 0)
+               goto err;
+
+       return (int)sig;
+
+err:
        errx(EX_USAGE, "invalid signal");
 }
 
@@ -151,7 +173,7 @@
 
        memset(&tim, 0, sizeof(tim));
        tim.it_value.tv_sec = (time_t)iv;
-       iv -= (time_t)iv;
+       iv -= (double)tim.it_value.tv_sec;
        tim.it_value.tv_usec = (suseconds_t)(iv * 1000000UL);
 
        if (setitimer(ITIMER_REAL, &tim, NULL) == -1)
@@ -182,6 +204,8 @@
                SIGQUIT,
        };
 
+       setprogname(argv[0]);
+
        foreground = preserve = 0;
        second_kill = 0;
        cpid = -1;



Home | Main Index | Thread Index | Old Index