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:
eadler 2018-01-01 22:33:57 +00:00
parent af8bf1e796
commit 1df3a19fc9
2 changed files with 28 additions and 4 deletions

View File

@ -28,7 +28,7 @@
.\" @(#)shutdown.8 8.2 (Berkeley) 4/27/95 .\" @(#)shutdown.8 8.2 (Berkeley) 4/27/95
.\" $FreeBSD$ .\" $FreeBSD$
.\" .\"
.Dd October 23, 2017 .Dd January 1, 2018
.Dt SHUTDOWN 8 .Dt SHUTDOWN 8
.Os .Os
.Sh NAME .Sh NAME
@ -138,6 +138,14 @@ suffix:
.Dq Li min . .Dq Li min .
.Dq Li h , .Dq Li h ,
.Dq Li hour . .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 .It Ar warning-message
Any other arguments comprise the warning message that is broadcast Any other arguments comprise the warning message that is broadcast
to users currently logged into the system. to users currently logged into the system.

View File

@ -431,7 +431,7 @@ getoffset(char *timearg)
struct tm *lt; struct tm *lt;
char *p; char *p;
time_t now; time_t now;
int this_year; int this_year, maybe_today;
char *timeunit; char *timeunit;
(void)time(&now); (void)time(&now);
@ -503,6 +503,7 @@ getoffset(char *timearg)
badtime(); badtime();
/* FALLTHROUGH */ /* FALLTHROUGH */
case 6: case 6:
maybe_today = 0;
lt->tm_mday = ATOI2(timearg); lt->tm_mday = ATOI2(timearg);
if (lt->tm_mday < 1 || lt->tm_mday > 31) if (lt->tm_mday < 1 || lt->tm_mday > 31)
badtime(); badtime();
@ -517,8 +518,23 @@ getoffset(char *timearg)
lt->tm_sec = 0; lt->tm_sec = 0;
if ((shuttime = mktime(lt)) == -1) if ((shuttime = mktime(lt)) == -1)
badtime(); badtime();
if ((offset = shuttime - now) < 0)
if ((offset = shuttime - now) < 0) {
if (!maybe_today)
errx(1, "that time is already past."); 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; break;
default: default:
badtime(); badtime();