svn commit: r327476 - head/sbin/shutdown
Eitan Adler
eadler at FreeBSD.org
Mon Jan 1 22:33:59 UTC 2018
Author: eadler
Date: Mon Jan 1 22:33:57 2018
New Revision: 327476
URL: https://svnweb.freebsd.org/changeset/base/327476
Log:
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 at khavrinen.lcs.mit.edu
Submitted on: 2001-11-30 20:30:01 UTC
Reviewed by: asmodai (at time of bug submission)
Modified:
head/sbin/shutdown/shutdown.8
head/sbin/shutdown/shutdown.c
Modified: head/sbin/shutdown/shutdown.8
==============================================================================
--- head/sbin/shutdown/shutdown.8 Mon Jan 1 22:31:52 2018 (r327475)
+++ head/sbin/shutdown/shutdown.8 Mon Jan 1 22:33:57 2018 (r327476)
@@ -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.
Modified: head/sbin/shutdown/shutdown.c
==============================================================================
--- head/sbin/shutdown/shutdown.c Mon Jan 1 22:31:52 2018 (r327475)
+++ head/sbin/shutdown/shutdown.c Mon Jan 1 22:33:57 2018 (r327476)
@@ -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();
More information about the svn-src-all
mailing list