Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 13 Nov 2002 10:07:22 -0800 (PST)
From:      Nate Lawson <nate@root.org>
To:        Sheldon Hearn <sheldonh@starjuice.net>
Cc:        current@freebsd.org
Subject:   Re: sleep(1) behavior
Message-ID:  <Pine.BSF.4.21.0211131003010.39871-200000@root.org>
In-Reply-To: <20021113080425.GO1278@starjuice.net>

next in thread | previous in thread | raw e-mail | index | archive | help
  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.
  Send mail to mime@docserver.cac.washington.edu for more info.

--0-2102765526-1037210842=:39871
Content-Type: TEXT/PLAIN; charset=US-ASCII

On Wed, 13 Nov 2002, Sheldon Hearn wrote:
> On (2002/11/12 16:37), Nate Lawson wrote:
> 
> > I've found an interesting contradiction and was wondering what behavior
> > sleep should have.  It checks for a command line flag with getopt(3) and
> > exits with usage() if it finds one.  However, it then checks for a '-' or
> > '+' sign.  If negative, it behaves like "sleep 0" and exits
> > immediately.  This case can almost never be triggered since the
> > getopt(3) will catch the minus sign, even if a digit follows it.
> > 
> > Current behavior:
> > sleep 0 = exits immediately
> > sleep -1 = exits with usage()
> > sleep -f = exits with usage()
> > sleep "   -1" = exits immediately and is the only way I know to trigger
> > the negative case.
> > 
> > What is the standard, desired behavior?
> 
> IEEE Std 1003.2-1992 says:
> 
> 	time	A nonnegative decimal integer specifying the number of
> 		seconds for which to suspend execution.
> 
> I think it's pretty clear that negative time arguments to sleep(1) are
> not portable.

Thanks, that's what I was expecting.  The attached patch provides the
following behavior:

sleep 0 = exit 0 immediately
sleep [ \t]*1AAAA = sleep 1 second
sleep [ \t]*\.2zzz = sleep .2 seconds
sleep [ \t]*-.* = usage()

Please let me know if there are any problems with this patch.

-Nate

--0-2102765526-1037210842=:39871
Content-Type: TEXT/PLAIN; charset=US-ASCII; name="sleep.diff"
Content-Transfer-Encoding: BASE64
Content-ID: <Pine.BSF.4.21.0211131007220.39871@root.org>
Content-Description: 
Content-Disposition: attachment; fil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90IGlz
ID49IElOVF9NQVguDQogCQkJICovDQogCQkJbCA9IElOVF9NQVg7DQorCQkJ
YnJlYWs7DQogCQl9DQotCX0gZWxzZQ0KLQkJbCA9IDA7DQorCQkrK3A7DQor
CX0NCiAJdGltZV90b19zbGVlcC50dl9zZWMgPSAodGltZV90KWw7DQogDQog
CS8qIENhbGN1bGF0ZSBuYW5vc2Vjb25kcy4gKi8NCkBAIC0xMTksNyArMTEx
LDcgQEANCiAJCX0gd2hpbGUgKGwgLz0gMTApOw0KIAl9DQogDQotCWlmICgh
bmVnICYmICh0aW1lX3RvX3NsZWVwLnR2X3NlYyA+IDAgfHwgdGltZV90b19z
bGVlcC50dl9uc2VjID4gMCkpDQorCWlmICh0aW1lX3RvX3NsZWVwLnR2X3Nl
YyA+IDAgfHwgdGltZV90b19zbGVlcC50dl9uc2VjID4gMCkNCiAJCSh2b2lk
KW5hbm9zbGVlcCgmdGltZV90b19zbGVlcCwgKHN0cnVjdCB0aW1lc3BlYyAq
KU5VTEwpOw0KIA0KIAlleGl0KDApOw0KQEAgLTEyOCw3ICsxMjAsOCBAQA0K
IHZvaWQNCiB1c2FnZSh2b2lkKQ0KIHsNCisJY29uc3QgY2hhciAqbXNnID0g
InVzYWdlOiBzbGVlcCBzZWNvbmRzXG4iOw0KIA0KLQkodm9pZClmcHJpbnRm
KHN0ZGVyciwgInVzYWdlOiBzbGVlcCBzZWNvbmRzXG4iKTsNCisJd3JpdGUo
U1RET1VUX0ZJTEVOTywgbXNnLCBzdHJsZW4obXNnKSk7DQogCWV4aXQoMSk7
DQogfQ0K
--0-2102765526-1037210842=:39871--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0211131003010.39871-200000>