From debbugs-submit-bounces@debbugs.gnu.org Sat Jul 16 15:28:52 2011 Received: (at submit) by debbugs.gnu.org; 16 Jul 2011 19:28:53 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QiAXj-0004qN-VZ for submit@debbugs.gnu.org; Sat, 16 Jul 2011 15:28:52 -0400 Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QiAXj-0004qC-5L for submit@debbugs.gnu.org; Sat, 16 Jul 2011 15:28:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QiAXc-0006ph-TE for submit@debbugs.gnu.org; Sat, 16 Jul 2011 15:28:46 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD autolearn=unavailable version=3.3.1 Received: from lists.gnu.org ([140.186.70.17]:52033) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QiAXc-0006pc-Jh for submit@debbugs.gnu.org; Sat, 16 Jul 2011 15:28:44 -0400 Received: from eggs.gnu.org ([140.186.70.92]:34839) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QiAXb-0006i8-Bo for bug-coreutils@gnu.org; Sat, 16 Jul 2011 15:28:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QiAXa-0006pA-7v for bug-coreutils@gnu.org; Sat, 16 Jul 2011 15:28:43 -0400 Received: from smtp.cs.ucla.edu ([131.179.128.62]:56106) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QiAXZ-0006p0-RC for bug-coreutils@gnu.org; Sat, 16 Jul 2011 15:28:41 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id D3D5339E80F2 for ; Sat, 16 Jul 2011 12:28:40 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id TBiUyQrsIh9a for ; Sat, 16 Jul 2011 12:28:40 -0700 (PDT) Received: from [192.168.1.10] (pool-71-189-109-235.lsanca.fios.verizon.net [71.189.109.235]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 81ADC39E80E1 for ; Sat, 16 Jul 2011 12:28:40 -0700 (PDT) Message-ID: <4E21E668.40603@cs.ucla.edu> Date: Sat, 16 Jul 2011 12:28:40 -0700 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.18) Gecko/20110617 Thunderbird/3.1.11 MIME-Version: 1.0 To: bug-coreutils@gnu.org Subject: timeout should use setitimer if available Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 140.186.70.17 X-Spam-Score: -4.7 (----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -4.7 (----) setitimer has nanosecond resolution, which is better than the one-second resolution that 'alarm' has. timeout should use setitimer if available, to take advantage of this. On 64-bit hosts, this has the additional advantage of increasing the upper bound for timeouts from 2**31 seconds to 2**63 seconds (about 68 years to about 292 billion years, which should be long enough for most practical purposes :-). From debbugs-submit-bounces@debbugs.gnu.org Sun Jul 17 05:59:07 2011 Received: (at 9101) by debbugs.gnu.org; 17 Jul 2011 09:59:08 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QiO7v-0004hK-Fs for submit@debbugs.gnu.org; Sun, 17 Jul 2011 05:59:07 -0400 Received: from mx.meyering.net ([82.230.74.64]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QiO7t-0004gq-Ti for 9101@debbugs.gnu.org; Sun, 17 Jul 2011 05:59:06 -0400 Received: from rho.meyering.net (localhost.localdomain [127.0.0.1]) by rho.meyering.net (Acme Bit-Twister) with ESMTP id 1FE5463C97; Sun, 17 Jul 2011 11:59:00 +0200 (CEST) From: Jim Meyering To: Paul Eggert Subject: Re: bug#9101: timeout should use setitimer if available In-Reply-To: <4E21E668.40603@cs.ucla.edu> (Paul Eggert's message of "Sat, 16 Jul 2011 12:28:40 -0700") References: <4E21E668.40603@cs.ucla.edu> Date: Sun, 17 Jul 2011 11:59:00 +0200 Message-ID: <87vcv1p6sb.fsf@rho.meyering.net> Lines: 12 MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -6.1 (------) X-Debbugs-Envelope-To: 9101 Cc: 9101@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -6.1 (------) Paul Eggert wrote: > setitimer has nanosecond resolution, which is better than the > one-second resolution that 'alarm' has. timeout should use > setitimer if available, to take advantage of this. On 64-bit > hosts, this has the additional advantage of increasing the > upper bound for timeouts from 2**31 seconds to 2**63 seconds > (about 68 years to about 292 billion years, which should be > long enough for most practical purposes :-). I like the idea of supporting a sub-second timeout interval, but it probably deserves a warning in the documentation. Even a command like "timeout 3 sleep 1" will timeout on a system under heavy load. From debbugs-submit-bounces@debbugs.gnu.org Mon Jul 18 06:03:24 2011 Received: (at 9101) by debbugs.gnu.org; 18 Jul 2011 10:03:25 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Qikfc-0006HF-6G for submit@debbugs.gnu.org; Mon, 18 Jul 2011 06:03:24 -0400 Received: from mail1.slb.deg.dub.stisp.net ([84.203.253.98]) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1QikfZ-0006H1-67 for 9101@debbugs.gnu.org; Mon, 18 Jul 2011 06:03:22 -0400 Received: (qmail 21646 invoked from network); 18 Jul 2011 10:03:14 -0000 Received: from unknown (HELO ?192.168.2.25?) (84.203.137.218) by mail1.slb.deg.dub.stisp.net with SMTP; 18 Jul 2011 10:03:14 -0000 Message-ID: <4E240462.7000904@draigBrady.com> Date: Mon, 18 Jul 2011 11:01:06 +0100 From: =?UTF-8?B?UMOhZHJhaWcgQnJhZHk=?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3 MIME-Version: 1.0 To: Paul Eggert Subject: Re: bug#9101: timeout should use setitimer if available References: <4E21E668.40603@cs.ucla.edu> In-Reply-To: <4E21E668.40603@cs.ucla.edu> X-Enigmail-Version: 1.0.1 Content-Type: multipart/mixed; boundary="------------040906090902050908070904" X-Spam-Score: -2.6 (--) X-Debbugs-Envelope-To: 9101 Cc: 9101@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.6 (--) This is a multi-part message in MIME format. --------------040906090902050908070904 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 16/07/11 20:28, Paul Eggert wrote: > setitimer has nanosecond resolution, which is better than the > one-second resolution that 'alarm' has. timeout should use > setitimer if available, to take advantage of this. On 64-bit > hosts, this has the additional advantage of increasing the > upper bound for timeouts from 2**31 seconds to 2**63 seconds > (about 68 years to about 292 billion years, which should be > long enough for most practical purposes :-). I'll apply this soon. cheers, Pádraig. --------------040906090902050908070904 Content-Type: text/x-patch; name="timeout-float.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="timeout-float.diff" >From 057796b81c0de662700a801d49426e9e56e5bc44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?= Date: Mon, 18 Jul 2011 10:49:17 +0100 Subject: [PATCH] timeout: support sub-second timeouts * src/timeout.c (settimeout): A new function to convert from a floating point duration and all alarm() or setitimer() if that's available. (parse_duration): Return a double rather than unsigned int. (usage): Mention floating point supported. (main): Pass the double to settimeout() rather than calling alarm() directly with the parsed int. (cleanup): Likewise. * doc/coreutils.texi (timeout invocation): Say floating point timeouts now supported, and mention the caveat with resolution. * m4/jm-macros.m4: Check for setitimer. * tests/misc/timeout-parameters: Add a test for the nanosecond to microsecond conversion boundary. * NEWS: Mention the improvement. --- NEWS | 2 + doc/coreutils.texi | 4 ++- m4/jm-macros.m4 | 5 ++- src/timeout.c | 65 +++++++++++++++++++++++++++++------------ tests/misc/timeout-parameters | 3 ++ 5 files changed, 58 insertions(+), 21 deletions(-) diff --git a/NEWS b/NEWS index c382200..2119f64 100644 --- a/NEWS +++ b/NEWS @@ -50,6 +50,8 @@ GNU coreutils NEWS -*- outline -*- stat -f now recognizes the GPFS, MQUEUE and PSTOREFS file system types. + timeout allows sub-second timeouts where supported. + ** Build-related Changes inherited from gnulib address a build failure on HP-UX 11.11 diff --git a/doc/coreutils.texi b/doc/coreutils.texi index 424446c..b406a3c 100644 --- a/doc/coreutils.texi +++ b/doc/coreutils.texi @@ -15694,7 +15694,7 @@ or a number. Also see @xref{Signal specifications}. @end table @cindex time units -@var{duration} is an integer followed by an optional unit: +@var{duration} is a floating point number followed by an optional unit: @display @samp{s} for seconds (the default) @samp{m} for minutes @@ -15702,6 +15702,8 @@ or a number. Also see @xref{Signal specifications}. @samp{d} for days @end display A duration of 0 disables the associated timeout. +Note that the actual timeout duration is dependent on system conditions, +which should be especially considered when specifying sub-second timeouts. @cindex exit status of @command{timeout} Exit status: diff --git a/m4/jm-macros.m4 b/m4/jm-macros.m4 index 9bb6fa4..fa75708 100644 --- a/m4/jm-macros.m4 +++ b/m4/jm-macros.m4 @@ -66,7 +66,10 @@ AC_DEFUN([coreutils_MACROS], # Used by sort.c. AC_CHECK_FUNCS_ONCE([nl_langinfo]) # Used by timeout.c - AC_CHECK_FUNCS_ONCE([setrlimit]) + AC_CHECK_FUNCS_ONCE( \ + setrlimit \ + setitimer \ + ) # Used by tail.c. AC_CHECK_FUNCS([inotify_init], diff --git a/src/timeout.c b/src/timeout.c index ccb4f85..bbbe8c3 100644 --- a/src/timeout.c +++ b/src/timeout.c @@ -78,7 +78,7 @@ static int timed_out; static int term_signal = SIGTERM; /* same default as kill command. */ static int monitored_pid; static int sigs_to_ignore[NSIG]; /* so monitor can ignore sigs it resends. */ -static unsigned long kill_after; +static double kill_after; static bool foreground; /* whether to use another program group. */ /* for long options with no corresponding short option, use enum */ @@ -97,6 +97,45 @@ static struct option const long_options[] = {NULL, 0, NULL, 0} }; +/* Start the timeout after which we'll receive a SIGALRM. + Round DURATION up to the next representable value. + Treat out-of-range values as if they were maximal, + as that's more useful in practice than reporting an error. + '0' means don't timeout. */ +static void +settimeout (double duration) +{ +#if HAVE_SETITIMER + struct timeval tv; + struct timespec ts = dtotimespec (duration); + tv.tv_sec = MIN (ts.tv_sec, LONG_MAX); /* Assuming tv_sec is positive. */ + tv.tv_usec = (ts.tv_nsec + 999) / 1000; + if (tv.tv_usec == 1000 * 1000) + { + if (tv.tv_sec != LONG_MAX) + { + tv.tv_sec++; + tv.tv_usec = 0; + } + else + tv.tv_usec--; + } + struct itimerval it = { {0, 0}, tv }; + if (setitimer (ITIMER_REAL, &it, NULL) == -1) + error (EXIT_FAILURE, errno, _("error setting timer")); +#else + unsigned int timeint; + if (UINT_MAX <= duration) + timeint = UINT_MAX; + else + { + unsigned int duration_floor = duration; + timeint = duration_floor + (duration_floor < duration); + } + alarm (timeint); +#endif +} + /* send sig to group but not ourselves. * FIXME: Is there a better way to achieve this? */ static int @@ -125,7 +164,7 @@ cleanup (int sig) { /* Start a new timeout after which we'll send SIGKILL. */ term_signal = SIGKILL; - alarm (kill_after); + settimeout (kill_after); kill_after = 0; /* Don't let later signals reset kill alarm. */ } @@ -182,7 +221,7 @@ Mandatory arguments to long options are mandatory for short options too.\n\ fputs (VERSION_OPTION_DESCRIPTION, stdout); fputs (_("\n\ -DURATION is an integer with an optional suffix:\n\ +DURATION is a floating point number with an optional suffix:\n\ `s' for seconds (the default), `m' for minutes, `h' for hours \ or `d' for days.\n"), stdout); @@ -232,7 +271,7 @@ apply_time_suffix (double *x, char suffix_char) return true; } -static unsigned int +static double parse_duration (const char* str) { double duration; @@ -250,19 +289,7 @@ parse_duration (const char* str) usage (EXIT_CANCELED); } - /* Return the requested duration, rounded up to the next representable value. - Treat out-of-range values as if they were maximal, - as that's more useful in practice than reporting an error. - - FIXME: Use dtotimespec + setitimer if setitimer is available, - as that has higher resolution. */ - if (UINT_MAX <= duration) - return UINT_MAX; - else - { - unsigned int duration_floor = duration; - return duration_floor + (duration_floor < duration); - } + return duration; } static void @@ -285,7 +312,7 @@ install_signal_handlers (int sigterm) int main (int argc, char **argv) { - unsigned long timeout; + double timeout; char signame[SIG2STR_MAX]; int c; @@ -373,7 +400,7 @@ main (int argc, char **argv) pid_t wait_result; int status; - alarm (timeout); + settimeout (timeout); while ((wait_result = waitpid (monitored_pid, &status, 0)) < 0 && errno == EINTR) diff --git a/tests/misc/timeout-parameters b/tests/misc/timeout-parameters index 56804a8..e99d4a5 100755 --- a/tests/misc/timeout-parameters +++ b/tests/misc/timeout-parameters @@ -55,6 +55,9 @@ test $? = 0 || fail=1 timeout 2.34e+5d sleep 0 test $? = 0 || fail=1 +# nanoseconds rounded up to microseconds +timeout .999999999 sleep 0 || fail=1 + # invalid signal spec timeout --signal=invalid 1 sleep 0 test $? = 125 || fail=1 -- 1.7.5.2 --------------040906090902050908070904-- From debbugs-submit-bounces@debbugs.gnu.org Mon Jul 18 12:44:17 2011 Received: (at 9101) by debbugs.gnu.org; 18 Jul 2011 16:44:17 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QiqvZ-0007lt-2G for submit@debbugs.gnu.org; Mon, 18 Jul 2011 12:44:17 -0400 Received: from smtp.cs.ucla.edu ([131.179.128.62]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QiqvX-0007lh-2Q for 9101@debbugs.gnu.org; Mon, 18 Jul 2011 12:44:16 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 206E939E80F8; Mon, 18 Jul 2011 09:44:09 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id IxhCQ8za0eU4; Mon, 18 Jul 2011 09:44:08 -0700 (PDT) Received: from [131.179.64.200] (Penguin.CS.UCLA.EDU [131.179.64.200]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id ABB0739E80F7; Mon, 18 Jul 2011 09:44:08 -0700 (PDT) Message-ID: <4E2462D8.1060606@cs.ucla.edu> Date: Mon, 18 Jul 2011 09:44:08 -0700 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110621 Fedora/3.1.11-1.fc14 Thunderbird/3.1.11 MIME-Version: 1.0 To: =?UTF-8?B?UMOhZHJhaWcgQnJhZHk=?= Subject: Re: bug#9101: timeout should use setitimer if available References: <4E21E668.40603@cs.ucla.edu> <4E240462.7000904@draigBrady.com> In-Reply-To: <4E240462.7000904@draigBrady.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -3.1 (---) X-Debbugs-Envelope-To: 9101 Cc: 9101@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -3.1 (---) On 07/18/11 03:01, P=C3=A1draig Brady wrote: > I'll apply this soon. Thanks for doing that. Some comments: I see that my bug report was incoherent, as it was talking about nanosecond resolution and setitimer, when I meant to be writing about timer_settime (which *does* have nanosecond resolution). Sorry about that. POSIX says that setitimer is obsolescent, and that applications should us= e timer_settime. How about if we add a gnulib module for timer_settime and have 'timeout' use that instead? (This could be a separate patch, done later.) + struct timespec ts =3D dtotimespec (duration); + tv.tv_sec =3D MIN (ts.tv_sec, LONG_MAX); /* Assuming tv_sec is posi= tive. */ That second statement should be removed. time_t is not necessarily the same as 'long', and setitimer should work with values longer than LONG_MAX, if time_t is wider than 'long'. And parse_duration when combined with dtotimespec guarantees that tv_sec is nonnegative here (it might be zero), so that comment needs to be removed too. + if (tv.tv_sec !=3D LONG_MAX) This LONG_MAX should be TYPE_MAXIMUM (time_t). Of course all of this rounding-and-checking-for-overflow business goes away once we go to timer_settime.... From debbugs-submit-bounces@debbugs.gnu.org Mon Jul 18 18:19:45 2011 Received: (at 9101) by debbugs.gnu.org; 18 Jul 2011 22:19:45 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QiwAC-0007iW-N1 for submit@debbugs.gnu.org; Mon, 18 Jul 2011 18:19:44 -0400 Received: from mail1.slb.deg.dub.stisp.net ([84.203.253.98]) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1QiwAA-0007iJ-L2 for 9101@debbugs.gnu.org; Mon, 18 Jul 2011 18:19:43 -0400 Received: (qmail 37182 invoked from network); 18 Jul 2011 22:19:36 -0000 Received: from unknown (HELO ?192.168.2.25?) (84.203.137.218) by mail1.slb.deg.dub.stisp.net with SMTP; 18 Jul 2011 22:19:36 -0000 Message-ID: <4E24B0F5.1030500@draigBrady.com> Date: Mon, 18 Jul 2011 23:17:25 +0100 From: =?UTF-8?B?UMOhZHJhaWcgQnJhZHk=?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3 MIME-Version: 1.0 To: Paul Eggert Subject: Re: bug#9101: timeout should use setitimer if available References: <4E21E668.40603@cs.ucla.edu> <4E240462.7000904@draigBrady.com> <4E2462D8.1060606@cs.ucla.edu> In-Reply-To: <4E2462D8.1060606@cs.ucla.edu> X-Enigmail-Version: 1.0.1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.6 (--) X-Debbugs-Envelope-To: 9101 Cc: 9101@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.6 (--) On 18/07/11 17:44, Paul Eggert wrote: > On 07/18/11 03:01, Pádraig Brady wrote: >> I'll apply this soon. > > Thanks for doing that. Some comments: > > I see that my bug report was incoherent, as it was talking about > nanosecond resolution and setitimer, when I meant to be writing about > timer_settime (which *does* have nanosecond resolution). Sorry about > that. > > POSIX says that setitimer is obsolescent, and that applications should use > timer_settime. How about if we add a gnulib module for timer_settime > and have 'timeout' use that instead? (This could be a separate patch, > done later.) Hmm. We don't need the extra resolution or functionality of timer_settime(). So I prefer the simplier setitimer() interface TBH. Currently, setitimer should be more portable too, I guess. No rush with timer_settime() I think. > > + struct timespec ts = dtotimespec (duration); > + tv.tv_sec = MIN (ts.tv_sec, LONG_MAX); /* Assuming tv_sec is positive. */ > > That second statement should be removed. time_t is not necessarily > the same as 'long', and setitimer should work with values longer than > LONG_MAX, if time_t is wider than 'long'. Bah, I was confused by the linux setitimer man page which explicitly stated 'long' was used for setitimer. Also the value on freebsd is truncated to 100000000. > And parse_duration when > combined with dtotimespec guarantees that tv_sec is nonnegative here > (it might be zero), so that comment needs to be removed too. Well the comment was confirming that for the purpose of that calculation :) > > + if (tv.tv_sec != LONG_MAX) > > This LONG_MAX should be TYPE_MAXIMUM (time_t). Could it ever be 'long', and that being different to time_t? I suppose we could use _GL_INT_MAXIMUM (tv.tv_sec), but I'll assume time_t is always used for the moment. I'll use the following: static void settimeout (double duration) { struct timeval tv; struct timespec ts = dtotimespec (duration); tv.tv_usec = (ts.tv_nsec + 999) / 1000; if (tv.tv_usec == 1000 * 1000) { if (tv.tv_sec != TYPE_MAXIMUM (time_t)) { tv.tv_sec++; tv.tv_usec = 0; } else tv.tv_usec--; } struct itimerval it = { {0, 0}, tv }; if (setitimer (ITIMER_REAL, &it, NULL) == -1) error (EXIT_FAILURE, errno, _("error setting timer")); } > Of course all of this rounding-and-checking-for-overflow business > goes away once we go to timer_settime.... Talking about overflow, for my own reference I noticed that there was some info lost in the double -> 64bit conversion: $ strace -e setitimer src/timeout 9223372036852775425 sleep 0 setitimer(ITIMER_REAL, {it_interval={0, 0}, it_value={9223372036852775936, 0}}, NULL) = 0 Not a practical issue for `timeout` at least. I'm marking this bug done now. thanks for the review, Pádraig. From debbugs-submit-bounces@debbugs.gnu.org Mon Jul 18 19:05:53 2011 Received: (at 9101) by debbugs.gnu.org; 18 Jul 2011 23:05:53 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Qiwsr-0000Iw-JZ for submit@debbugs.gnu.org; Mon, 18 Jul 2011 19:05:53 -0400 Received: from smtp.cs.ucla.edu ([131.179.128.62]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Qiwsp-0000Ij-3c for 9101@debbugs.gnu.org; Mon, 18 Jul 2011 19:05:52 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 002BA39E80F7; Mon, 18 Jul 2011 16:05:44 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id L4ki+O6jLDul; Mon, 18 Jul 2011 16:05:44 -0700 (PDT) Received: from [131.179.64.200] (Penguin.CS.UCLA.EDU [131.179.64.200]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 83C6239E80E0; Mon, 18 Jul 2011 16:05:44 -0700 (PDT) Message-ID: <4E24BC48.3050809@cs.ucla.edu> Date: Mon, 18 Jul 2011 16:05:44 -0700 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110621 Fedora/3.1.11-1.fc14 Thunderbird/3.1.11 MIME-Version: 1.0 To: =?UTF-8?B?UMOhZHJhaWcgQnJhZHk=?= Subject: Re: bug#9101: timeout should use setitimer if available References: <4E21E668.40603@cs.ucla.edu> <4E240462.7000904@draigBrady.com> <4E2462D8.1060606@cs.ucla.edu> <4E24B0F5.1030500@draigBrady.com> In-Reply-To: <4E24B0F5.1030500@draigBrady.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -3.1 (---) X-Debbugs-Envelope-To: 9101 Cc: 9101@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -3.1 (---) On 07/18/11 15:17, P=C3=A1draig Brady wrote: > I noticed that there was some info lost > in the double -> 64bit conversion: >=20 > $ strace -e setitimer src/timeout 9223372036852775425 sleep 0 > setitimer(ITIMER_REAL, {it_interval=3D{0, 0}, it_value=3D{9223372036852= 775936, 0}}, NULL) =3D 0 The info is lost in converting string to double. IEEE-754 double can represent integers exactly up through 2**52; then it starts losing information. We could work around this on x86 by going to long double, but... > Not a practical issue for `timeout` at least. Exactly. >> + if (tv.tv_sec !=3D LONG_MAX) >> >=20 >> > This LONG_MAX should be TYPE_MAXIMUM (time_t). > Could it ever be 'long', and that being different to time_t? Not on any host I know of. Historically tv_sec has always been of type time_t, and POSIX requires it; I don't expect this to change. > We don't need the extra resolution This is true in a practical sense, but it'd be nice to do it "right", if only for the future machines that can really do sub-microsecond timing accurately. Obviously this is low priority though. From debbugs-submit-bounces@debbugs.gnu.org Tue Jul 19 07:02:52 2011 Received: (at 9101) by debbugs.gnu.org; 19 Jul 2011 11:02:52 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Qj84e-0007jK-SG for submit@debbugs.gnu.org; Tue, 19 Jul 2011 07:02:52 -0400 Received: from mail1.slb.deg.dub.stisp.net ([84.203.253.98]) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1Qj84Z-0007j2-2r for 9101@debbugs.gnu.org; Tue, 19 Jul 2011 07:02:47 -0400 Received: (qmail 30258 invoked from network); 19 Jul 2011 11:02:36 -0000 Received: from unknown (HELO ?192.168.2.25?) (84.203.137.218) by mail1.slb.deg.dub.stisp.net with SMTP; 19 Jul 2011 11:02:36 -0000 Message-ID: <4E2563C7.30001@draigBrady.com> Date: Tue, 19 Jul 2011 12:00:23 +0100 From: =?UTF-8?B?UMOhZHJhaWcgQnJhZHk=?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3 MIME-Version: 1.0 To: Paul Eggert Subject: Re: bug#9101: timeout should use setitimer if available References: <4E21E668.40603@cs.ucla.edu> <4E240462.7000904@draigBrady.com> <4E2462D8.1060606@cs.ucla.edu> <4E24B0F5.1030500@draigBrady.com> In-Reply-To: <4E24B0F5.1030500@draigBrady.com> X-Enigmail-Version: 1.0.1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.6 (--) X-Debbugs-Envelope-To: 9101 Cc: 9101@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.6 (--) On 18/07/11 23:17, Pádraig Brady wrote: > On 18/07/11 17:44, Paul Eggert wrote: >> On 07/18/11 03:01, Pádraig Brady wrote: >>> I'll apply this soon. >> >> Thanks for doing that. Some comments: >> >> I see that my bug report was incoherent, as it was talking about >> nanosecond resolution and setitimer, when I meant to be writing about >> timer_settime (which *does* have nanosecond resolution). Sorry about >> that. >> >> POSIX says that setitimer is obsolescent, and that applications should use >> timer_settime. How about if we add a gnulib module for timer_settime >> and have 'timeout' use that instead? (This could be a separate patch, >> done later.) > > Hmm. We don't need the extra resolution or functionality of timer_settime(). > So I prefer the simplier setitimer() interface TBH. > Currently, setitimer should be more portable too, I guess. > No rush with timer_settime() I think. Note the main current platform missing timer_settimer is darwin. Using timer_settimer isn't that onerous actually. The gnulib check could be lumped into clock_time, like: diff --git a/m4/clock_time.m4 b/m4/clock_time.m4 index 3c08512..344d330 100644 --- a/m4/clock_time.m4 +++ b/m4/clock_time.m4 @@ -4,7 +4,7 @@ dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. -# Check for clock_gettime and clock_settime, and set LIB_CLOCK_GETTIME. +# Check for clock_[gs]ettime and timer_settime, and set LIB_CLOCK_GETTIME. # For a program named, say foo, you should add a line like the following # in the corresponding Makefile.am file: # foo_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME) @@ -26,6 +26,6 @@ AC_DEFUN([gl_CLOCK_TIME], AC_SEARCH_LIBS([clock_gettime], [rt posix4], [test "$ac_cv_search_clock_gettime" = "none required" || LIB_CLOCK_GETTIME=$ac_cv_search_clock_gettime]) - AC_CHECK_FUNCS([clock_gettime clock_settime]) + AC_CHECK_FUNCS([clock_gettime clock_settime timer_settime]) LIBS=$gl_saved_libs ]) And coreutils could use it like: diff --git a/src/Makefile.am b/src/Makefile.am index ef0e7a4..76cee0d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -329,6 +329,7 @@ date_LDADD += $(LIB_CLOCK_GETTIME) ginstall_LDADD += $(LIB_CLOCK_GETTIME) ls_LDADD += $(LIB_CLOCK_GETTIME) pr_LDADD += $(LIB_CLOCK_GETTIME) +timeout_LDADD += $(LIB_CLOCK_GETTIME) touch_LDADD += $(LIB_CLOCK_GETTIME) # for gethrxtime diff --git a/src/timeout.c b/src/timeout.c index bfca548..8b5ff8d 100644 --- a/src/timeout.c +++ b/src/timeout.c @@ -105,7 +105,15 @@ static struct option const long_options[] = static void settimeout (double duration) { -#if HAVE_SETITIMER +#if HAVE_TIMER_SETTIME + struct timespec ts = dtotimespec (duration); + struct itimerspec its = { {0, 0}, ts }; + timer_t timerid; + if (timer_create (CLOCK_REALTIME, NULL, &timerid) == -1) + error (EXIT_FAILURE, errno, _("error in timer_create")); + if (timer_settime (timerid, 0, &its, NULL) == -1) + error (EXIT_FAILURE, errno, _("error in timer_settime")); +#elif HAVE_SETITIMER struct timeval tv; struct timespec ts = dtotimespec (duration); tv.tv_usec = (ts.tv_nsec + 999) / 1000; We could remove the setitimer stuff altogether and just support 1 second resolution on darwin et. al. That's by far the most common use case anyway. cheers, Pádraig. From debbugs-submit-bounces@debbugs.gnu.org Tue Jul 19 14:46:15 2011 Received: (at 9101) by debbugs.gnu.org; 19 Jul 2011 18:46:15 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QjFJ9-0000hx-2z for submit@debbugs.gnu.org; Tue, 19 Jul 2011 14:46:15 -0400 Received: from smtp.cs.ucla.edu ([131.179.128.62]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QjFJ4-0000he-QK for 9101@debbugs.gnu.org; Tue, 19 Jul 2011 14:46:12 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id C3FF939E80F7; Tue, 19 Jul 2011 11:46:04 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Gep+Xch2wcgT; Tue, 19 Jul 2011 11:45:59 -0700 (PDT) Received: from [131.179.64.200] (Penguin.CS.UCLA.EDU [131.179.64.200]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 6BB0739E80E0; Tue, 19 Jul 2011 11:45:59 -0700 (PDT) Message-ID: <4E25D0E7.6070900@cs.ucla.edu> Date: Tue, 19 Jul 2011 11:45:59 -0700 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110621 Fedora/3.1.11-1.fc14 Thunderbird/3.1.11 MIME-Version: 1.0 To: =?UTF-8?B?UMOhZHJhaWcgQnJhZHk=?= Subject: Re: bug#9101: timeout should use setitimer if available References: <4E21E668.40603@cs.ucla.edu> <4E240462.7000904@draigBrady.com> <4E2462D8.1060606@cs.ucla.edu> <4E24B0F5.1030500@draigBrady.com> <4E2563C7.30001@draigBrady.com> In-Reply-To: <4E2563C7.30001@draigBrady.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -3.1 (---) X-Debbugs-Envelope-To: 9101 Cc: 9101@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -3.1 (---) On 07/19/11 04:00, P=C3=A1draig Brady wrote: > + if (timer_create (CLOCK_REALTIME, NULL, &timerid) =3D=3D -1) > + error (EXIT_FAILURE, errno, _("error in timer_create")); > + if (timer_settime (timerid, 0, &its, NULL) =3D=3D -1) > + error (EXIT_FAILURE, errno, _("error in timer_settime")); A minor point: the usual (more-conservative, and often-faster) style in coreutils is to write "foo (...) !=3D 0" rather than "foo (...) =3D=3D -1" for system calls that return 0 or -1. > We could remove the setitimer stuff altogether and > just support 1 second resolution on darwin et. al. > That's by far the most common use case anyway. That sounds good to me. Another thought, to make the code more bulletproof, is to fall back on alarm if timer_create and timer_settime fail due to ENOTSUP or EAGAIN or whatever. Something like this (untested) code: /* Start the timeout after which we'll receive a SIGALRM. Round DURATION up to the next representable value. Treat out-of-range values as if they were maximal, as that's more useful in practice than reporting an error. '0' means don't timeout. */ static void settimeout (double duration) { #if HAVE_TIMER_SETTIME /* Prefer timer_settime if it works, as it's higher-resolution. */ struct timespec ts =3D dtotimespec (duration); struct itimerspec its =3D { {0, 0}, ts }; timer_t timerid; if (timer_create (CLOCK_REALTIME, NULL, &timerid) =3D=3D 0) { if (timer_settime (timerid, 0, &its, NULL) =3D=3D 0) return; timer_delete (timerid); } #endif if (UINT_MAX <=3D duration) alarm (UINT_MAX); else { unsigned int duration_floor =3D duration; alarm (duration_floor + (duration_floor < duration)); } } > The gnulib check could be lumped into clock_time, like: Yes, that would work, but the clock-time module probably should stay decoupled from timer_settime. How about the following (untested) patch instead? The idea is to append "timeout_LDADD +=3D $(LIB_TIMER_SETTIME)" to src/Makefile.am. diff --git a/m4/jm-macros.m4 b/m4/jm-macros.m4 index 9bb6fa4..c32cbd3 100644 --- a/m4/jm-macros.m4 +++ b/m4/jm-macros.m4 @@ -43,6 +43,11 @@ AC_DEFUN([coreutils_MACROS], =20 # used by ls AC_REQUIRE([gl_CLOCK_TIME]) + coreutils_lib_pattern=3D'-l\(.*\)' + coreutils_lib_rt=3D` + expr "X$ac_cv_search_clock_gettime" : "X$coreutils_lib_pattern" + ` + # used by shred AC_CHECK_FUNCS_ONCE([directio]) =20 @@ -97,13 +102,24 @@ AC_DEFUN([coreutils_MACROS], # for dd.c and shred.c coreutils_saved_libs=3D$LIBS LIB_FDATASYNC=3D - AC_SEARCH_LIBS([fdatasync], [rt posix4], + AC_SEARCH_LIBS([fdatasync], [$coreutils_lib_rt], [test "$ac_cv_search_fdatasync" =3D "none required" |= | LIB_FDATASYNC=3D$ac_cv_search_fdatasync]) AC_SUBST([LIB_FDATASYNC]) AC_CHECK_FUNCS([fdatasync]) LIBS=3D$coreutils_saved_libs =20 + # used by timeout.c + AC_SUBST([LIB_TIMER_SETTIME]) + coreutils_saved_libs=3D$LIBS + LIB_TIMER_SETTIME=3D + AC_SEARCH_LIBS([timer_settime], [$coreutils_lib_rt], + [test "$ac_cv_search_timer_settime" =3D "none require= d" || + LIB_TIMER_SETTIME=3D$ac_cv_search_timer_settime]) + AC_SUBST([LIB_TIMER_SETTIME]) + AC_CHECK_FUNCS([timer_settim]) + LIBS=3D$coreutils_saved_libs + # Check whether libcap is usable -- for ls --color support LIB_CAP=3D AC_ARG_ENABLE([libcap], From debbugs-submit-bounces@debbugs.gnu.org Tue Jul 19 15:01:58 2011 Received: (at 9101) by debbugs.gnu.org; 19 Jul 2011 19:01:59 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QjFYM-00014D-2v for submit@debbugs.gnu.org; Tue, 19 Jul 2011 15:01:58 -0400 Received: from smtp12.hushmail.com ([65.39.178.135]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QjFYJ-00013z-Ig for 9101@debbugs.gnu.org; Tue, 19 Jul 2011 15:01:56 -0400 Received: from smtp12.hushmail.com (localhost.localdomain [127.0.0.1]) by smtp12.hushmail.com (Postfix) with SMTP id 42102C015F for <9101@debbugs.gnu.org>; Tue, 19 Jul 2011 19:01:49 +0000 (UTC) X-Hush-Verified-Domain: hush.ai Received: from smtp.hushmail.com (w7.hushmail.com [65.39.178.32]) by smtp12.hushmail.com (Postfix) with ESMTP; Tue, 19 Jul 2011 19:01:48 +0000 (UTC) Received: from [192.168.1.65] (unknown [65.39.178.78]) by smtp.hushmail.com (Postfix) with ESMTP id 4E9E26F43F; Tue, 19 Jul 2011 19:01:46 +0000 (UTC) Subject: Re: bug#9101: timeout should use setitimer if available Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: multipart/signed; protocol="application/pgp-signature"; micalg=pgp-sha1; boundary="Apple-Mail-1--65071004" From: SciFi X-Priority: 5 In-Reply-To: <4E2563C7.30001@draigBrady.com> Date: Tue, 19 Jul 2011 14:01:34 -0500 Content-Transfer-Encoding: 7bit Message-Id: References: <4E21E668.40603@cs.ucla.edu> <4E240462.7000904@draigBrady.com> <4E2462D8.1060606@cs.ucla.edu> <4E24B0F5.1030500@draigBrady.com> <4E2563C7.30001@draigBrady.com> To: =?iso-8859-1?Q?P=E1draig_Brady?= X-Pgp-Agent: GPGMail 1.3.3 X-Mailer: Apple Mail (2.1084) X-Spam-Score: -4.3 (----) X-Debbugs-Envelope-To: 9101 Cc: Paul Eggert , 9101@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -4.0 (----) This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --Apple-Mail-1--65071004 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=iso-8859-1 Hi, On Jul 19, 2011, at 06:00, P=E1draig Brady wrote: >=20 > We could remove the setitimer stuff altogether and > just support 1 second resolution on darwin et. al. > That's by far the most common use case anyway. If I may, since I am an OSX user [1] [2] , I cast my "vote" here. ;) [1] I am planning to use the 'timeout' CLI as part of a simple PVR app in conjunction with HDHomeRun=AE tuners. 1s-resolution is plenty, if I can also trust the age-old 'at'/'cron' mechanisms, too. ;) [2] OT: I am also planning to "jump ship", and have posted a big write-up on why I've decided this on the pan-users list (my current main project): = I'd like to invite anyone to comment in that thread. --Apple-Mail-1--65071004 content-type: application/pgp-signature; x-mac-type=70674453; name=PGP.sig content-description: This is a digitally signed message part content-disposition: inline; filename=PGP.sig content-transfer-encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.17 (Darwin) Comment: GPGTools - http://gpgtools.org iQEcBAEBAgAGBQJOJdSWAAoJEKkeWNKet7+K8qcIAJctdp6Cg6ELm4iFKpDnfkbB vKchX5Ie+VGfKp8Ze74ha8c3hrzs/rvqJmyFJkx90jfJQ1eNHsaFSiC3NC4UteOA 8HlJ50gsCxLvuu1rtYUhyMNlxvMLsfaq138F3tQWICcz1zpl+2Sfo9MKqbRKcH8e 9PwLYW7Duj2BOrVnkGLorci3BL/F7h1xSiNRvAu39zW4Dd1f5UhsLzp+ribTz9vN 20NStJBWCb4PeswDyIsZt2n0iQRprlF3upxmdbGQyUXv54q1iKjgp0XEdItymgy6 0xsr+JzQs+rL/PUMZ2cknFMzTsYWoB7HagrQ11wl3kzig2SXa/mTuGuq+AIeAxA= =xFdz -----END PGP SIGNATURE----- --Apple-Mail-1--65071004-- From debbugs-submit-bounces@debbugs.gnu.org Tue Jul 19 18:27:22 2011 Received: (at 9101) by debbugs.gnu.org; 19 Jul 2011 22:27:22 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QjIl3-0007KV-FC for submit@debbugs.gnu.org; Tue, 19 Jul 2011 18:27:22 -0400 Received: from mail1.slb.deg.dub.stisp.net ([84.203.253.98]) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1QjIkw-0007KD-N8 for 9101@debbugs.gnu.org; Tue, 19 Jul 2011 18:27:15 -0400 Received: (qmail 38311 invoked from network); 19 Jul 2011 22:27:04 -0000 Received: from unknown (HELO ?192.168.2.25?) (84.203.137.218) by mail1.slb.deg.dub.stisp.net with SMTP; 19 Jul 2011 22:27:04 -0000 Message-ID: <4E260430.4080403@draigBrady.com> Date: Tue, 19 Jul 2011 23:24:48 +0100 From: =?UTF-8?B?UMOhZHJhaWcgQnJhZHk=?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3 MIME-Version: 1.0 To: Paul Eggert Subject: Re: bug#9101: timeout should use setitimer if available References: <4E21E668.40603@cs.ucla.edu> <4E240462.7000904@draigBrady.com> <4E2462D8.1060606@cs.ucla.edu> <4E24B0F5.1030500@draigBrady.com> <4E2563C7.30001@draigBrady.com> <4E25D0E7.6070900@cs.ucla.edu> In-Reply-To: <4E25D0E7.6070900@cs.ucla.edu> X-Enigmail-Version: 1.0.1 Content-Type: multipart/mixed; boundary="------------000605080807060901050209" X-Spam-Score: -2.6 (--) X-Debbugs-Envelope-To: 9101 Cc: bug-gnulib , 9101@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.6 (--) This is a multi-part message in MIME format. --------------000605080807060901050209 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 19/07/11 19:45, Paul Eggert wrote: > On 07/19/11 04:00, Pádraig Brady wrote: > >> + if (timer_create (CLOCK_REALTIME, NULL, &timerid) == -1) >> + error (EXIT_FAILURE, errno, _("error in timer_create")); >> + if (timer_settime (timerid, 0, &its, NULL) == -1) >> + error (EXIT_FAILURE, errno, _("error in timer_settime")); > > A minor point: the usual (more-conservative, and often-faster) style > in coreutils is to write "foo (...) != 0" rather than "foo (...) == > -1" for system calls that return 0 or -1. > >> We could remove the setitimer stuff altogether and >> just support 1 second resolution on darwin et. al. >> That's by far the most common use case anyway. > OK I'll do that, encompassing your fallback suggestion. > >> The gnulib check could be lumped into clock_time, like: > > Yes, that would work, but the clock-time module probably should stay > decoupled from timer_settime. How about the following (untested) > patch instead? The idea is to append "timeout_LDADD += > $(LIB_TIMER_SETTIME)" to src/Makefile.am. > > diff --git a/m4/jm-macros.m4 b/m4/jm-macros.m4 I'd rather not add this into jm-macros. How about just adding a module to gnulib where others might find it useful too? Proposed module attached. cheers, Pádraig. --------------000605080807060901050209 Content-Type: text/x-patch; name="timer-time.diff" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="timer-time.diff" >From 40c196b627ab6b5343cabd7fd4befc0733142ba5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?= Date: Tue, 19 Jul 2011 21:51:49 +0100 Subject: [PATCH] timer-time: A new module to check for timer_settime() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * m4/timer_time.m4: Check for the POSIX function. * modules/timer-time: Add the new module. * MODULES.html.sh (Compat checks for POSIX:2008 functions): Mention it. Signed-off-by: Pádraig Brady --- ChangeLog | 8 ++++++++ MODULES.html.sh | 1 + m4/timer_time.m4 | 26 ++++++++++++++++++++++++++ modules/timer-time | 26 ++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 0 deletions(-) create mode 100644 m4/timer_time.m4 create mode 100644 modules/timer-time diff --git a/ChangeLog b/ChangeLog index e72af4c..fa135a2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2011-07-19 Pádraig Brady + timer-time: A new module to check for timer_settime() + * m4/timer_time.m4: Check for the posix function. + * modules/timer-time: Add the new module. + * MODULES.html.sh (Compat checks for POSIX:2008 functions): + Mention it. + +2011-07-19 Pádraig Brady + getopt-gnu: suppress core dumps from detection code * m4/getopt.m4 (gl_GETOPT_CHECK_HEADERS): Use the nocrash module to suppress core dumps that may well occur on glibc systems. diff --git a/MODULES.html.sh b/MODULES.html.sh index 99de344..bcd8aac 100755 --- a/MODULES.html.sh +++ b/MODULES.html.sh @@ -2522,6 +2522,7 @@ func_all_modules () func_module link-follow func_module rename-dest-slash func_module rmdir-errno + func_module timer-time func_module unlink-busy func_module winsz-ioctl func_module winsz-termios diff --git a/m4/timer_time.m4 b/m4/timer_time.m4 new file mode 100644 index 0000000..29e5a3d --- /dev/null +++ b/m4/timer_time.m4 @@ -0,0 +1,26 @@ +# timer_time.m4 serial 1 +dnl Copyright (C) 2011 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +# Check for timer_settime, and set LIB_TIMER_TIME. +# For a program named, say foo, you should add a line like the following +# in the corresponding Makefile.am file: +# foo_LDADD = $(LDADD) $(LIB_TIMER_TIME) + +AC_DEFUN([gl_TIMER_TIME], +[ + dnl Based on clock_time.m4. See details there. + + AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) + + LIB_TIMER_TIME= + AC_SUBST([LIB_TIMER_TIME]) + gl_saved_libs=$LIBS + AC_SEARCH_LIBS([timer_settime], [rt posix4], + [test "$ac_cv_search_timer_settime" = "none required" || + LIB_TIMER_TIME=$ac_cv_search_timer_settime]) + AC_CHECK_FUNCS([timer_settime]) + LIBS=$gl_saved_libs +]) diff --git a/modules/timer-time b/modules/timer-time new file mode 100644 index 0000000..1adcf2c --- /dev/null +++ b/modules/timer-time @@ -0,0 +1,26 @@ +Description: +Check for timer_settime. Within HAVE_TIMER_SETTIME one can +assume timer_create is available too, as that is a +prerequisite to use timer_settime. + +Files: +m4/timer_time.m4 + +Depends-on: +extensions + +configure.ac: +gl_TIMER_TIME + +Makefile.am: + +Include: + +Link: +$(LIB_TIMER_TIME) + +License: +LGPLv2+ + +Maintainer: +Pádraig Brady -- 1.7.5.2 --------------000605080807060901050209-- From debbugs-submit-bounces@debbugs.gnu.org Tue Jul 19 18:46:53 2011 Received: (at 9101) by debbugs.gnu.org; 19 Jul 2011 22:46:53 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QjJ40-0007nf-EO for submit@debbugs.gnu.org; Tue, 19 Jul 2011 18:46:53 -0400 Received: from smtp.cs.ucla.edu ([131.179.128.62]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QjJ3x-0007nT-S7 for 9101@debbugs.gnu.org; Tue, 19 Jul 2011 18:46:51 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 50E6839E80F7; Tue, 19 Jul 2011 15:46:44 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id G2f6KcWZzkAX; Tue, 19 Jul 2011 15:46:43 -0700 (PDT) Received: from [192.168.1.10] (pool-71-189-109-235.lsanca.fios.verizon.net [71.189.109.235]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id D2C3939E80E0; Tue, 19 Jul 2011 15:46:43 -0700 (PDT) Message-ID: <4E26094F.5050403@cs.ucla.edu> Date: Tue, 19 Jul 2011 15:46:39 -0700 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.18) Gecko/20110617 Thunderbird/3.1.11 MIME-Version: 1.0 To: =?UTF-8?B?UMOhZHJhaWcgQnJhZHk=?= Subject: Re: bug#9101: timeout should use setitimer if available References: <4E21E668.40603@cs.ucla.edu> <4E240462.7000904@draigBrady.com> <4E2462D8.1060606@cs.ucla.edu> <4E24B0F5.1030500@draigBrady.com> <4E2563C7.30001@draigBrady.com> <4E25D0E7.6070900@cs.ucla.edu> <4E260430.4080403@draigBrady.com> In-Reply-To: <4E260430.4080403@draigBrady.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -3.0 (---) X-Debbugs-Envelope-To: 9101 Cc: bug-gnulib , 9101@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -3.0 (---) On 07/19/11 15:24, P=C3=A1draig Brady wrote: > How about just adding a module to gnulib > where others might find it useful too? Yes, that's better, thanks. Could you please add Jim and me to the maintainer list? From debbugs-submit-bounces@debbugs.gnu.org Thu Oct 11 18:34:30 2018 Received: (at control) by debbugs.gnu.org; 11 Oct 2018 22:34:30 +0000 Received: from localhost ([127.0.0.1]:45702 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gAjXK-0004zX-B8 for submit@debbugs.gnu.org; Thu, 11 Oct 2018 18:34:30 -0400 Received: from mail-pg1-f182.google.com ([209.85.215.182]:45621) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gAjXI-0004zL-9d for control@debbugs.gnu.org; Thu, 11 Oct 2018 18:34:28 -0400 Received: by mail-pg1-f182.google.com with SMTP id t70-v6so4828541pgd.12 for ; Thu, 11 Oct 2018 15:34:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:message-id:date:user-agent:mime-version:content-language :content-transfer-encoding; bh=7apBCEYAVn0WRPO0lUXyhbI1fmL5j8ewFFZTMWbq3yI=; b=toL8k7fQ5KxcbpSCAnSstHi4BG3qCcxWJcN/bt/seLilla0Ue8MSoU9J1v5V6iO3fg Amtg9kpyXCz6IczP+2B5sJYJK3YfFfjxTAGmOxtTrod4ghSW0k15rGSpYxYDiFSlcAsB b+vq/HbVS9N7uvE1FMp1P3qbiMEIDsfLl6k4ET6Al2IcPeFzjjrZ9zwHGa2VJe/ExfXe 3jQYK+A79YMNLDdZUC61eJzXCsccw+t/vFb+7hJkDSgoB+YVi3OxSUwg8JCeiJ7OQyWV 5ZoV8ucVi7kf21B9kSPfhOsY9gPJXdQIdN2I3zwzq+DrwthawKhrBWKjm3NgJcH/itND ft5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=7apBCEYAVn0WRPO0lUXyhbI1fmL5j8ewFFZTMWbq3yI=; b=nuSXC9XJQrXagjzp9W7BnUZ1ommpMMtThBjiA0K4nSj9o4WjsFR3A+T1I38yKP0Fzo a80GuqT/kmd2gJ88NlNpMrUnhTux+WSOZT6sFbPjHet1qbxR/kyeBG+9D3hrvi5hSWA0 tPvm9ZgUek97jmNo/HTOyGsYT7L9WvOcTvbZmJCQO76Uela8KzNPYaRgVOQJVzz465na sR7y8GEOE2qoVSBsmVUSe1wlUlBo3OI4XiIlKUgqew8ofHkd3Hl+Mbbx5l67NR2KDA57 ZddvDznKsR+vGLbgzftMTy7UXhlrFIOgqUwKS/fIz34hApKzdH3ed7ALT7sbC92Nk5DQ euZw== X-Gm-Message-State: ABuFfoizOr8B6DzumAK7s/Z8zthjLcrY02/3IwhW8rDQY8Q2vWkcMPwY fJKVbts5ENDLCy3pJZy+ho5ZQXpS X-Google-Smtp-Source: ACcGV60Jjf/wOacofqXbjwl8/obHA6hjNflkUrX7x5s0ygRZTEYhAlGGdhz8FbeEIziWm+tOq6xQvQ== X-Received: by 2002:a62:8910:: with SMTP id v16-v6mr3401359pfd.106.1539297261732; Thu, 11 Oct 2018 15:34:21 -0700 (PDT) Received: from tomato.housegordon.com (moose.housegordon.com. [184.68.105.38]) by smtp.googlemail.com with ESMTPSA id o12-v6sm12147564pgv.7.2018.10.11.15.34.19 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Oct 2018 15:34:20 -0700 (PDT) To: control@debbugs.gnu.org From: Assaf Gordon Message-ID: <9feaab7a-6767-723b-785a-b9e39fa507c7@gmail.com> Date: Thu, 11 Oct 2018 16:34:19 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Score: 2.0 (++) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: close 12656 tags 8824 moreinfo close 8824 tags 8767 + moreinfo close 8767 [...] Content analysis details: (2.0 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [209.85.215.182 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (assafgordon[at]gmail.com) 0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.215.182 listed in wl.mailspike.net] 1.8 MISSING_SUBJECT Missing Subject: header 0.2 NO_SUBJECT Extra score for no subject 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.0 (+) close 12656 tags 8824 moreinfo close 8824 tags 8767 + moreinfo close 8767 tags 8736 wontfix close 8736 tags 8700 wontfix close 8700 close 8616 tags 9101 fixed close 9101 retitle 9129 printf: RFE: reject field width larger than INT_MAX tags 9129 notabug close 9129 tags 9140 fixed close 9140 tags 9207 wontfix close 9207 From unknown Wed Jun 18 00:23:55 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Fri, 09 Nov 2018 12:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator