summaryrefslogtreecommitdiff
path: root/sbin/shutdown/shutdown.c
diff options
context:
space:
mode:
Diffstat (limited to 'sbin/shutdown/shutdown.c')
-rw-r--r--sbin/shutdown/shutdown.c44
1 files changed, 24 insertions, 20 deletions
diff --git a/sbin/shutdown/shutdown.c b/sbin/shutdown/shutdown.c
index f85f10318f8..a8c8b16d806 100644
--- a/sbin/shutdown/shutdown.c
+++ b/sbin/shutdown/shutdown.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: shutdown.c,v 1.44 2015/11/16 18:35:31 deraadt Exp $ */
+/* $OpenBSD: shutdown.c,v 1.45 2016/09/01 09:50:38 deraadt Exp $ */
/* $NetBSD: shutdown.c,v 1.9 1995/03/18 15:01:09 cgd Exp $ */
/*
@@ -198,9 +198,14 @@ main(int argc, char *argv[])
}
mbuflen = strlen(mbuf);
- if (offset)
- (void)printf("Shutdown at %.24s.\n", ctime(&shuttime));
- else
+ if (offset) {
+ char *ct = ctime(&shuttime);
+
+ if (ct)
+ printf("Shutdown at %.24s.\n", ct);
+ else
+ printf("Shutdown soon.\n");
+ } else
(void)printf("Shutdown NOW!\n");
if (!(whom = getlogin()))
@@ -297,10 +302,12 @@ timewarn(int timeleft)
"\007*** %sSystem shutdown message from %s@%s ***\007\n",
timeleft ? "": "FINAL ", whom, hostname);
- if (timeleft > 10*60)
- (void)fprintf(pf, "System going down at %5.5s\n\n",
- ctime(&shuttime) + 11);
- else if (timeleft > 59)
+ if (timeleft > 10*60) {
+ struct tm *tm = localtime(&shuttime);
+
+ fprintf(pf, "System going down at %d:%02d\n\n",
+ tm->tm_hour, tm->tm_min);
+ } else if (timeleft > 59)
(void)fprintf(pf, "System going down in %d minute%s\n\n",
timeleft / 60, (timeleft > 60) ? "s" : "");
else if (timeleft)
@@ -514,7 +521,6 @@ getoffset(char *timearg)
}
}
-#define FSMSG "fastboot file for fsck\n"
void
doitfast(void)
{
@@ -522,31 +528,29 @@ doitfast(void)
if ((fastfd = open(_PATH_FASTBOOT, O_WRONLY|O_CREAT|O_TRUNC,
0664)) >= 0) {
- (void)write(fastfd, FSMSG, sizeof(FSMSG) - 1);
- (void)close(fastfd);
+ dprintf(fastfd, "fastboot file for fsck\n");
+ close(fastfd);
}
}
-#define NOMSG "\n\nNO LOGINS: System going down at "
void
nolog(void)
{
int logfd;
- char *ct;
+ struct tm *tm;
(void)unlink(_PATH_NOLOGIN); /* in case linked to another file */
(void)signal(SIGINT, finish);
(void)signal(SIGHUP, finish);
(void)signal(SIGQUIT, finish);
(void)signal(SIGTERM, finish);
- if ((logfd = open(_PATH_NOLOGIN, O_WRONLY|O_CREAT|O_TRUNC,
+ tm = localtime(&shuttime);
+ if (tm && (logfd = open(_PATH_NOLOGIN, O_WRONLY|O_CREAT|O_TRUNC,
0664)) >= 0) {
- (void)write(logfd, NOMSG, sizeof(NOMSG) - 1);
- ct = ctime(&shuttime);
- (void)write(logfd, ct + 11, 5);
- (void)write(logfd, "\n\n", 2);
- (void)write(logfd, mbuf, strlen(mbuf));
- (void)close(logfd);
+ dprintf(logfd,
+ "\n\nNO LOGINS: System going down at %d:%02d\n\n",
+ tm->tm_hour, tm->tm_min);
+ close(logfd);
}
}