[PATCH] Shutdown cooloff feature
Xin LI
delphij at delphij.net
Mon Sep 28 23:07:38 UTC 2009
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
I'm not sure if anyone would find this useful:
- If a shutdown is initiated from a tty -and-
- It's not a restart -and-
- The time parameter is set to "now"
Then, the shutdown(8) program would give something like this:
Shutting down <hostname> NOW, press ^C within 5 seconds to cancel...
So the user would get a chance to terminate it before it's too late.
Cheers,
- --
Xin LI <delphij at delphij.net> http://www.delphij.net/
FreeBSD - The Power to Serve!
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.12 (FreeBSD)
iEYEARECAAYFAkrBQa8ACgkQi+vbBBjt66D5iQCgmISna2P4CbX9qob5SuetGuoy
nUUAn0BtA/67Lyy8+91JppokUE57c/Ew
=Aytq
-----END PGP SIGNATURE-----
-------------- next part --------------
Index: shutdown.c
===================================================================
--- shutdown.c (revision 197578)
+++ shutdown.c (working copy)
@@ -103,6 +103,7 @@ static void timewarn(int);
static void usage(const char *);
extern const char **environ;
+static char hostname[MAXHOSTNAMELEN];
int
main(int argc, char **argv)
@@ -159,6 +160,7 @@ main(int argc, char **argv)
if (nosync != NULL && !oflag)
usage("-n requires -o");
+ gethostname(hostname, sizeof(hostname));
getoffset(*argv++);
if (*argv) {
@@ -193,8 +195,22 @@ main(int argc, char **argv)
if (offset)
(void)printf("Shutdown at %.24s.\n", ctime(&shuttime));
- else
+ else {
+ /*
+ * Safe belt when the operation is going to happen
+ * immediately from a tty.
+ */
+ if (doreboot != 1) {
+ if (isatty(STDIN_FILENO)) {
+ printf("Shutting down %s NOW, press ^C within "
+ "5 seconds to cancel...", hostname);
+ fflush(stdout);
+ sleep(5);
+ printf(" going ahead!\n");
+ }
+ }
(void)printf("Shutdown NOW!\n");
+ }
if (!(whom = getlogin()))
whom = (pw = getpwuid(getuid())) ? pw->pw_name : "???";
@@ -271,14 +287,9 @@ static const char *restricted_environ[] = {
static void
timewarn(int timeleft)
{
- static int first;
- static char hostname[MAXHOSTNAMELEN + 1];
FILE *pf;
char wcmd[MAXPATHLEN + 4];
- if (!first++)
- (void)gethostname(hostname, sizeof(hostname));
-
/* undoc -n option to wall suppresses normal wall banner */
(void)snprintf(wcmd, sizeof(wcmd), "%s -n", _PATH_WALL);
environ = restricted_environ;
More information about the freebsd-current
mailing list