-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Builtin sleep
and the tmxdate()
function
#990
Comments
For the record here are the problems identified by oclint. There are lots of problems with the other AST time subsystem code.
|
If we eliminate the use of
|
I asked earlier:
This is a good example where the principal of orthogonality should have been applied. Even if sleeping till the same wall clock time at some future date is useful it should have been implemented via a composition pattern. For example |
Grumble! The builtin
The first one produces the number of seconds represented by the argument as evaluated by The second invocation calculates seconds since the epoch represented by the date string as interpreted by |
The ksh93v- work in progress code had a builtin |
While converting the code to use
Yet the ksh(1) man page says the argument is a simple floating point literal representing the number of seconds to sleep. So this discrepancy between the official man page and the doc string shown by |
The question is whether we can change the |
Gah! I don't know how I missed the fact the ksh(1) man page says:
However, it is still worth noting that description differs significantly from the output of |
Outside of the AST time subsystem there are relatively few uses of that code by ksh. One such use is the
tmxdate()
function. It is used in one place in src/cmd/ksh93/bltins/print.c and three places in src/cmd/ksh93/bltins/sleep.c. I'd like to remove those uses because tmxdate.c has quite a few problems as identified by oclint and Coverity Scan and I'd rather remove the dependency than fix the problems. This issue focuses on the uses by the builtinsleep
command.The first thing to note is that the man page and
sleep --help
don't define the valid durations. The former says "seconds" and the latter "duration" but without defining either term. As of right now, in the US/Pacific timezone, the following invocations result in the indicated sleep duration in seconds:sleep 7d
=> 604800sleep '7 day'
=> 608400sleep '1 week'
=> 608400Whoa! Shouldn't those all have the same sleep duration? The first one is obviously correct since
7 * 24 * 60 * 60 == 604800
. The other two have an extra hour. Why? Because those forms causetmxdate()
to be called which calculates the delta between two wall clock times. Between now and 7 days in the future my timezone will switch from daylight savings time (DST) to standard time and wall clock time falls back one hour thus requiring adding an extra hour to achieve the same wall clock time. I'll bet 99.999% of people will be surprised at the difference between those formulations. Most people would expect them to produce the same sleep duration.Note 1: A bare number optionally followed by the suffix
d
,h
,m
ors
is handled directly by theb_sleep()
function. This is equivalent to the behavior of the GNUsleep
command. Anything else is handed off totmxdate()
. Apparently the people who implemented this thought it would be cool if you could typesleep '1 week 2 day 3 hour 4 second'
. Quick, tell me whatsleep 'Nov 2'
does if it is currently any time in Nov 1? Answer: it calculates the duration to reach the current wall clock time on that date taking into account DST shifts. This is plain nuts.Note 2: Neither bash nor zsh implement
sleep
as a builtin and thus you're at the mercy of whatever the platform external command implements.P.S., I find it ironic how people have argued for the builtin
echo
behavior depending on whether the ATT or UCB universe was in effect or the contents ofPATH
. Yet here we have an example of a command that deliberately does not attempt to conform to the implementation of the command provided by the platform.The text was updated successfully, but these errors were encountered: