aboutsummaryrefslogtreecommitdiff
path: root/sbin/shutdown
diff options
context:
space:
mode:
authorEitan Adler <eadler@FreeBSD.org>2018-01-01 22:33:57 +0000
committerEitan Adler <eadler@FreeBSD.org>2018-01-01 22:33:57 +0000
commitcb1101afd7dcab548680a142d4a4b375a5a39b08 (patch)
tree96b2a313a21c7dacffd93f6b8b07346a7d6bf4d2 /sbin/shutdown
parentb0125116ca90c301f31ae96e32504f7586f07730 (diff)
downloadsrc-cb1101afd7dcab548680a142d4a4b375a5a39b08.tar.gz
src-cb1101afd7dcab548680a142d4a4b375a5a39b08.zip
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)
Notes
Notes: svn path=/head/; revision=327476
Diffstat (limited to 'sbin/shutdown')
-rw-r--r--sbin/shutdown/shutdown.810
-rw-r--r--sbin/shutdown/shutdown.c22
2 files changed, 28 insertions, 4 deletions
diff --git a/sbin/shutdown/shutdown.8 b/sbin/shutdown/shutdown.8
index b388aaf92fe9..557a942bb406 100644
--- a/sbin/shutdown/shutdown.8
+++ b/sbin/shutdown/shutdown.8
@@ -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.
diff --git a/sbin/shutdown/shutdown.c b/sbin/shutdown/shutdown.c
index c8e77883f6be..622b99fa2fa3 100644
--- a/sbin/shutdown/shutdown.c
+++ b/sbin/shutdown/shutdown.c
@@ -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)
- errx(1, "that time is already past.");
+
+ 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();