Bug 37442 - [patch] sleep(1) to support time multipliers
Summary: [patch] sleep(1) to support time multipliers
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 4.5-RELEASE
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-04-25 06:50 UTC by edwin
Modified: 2018-11-19 17:44 UTC (History)
1 user (show)

See Also:


Attachments
file.diff (2.64 KB, patch)
2002-04-25 06:50 UTC, edwin
no flags Details | Diff
file.diff (3.37 KB, patch)
2002-04-25 06:50 UTC, edwin
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description edwin 2002-04-25 06:50:00 UTC
I want to run my nightly downloads run in an xterm, so I can check
if they've run properly. Often I have to delay them for hours and
am now pretty good skilled in the multiplication table of 1800, but
now and then things are one hour off. To solve this, I've modified
sleep(1) to support multipliers: sleep 1h will sleep for one hour,
sleep 2.5m will sleep for two and a half minute.

Fix: Two patches, one against the 4.5 code, one against the -current of today.

This is patch against the 4.5 code:

This is the patch against -current
Comment 1 Peter Pentchev 2002-04-25 12:07:17 UTC
On Thu, Apr 25, 2002 at 03:49:24PM +1000, Edwin Groothuis wrote:
> 
> >Number:         37442
> >Category:       bin
> >Synopsis:       [PATCH] sleep.c to support time multipliers
> >Originator:     Edwin Groothuis
> >Description:
> 
> I want to run my nightly downloads run in an xterm, so I can check
> if they've run properly. Often I have to delay them for hours and
> am now pretty good skilled in the multiplication table of 1800, but
> now and then things are one hour off. To solve this, I've modified
> sleep(1) to support multipliers: sleep 1h will sleep for one hour,
> sleep 2.5m will sleep for two and a half minute.

Mmm... not to knock your patch down, but.. you do realize that
this can be done with expr(1) and/or shell built-in arithmetic
functions (ksh and bash have $((5 * 1800)), don't know about
other shells), right?

G'luck,
Peter

-- 
Peter Pentchev	roam@ringlet.net	roam@FreeBSD.org
PGP key:	http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint	FDBA FD79 C26F 3C51 C95E  DF9E ED18 B68D 1619 4553
No language can express every thought unambiguously, least of all this one.
Comment 2 edwin 2002-04-25 12:46:13 UTC
On Thu, Apr 25, 2002 at 02:07:17PM +0300, Peter Pentchev wrote:
> On Thu, Apr 25, 2002 at 03:49:24PM +1000, Edwin Groothuis wrote:
> > 
> > >Number:         37442
> > >Category:       bin
> > >Synopsis:       [PATCH] sleep.c to support time multipliers
> > >Originator:     Edwin Groothuis
> > >Description:
> > 
> > I want to run my nightly downloads run in an xterm, so I can check
> > if they've run properly. Often I have to delay them for hours and
> > am now pretty good skilled in the multiplication table of 1800, but
> > now and then things are one hour off. To solve this, I've modified
> > sleep(1) to support multipliers: sleep 1h will sleep for one hour,
> > sleep 2.5m will sleep for two and a half minute.
> 
> Mmm... not to knock your patch down, but.. you do realize that
> this can be done with expr(1) and/or shell built-in arithmetic
> functions (ksh and bash have $((5 * 1800)), don't know about
> other shells), right?

Yes I know, that's what I did in the beginning. But I also know
that its easier to write (and make sure it's correct) '2.5h' than
'9000' (or echo ((5 * 1800)), which puts you in the situation that
you're thinking in 5 half hours instead of 2.5 hours (which is the
same in timespan but not how an average person thinks)).

Edwin

-- 
Edwin Groothuis      |           Personal website: http://www.MavEtJu.org
edwin@mavetju.org    |        Interested in MUDs? Visit Fatal Dimensions:
bash$ :(){ :|:&};:   |                    http://www.FatalDimensions.org/
Comment 3 Andrew Stevenson 2002-06-12 14:58:56 UTC
 > Mmm... not to knock your patch down, but.. you do realize > that this 
can be done with expr(1) and/or shell built-in
 > arithmetic functions (ksh and bash have $((5 * 1800)),
 > don't know about other shells), right?

That shouldn't be enough to stop the patch though (IMHO anyway). After 
all df supports -h and I'm sure with a bit of awk and/or sh you could 
get similar behavior without this rather nice switch.

It just makes sleep that bit more convenient without breaking any 
historical behavior.

Andrew
Comment 4 ru freebsd_committer 2002-08-12 18:38:29 UTC
On Mon, Aug 12, 2002 at 09:04:20PM +1000, Edwin Groothuis wrote:
> Greetings,
> 
> "Why me" is what you ask yourself now probably. Mostly because you
> are the one who made the last changes to sleep.c... nearly three
> years ago :-/
> 
> Could you have please a look at PR bin/37442?
>     (http://www.freebsd.org/cgi/query-pr.cgi?pr=bin/37442)
> 
> The PR is about a small change in sleep which allows the usage of
> multipliers: So that 10m is 10 minutes, 3h is three hours and 4d
> is four days.
> 
> It doesn't break any current script-usages, it only adds extra
> flexibility for people who want to use it.
> 
POSIX.1-2001 clearly documents the sleep(1)'s SYNOPSIS:

: SYNOPSIS
:             sleep time

And requires that:

: DESCRIPTION
:             The sleep utility shall suspend execution for at least
:             the integral number of seconds specified by the time
:             operand.

We are currently "compatible" with POSIX in that we don't violate it
(POSIX allows the implementation to support more fine-grained sleep,
just does not require it to).

If we make the change you propose, we will become incompatible with
POSIX, as the latter requires ``sleep 10m'' to sleep for "at least
10 seconds".

I will close the PR if you don't mind, pending your confirmation.


Cheers,
-- 
Ruslan Ermilov		Sysadmin and DBA,
ru@sunbay.com		Sunbay Software AG,
ru@FreeBSD.org		FreeBSD committer,
+380.652.512.251	Simferopol, Ukraine

http://www.FreeBSD.org	The Power To Serve
http://www.oracle.com	Enabling The Information Age
Comment 5 ru freebsd_committer 2002-08-13 09:34:51 UTC
On Tue, Aug 13, 2002 at 01:52:41AM +0400, "."@babolo.ru wrote:
> Ruslan Ermilov writes:
> > The following reply was made to PR bin/37442; it has been noted by GNATS.
> > 
> > From: Ruslan Ermilov <ru@FreeBSD.org>
> > To: Edwin Groothuis <edwin@mavetju.org>
> > Cc: bug-followup@FreeBSD.org
> > Subject: Re: bin/37442 - patch for /bin/sleep
> > Date: Mon, 12 Aug 2002 20:38:29 +0300
> > 
> >  On Mon, Aug 12, 2002 at 09:04:20PM +1000, Edwin Groothuis wrote:
> >  > Greetings,
> >  > 
> >  > "Why me" is what you ask yourself now probably. Mostly because you
> >  > are the one who made the last changes to sleep.c... nearly three
> >  > years ago :-/
> >  > 
> >  > Could you have please a look at PR bin/37442?
> >  >     (http://www.freebsd.org/cgi/query-pr.cgi?pr=bin/37442)
> >  > 
> >  > The PR is about a small change in sleep which allows the usage of
> >  > multipliers: So that 10m is 10 minutes, 3h is three hours and 4d
> >  > is four days.
> >  > 
> >  > It doesn't break any current script-usages, it only adds extra
> >  > flexibility for people who want to use it.
> >  > 
> >  POSIX.1-2001 clearly documents the sleep(1)'s SYNOPSIS:
> >  
> >  : SYNOPSIS
> >  :             sleep time
> >  
> >  And requires that:
> >  
> >  : DESCRIPTION
> >  :             The sleep utility shall suspend execution for at least
> >  :             the integral number of seconds specified by the time
> >  :             operand.
> >  
> >  We are currently "compatible" with POSIX in that we don't violate it
> >  (POSIX allows the implementation to support more fine-grained sleep,
> >  just does not require it to).
> >  
> >  If we make the change you propose, we will become incompatible with
> >  POSIX, as the latter requires ``sleep 10m'' to sleep for "at least
> >  10 seconds".
> As far as I understand any value bigger then 10s is "at least 10 seconds".
> So 10m is "at least 10 seconds".
> :-)
> So, this IS compatible with POSIX
> 

Nope.  "at least the integral number of seconds" is not the same as "at
least the X seconds".  The point is to say that the implementation may
choose to support non-integral intervals, as we do.


Cheers,
-- 
Ruslan Ermilov		Sysadmin and DBA,
ru@sunbay.com		Sunbay Software AG,
ru@FreeBSD.org		FreeBSD committer,
+380.652.512.251	Simferopol, Ukraine

http://www.FreeBSD.org	The Power To Serve
http://www.oracle.com	Enabling The Information Age
Comment 6 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 08:01:15 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped
Comment 7 david 2018-11-19 17:44:31 UTC
I have recently needed to make use of a system that runs "16.04.1-Ubuntu"; I find that its sleep(1) appears to support this syntax.

I believe that there may be some benefit to making FreeBSD's sleep(1) capable of handling the same arguments that the Linux one does (and behave similarly).