shutdown: Assume absolute time is in the future
The original bug describes it best: When an absolute time is specified to shutdown, the program's behavior depends on whether that time has passed during the current calendar day. POLA would suggest that for shutdown, whose time argument is always supposed to be in the future, absolute times specified without a specific date should refer to the next occurrence of that time, rather than erroring out if that time has already passed during the current day. PR: 32411 Submitted by: wollman@khavrinen.lcs.mit.edu Submitted on: 2001-11-30 20:30:01 UTC Reviewed by: asmodai (at time of bug submission)
This commit is contained in:
parent
af8bf1e796
commit
1df3a19fc9
@ -28,7 +28,7 @@
|
||||
.\" @(#)shutdown.8 8.2 (Berkeley) 4/27/95
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd October 23, 2017
|
||||
.Dd January 1, 2018
|
||||
.Dt SHUTDOWN 8
|
||||
.Os
|
||||
.Sh NAME
|
||||
@ -138,6 +138,14 @@ suffix:
|
||||
.Dq Li min .
|
||||
.Dq Li h ,
|
||||
.Dq Li hour .
|
||||
.Pp
|
||||
If an absolute time is specified, but not a date,
|
||||
and that time today has already passed,
|
||||
.Nm
|
||||
will assume that the same time tomorrow was meant.
|
||||
(If a complete date is specified which has already passed,
|
||||
.Nm
|
||||
will print an error and exit without shutting the system down.)
|
||||
.It Ar warning-message
|
||||
Any other arguments comprise the warning message that is broadcast
|
||||
to users currently logged into the system.
|
||||
|
@ -431,7 +431,7 @@ getoffset(char *timearg)
|
||||
struct tm *lt;
|
||||
char *p;
|
||||
time_t now;
|
||||
int this_year;
|
||||
int this_year, maybe_today;
|
||||
char *timeunit;
|
||||
|
||||
(void)time(&now);
|
||||
@ -503,6 +503,7 @@ getoffset(char *timearg)
|
||||
badtime();
|
||||
/* FALLTHROUGH */
|
||||
case 6:
|
||||
maybe_today = 0;
|
||||
lt->tm_mday = ATOI2(timearg);
|
||||
if (lt->tm_mday < 1 || lt->tm_mday > 31)
|
||||
badtime();
|
||||
@ -517,8 +518,23 @@ getoffset(char *timearg)
|
||||
lt->tm_sec = 0;
|
||||
if ((shuttime = mktime(lt)) == -1)
|
||||
badtime();
|
||||
if ((offset = shuttime - now) < 0)
|
||||
|
||||
if ((offset = shuttime - now) < 0) {
|
||||
if (!maybe_today)
|
||||
errx(1, "that time is already past.");
|
||||
|
||||
/*
|
||||
* If the user only gave a time, assume that
|
||||
* any time earlier than the current time
|
||||
* was intended to be that time tomorrow.
|
||||
*/
|
||||
lt->tm_mday++;
|
||||
if ((shuttime = mktime(lt)) == -1)
|
||||
badtime();
|
||||
if ((offset = shuttime - now) < 0) {
|
||||
errx(1, "tomorrow is before today?");
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
badtime();
|
||||
|
Loading…
Reference in New Issue
Block a user