I've made a small modification to shutdown to allow for an extra time
format specifier. It allows specifying hours and minutes away from 'now' in
the form +hh:mm. I also added the extra syntax to the relevant manpage.
When checking this new relative time, hh is limited to 99999 hours, which
corresponds to a little over 11 years.

This syntax allows more easily specifying shutdown times several days in
advance, like a preplanned reboot at 1AM on Sunday set up on the previous
Friday.

I've attached a patch implementing the changes against the 2.95 release
branch.

Thanks,
Will
diff --git man/shutdown.8 man/shutdown.8
index 5d012ec..871808f 100644
--- man/shutdown.8
+++ man/shutdown.8
@@ -142,7 +142,9 @@ The \fItime\fP argument can have different formats.  First, it can be an
 absolute time in the format \fIhh:mm\fP, in which \fIhh\fP is the hour
 (1 or 2 digits) and \fImm\fP is the minute of the hour (in two digits).
 Second, it can be in the format \fB+\fP\fIm\fP, in which \fIm\fP is the
-number of minutes to wait.  The word \fBnow\fP is an alias for \fB+0\fP.
+number of minutes to wait.  Third, it can be in the format \fB+\fP\fIhh:mm\fP,
+in which \fIhh:mm\fP is the number of hours and minutes to wait.
+The word \fBnow\fP is an alias for \fB+0\fP.
 .PP
 If shutdown is called with a delay, it will create the advisory file
 .I /etc/nologin
diff --git src/shutdown.c src/shutdown.c
index b744a2c..c49795f 100644
--- src/shutdown.c
+++ src/shutdown.c
@@ -788,13 +788,21 @@ int main(int argc, char **argv)
 		wt = atoi(when);
 		if (wt == 0 && when[0] != '0') usage();
 	} else {
-		/* Time in hh:mm format. */
 		if (sscanf(when, "%d:%2d", &hours, &mins) != 2) usage();
-		if (hours > 23 || mins > 59) usage();
-		time(&t);
-		lt = localtime(&t);
-		wt = (60*hours + mins) - (60*lt->tm_hour + lt->tm_min);
-		if (wt < 0) wt += 1440;
+		/* Time in hh:mm format. */
+		if (when[0] == '+') {
+			/* Hours and minutes from now */
+			if (hours > 99999 || mins > 59) usage();
+			wt = (60*hours + mins);
+			if (wt < 0) usage();
+		} else {
+			/* Time of day */
+			if (hours > 23 || mins > 59) usage();
+			time(&t);
+			lt = localtime(&t);
+			wt = (60*hours + mins) - (60*lt->tm_hour + lt->tm_min);
+			if (wt < 0) wt += 1440;
+		}
 	}
 	/* Shutdown NOW if time == 0 */
 	if (wt == 0) issue_shutdown(halttype);

Reply via email to