aboutsummaryrefslogtreecommitdiff
path: root/sbin/shutdown
diff options
context:
space:
mode:
authorGleb Kurtsou <gleb@FreeBSD.org>2014-12-16 08:29:02 +0000
committerGleb Kurtsou <gleb@FreeBSD.org>2014-12-16 08:29:02 +0000
commitc7d73a4d23fe6884a49b0a4eb8734aa8a153bef4 (patch)
tree4c9c33424f43c0ded83197e7bb5cae28b6979c4c /sbin/shutdown
parent09eced2549e92b5fbc11d825804aa2e16ce72059 (diff)
downloadsrc-c7d73a4d23fe6884a49b0a4eb8734aa8a153bef4.tar.gz
src-c7d73a4d23fe6884a49b0a4eb8734aa8a153bef4.zip
sbin/shutdown: Support time units as in 'shutdown -r +5sec'
Units supported: s, sec, m, min, h, hour. Differential Revision: https://reviews.freebsd.org/D1272
Notes
Notes: svn path=/head/; revision=275818
Diffstat (limited to 'sbin/shutdown')
-rw-r--r--sbin/shutdown/shutdown.811
-rw-r--r--sbin/shutdown/shutdown.c24
2 files changed, 32 insertions, 3 deletions
diff --git a/sbin/shutdown/shutdown.8 b/sbin/shutdown/shutdown.8
index 871efbed8b06..4145ba5b64df 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 March 19, 2013
+.Dd December 15, 2014
.Dt SHUTDOWN 8
.Os
.Sh NAME
@@ -118,6 +118,15 @@ to the current system values.
The first form brings the system down in
.Ar number
minutes and the second at the absolute time specified.
+.Ar +number
+may be specified in units other than minutes by appending the corresponding
+suffix:
+.Dq Li s ,
+.Dq Li sec ,
+.Dq Li m ,
+.Dq Li min .
+.Dq Li h ,
+.Dq Li hour .
.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 f53b3d8c98f9..b04e0bd87de6 100644
--- a/sbin/shutdown/shutdown.c
+++ b/sbin/shutdown/shutdown.c
@@ -48,6 +48,7 @@ __FBSDID("$FreeBSD$");
#include <ctype.h>
#include <err.h>
+#include <errno.h>
#include <fcntl.h>
#include <paths.h>
#include <pwd.h>
@@ -322,7 +323,8 @@ timewarn(int timeleft)
(void)fprintf(pf, "System going down in %d minute%s\n\n",
timeleft / 60, (timeleft > 60) ? "s" : "");
else if (timeleft)
- (void)fprintf(pf, "System going down in 30 seconds\n\n");
+ (void)fprintf(pf, "System going down in %s30 seconds\n\n",
+ (offset > 0 && offset < 30 ? "less than " : ""));
else
(void)fprintf(pf, "System going down IMMEDIATELY\n\n");
@@ -415,6 +417,7 @@ getoffset(char *timearg)
char *p;
time_t now;
int this_year;
+ char *timeunit;
(void)time(&now);
@@ -427,8 +430,25 @@ getoffset(char *timearg)
if (*timearg == '+') { /* +minutes */
if (!isdigit(*++timearg))
badtime();
- if ((offset = atoi(timearg) * 60) < 0)
+ errno = 0;
+ offset = strtol(timearg, &timeunit, 10);
+ if (offset < 0 || offset == LONG_MAX || errno != 0)
badtime();
+ if (timeunit[0] == '\0' || strcasecmp(timeunit, "m") == 0 ||
+ strcasecmp(timeunit, "min") == 0 ||
+ strcasecmp(timeunit, "mins") == 0) {
+ offset *= 60;
+ } else if (strcasecmp(timeunit, "h") == 0 ||
+ strcasecmp(timeunit, "hour") == 0 ||
+ strcasecmp(timeunit, "hours") == 0) {
+ offset *= 60 * 60;
+ } else if (strcasecmp(timeunit, "s") == 0 ||
+ strcasecmp(timeunit, "sec") == 0 ||
+ strcasecmp(timeunit, "secs") == 0) {
+ offset *= 1;
+ } else {
+ badtime();
+ }
shuttime = now + offset;
return;
}