From owner-svn-src-head@FreeBSD.ORG Wed Jul 16 12:33:20 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 8CBED8C5; Wed, 16 Jul 2014 12:33:20 +0000 (UTC) Received: from mail-we0-x231.google.com (mail-we0-x231.google.com [IPv6:2a00:1450:400c:c03::231]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id A617422CE; Wed, 16 Jul 2014 12:33:19 +0000 (UTC) Received: by mail-we0-f177.google.com with SMTP id w62so807221wes.8 for ; Wed, 16 Jul 2014 05:33:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=h3fEoG2dk063gODyJGLeqv3rnQpmyiEkx2niM5So76E=; b=HtcKeLw2bjR4nqRBy/qPNxBBOGYdXxrOck/xAFLW8Ws3VxJ8jTtYn6iAJo904NlVRc 9npxcMRc0Ks/MgsPx4awa75JoaoWsygpGgCetWhljv3CZpZTWItgGfojdII9X1yE1o0m i+C3NrHRGT3QHnnboRkPt4toD6PUmFrEzTOEwFv/fLAiHb6B2gyCxw1oRPo05GeEaTcq tZNgbI0iT8R4erGI1eeO9eeUIWUinQZgIWNcUsCFj2q65OnuZy/gPy3D4bAn2NCYfd/Z z9LxAZ7EldkC7fGclNOXnKNfVWyRaDD3O+CJv1IX6nA5yX8cG0iQ8nLchUF+mob2eLj+ vayg== MIME-Version: 1.0 X-Received: by 10.194.120.35 with SMTP id kz3mr35731339wjb.38.1405513994454; Wed, 16 Jul 2014 05:33:14 -0700 (PDT) Sender: pluknet@gmail.com Received: by 10.216.241.70 with HTTP; Wed, 16 Jul 2014 05:33:14 -0700 (PDT) In-Reply-To: <201407160955.s6G9taro084054@svn.freebsd.org> References: <201407160955.s6G9taro084054@svn.freebsd.org> Date: Wed, 16 Jul 2014 16:33:14 +0400 X-Google-Sender-Auth: vh6RYuDcu5iCtvt8xUg-Rk9KabU Message-ID: Subject: Re: svn commit: r268745 - in head/usr.bin: . timeout From: Sergey Kandaurov To: Baptiste Daroussin Content-Type: text/plain; charset=ISO-8859-1 Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Jul 2014 12:33:20 -0000 On 16 July 2014 13:55, Baptiste Daroussin 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 > +.\" 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 > + * Copyright (c) 2014 Vsevolod Stakhov > + * 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 > +__FBSDID("$FreeBSD$"); > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#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