- char *ts;
-
- fprintf(term, "\007\007*** System shutdown message from %s ***\n", shutter);
- ts = ctime(&sdt);
- if (sdt - nowtime > 10 MINUTES)
- fprintf(term, "System going down at %5.5s\n", ts+11);
- else if ( sdt - nowtime > 60 SECONDS ) {
- fprintf(term, "System going down in %d minute%s\n",
- (sdt-nowtime+30)/60, (sdt-nowtime+30)/60 != 1 ? "s" : "");
- } else if ( sdt - nowtime > 0 ) {
- fprintf(term, "System going down in %d second%s\n",
- sdt-nowtime, sdt-nowtime != 1 ? "s" : "");
- } else
- fprintf(term, "System going down IMMEDIATELY\n");
+ static int first;
+ static char hostname[MAXHOSTNAMELEN + 1];
+ char wcmd[MAXPATHLEN + 4];
+ FILE *pf;
+ char *ctime();
+ void timeout();
+
+ if (!first++)
+ (void)gethostname(hostname, sizeof(hostname));
+
+ /* undoc -n option to wall suppresses normal wall banner */
+ (void)sprintf(wcmd, "%s -n", _PATH_WALL);
+ if (!(pf = popen(wcmd, "w"))) {
+ syslog(LOG_ERR, "shutdown: can't find %s: %m", _PATH_WALL);
+ return;
+ }
+
+ (void)fprintf(pf,
+ "\007*** %sSystem shutdown message from %s@%s ***\007\n",
+ tp->timeleft ? "": "FINAL ", whom, hostname);
+
+ if (tp->timeleft > 10*60)
+ (void)fprintf(pf, "System going down at %5.5s\n\n",
+ ctime(&shuttime) + 11);
+ else if (tp->timeleft > 59)
+ (void)fprintf(pf, "System going down in %d minute%s\n\n",
+ tp->timeleft / 60, (tp->timeleft > 60) ? "s" : "");
+ else if (tp->timeleft)
+ (void)fprintf(pf, "System going down in 30 seconds\n\n");
+ else
+ (void)fprintf(pf, "System going down IMMEDIATELY\n\n");
+
+ if (mbuflen)
+ (void)fwrite(mbuf, sizeof(*mbuf), mbuflen, pf);
+
+ /*
+ * play some games, just in case wall doesn't come back
+ * probably unecessary, given that wall is careful.
+ */
+ if (!setjmp(alarmbuf)) {
+ (void)signal(SIGALRM, timeout);
+ (void)alarm((u_int)30);
+ (void)pclose(pf);
+ (void)alarm((u_int)0);
+ (void)signal(SIGALRM, SIG_DFL);
+ }