Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 16 Jul 2014 16:33:14 +0400
From:      Sergey Kandaurov <pluknet@freebsd.org>
To:        Baptiste Daroussin <bapt@freebsd.org>
Cc:        svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org
Subject:   Re: svn commit: r268745 - in head/usr.bin: . timeout
Message-ID:  <CAE-mSOJZqDyoN2VOV8BaGORx2Yr-xPa7a=6YE=uMLkvPnFpWww@mail.gmail.com>
In-Reply-To: <201407160955.s6G9taro084054@svn.freebsd.org>
References:  <201407160955.s6G9taro084054@svn.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On 16 July 2014 13:55, Baptiste Daroussin <bapt@freebsd.org> wrote:
> Author: bapt
> Date: Wed Jul 16 09:55:36 2014
> New Revision: 268745
> URL: http://svnweb.freebsd.org/changeset/base/268745
>
> Log:
>   New BSDL timeout(1) utility compatible with GNU timeout
[...]
(sorry, missed this in a previous reply)

> Added: head/usr.bin/timeout/timeout.1
> ==============================================================================
> --- /dev/null   00:00:00 1970   (empty, because file is newly added)
> +++ head/usr.bin/timeout/timeout.1      Wed Jul 16 09:55:36 2014        (r268745)
> @@ -0,0 +1,70 @@
> +.\" Copyright (c) 2014 Baptiste Daroussin <bapt@FreeBSD.org>
> +.\" All rights reserved.
> +.\"
> +.\" Redistribution and use in source and binary forms, with or without
> +.\" modification, are permitted provided that the following conditions
> +.\" are met:
> +.\" 1. Redistributions of source code must retain the above copyright
> +.\"    notice, this list of conditions and the following disclaimer.
> +.\" 2. Redistributions in binary form must reproduce the above copyright
> +.\"    notice, this list of conditions and the following disclaimer in the
> +.\"    documentation and/or other materials provided with the distribution.
> +.\"
> +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
> +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
> +.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
> +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
> +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
> +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
> +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
> +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
> +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
> +.\" SUCH DAMAGE.
> +.\"
> +.\" $FreeBSD$
> +.\"
> +.Dd July 16, 2014
> +.Dt TIMEOUT 1
> +.Os
> +.Sh NAME
> +.Nm timeout
> +.Nd run a command with a time limit
> +.Sh SYNOPSIS
> +.Nm
> +.Op Fl -signal Ar sig | Fl s Ar sig
> +.Op Fl -preserve-status
> +.Op Fl -kill-after Ar time | Fl k Ar time
> +.Op Fl -foreground
> +.Ao Ar duration Ac
> +.Ao Ar command Ac
> +.Ao Ar args ... Ac
> +.Sh DESCRIPTION
> +.Nm

please

The
.Nm
utility

> +starts the
> +.Ar command
> +with its
> +.Ar args
> +and kills if it is still runs after

and kills _it_ ?

> +.Ar duration .

in what units?

> +.Bl -tag -width "-k time, --kill-after time"
> +.It Fl -preserve-status
> +Always exist with the same status as
> +.Ar command
> +even if it times out.
> +.It Fl -foreground
> +Do not propagate timeout to the
> +.Ar command
> +children.
> +.It Fl s Ar sig , Fl -signal Ar sig
> +Speficy the signal to send on timeout by default
> +.Ar SIGTERM .
> +.It Fl k Ar time , Fl -kill-after Ar time
> +Send a second kill if the
> +.Ar command
> +is still running after
> +.Ar time
> +seconds after the first signal was sent
> +.Sh SEE ALSO
> +.Xr signal 3 ,
> +.Xr kill 1

The entries are unsorted.

>
> Added: head/usr.bin/timeout/timeout.c
> ==============================================================================
> --- /dev/null   00:00:00 1970   (empty, because file is newly added)
> +++ head/usr.bin/timeout/timeout.c      Wed Jul 16 09:55:36 2014        (r268745)
> @@ -0,0 +1,336 @@
> +/*-
> + * Copyright (c) 2014 Baptiste Daroussin <bapt@FreeBSD.org>
> + * Copyright (c) 2014 Vsevolod Stakhov <vsevolod@FreeBSD.org>
> + * All rights reserved.
> + *~
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + * 1. Redistributions of source code must retain the above copyright
> + *    notice, this list of conditions and the following disclaimer
> + *    in this position and unchanged.
> + * 2. Redistributions in binary form must reproduce the above copyright
> + *    notice, this list of conditions and the following disclaimer in the
> + *    documentation and/or other materials provided with the distribution.
> + *~
> + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
> + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
> + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
> + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
> + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
> + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
> + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
> + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
> + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
> + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
> + */
> +
> +#include <sys/cdefs.h>
> +__FBSDID("$FreeBSD$");
> +
> +#include <sys/types.h>
> +#include <sys/time.h>
> +#include <sys/wait.h>
> +#include <signal.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <sysexits.h>
> +#include <unistd.h>
> +#include <getopt.h>
> +#include <err.h>
> +#include <spawn.h>
> +#include <errno.h>
> +#include <stdbool.h>
> +
> +#define EXIT_TIMEOUT 124
> +

this magic macro is used only once

[...]

> +int
> +main(int argc, char **argv)
> +{
> +       int ch;
> +       unsigned long i;
> +       int foreground, preserve;
> +       int error, pstat, status;
> +       int killsig = SIGTERM;
> +       int killedwith;
> +       pid_t pgid, pid, cpid;
> +       double first_kill;
> +       double second_kill;
> +       bool timedout = false;
> +       bool do_second_kill = false;
> +       struct sigaction signals;
> +       int signums[] = {
> +               -1,
> +               SIGTERM,
> +               SIGINT,
> +               SIGHUP,
> +               SIGCHLD,
> +               SIGALRM,
> +               SIGQUIT,
> +       };
> +

this is presumably largely unsorted

-- 
wbr,
pluknet



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAE-mSOJZqDyoN2VOV8BaGORx2Yr-xPa7a=6YE=uMLkvPnFpWww>