From owner-freebsd-current@FreeBSD.ORG Mon Sep 28 23:07:38 2009 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 090441065670 for ; Mon, 28 Sep 2009 23:07:38 +0000 (UTC) (envelope-from delphij@delphij.net) Received: from tarsier.delphij.net (delphij-pt.tunnel.tserv2.fmt.ipv6.he.net [IPv6:2001:470:1f03:2c9::2]) by mx1.freebsd.org (Postfix) with ESMTP id 9F3E38FC1D for ; Mon, 28 Sep 2009 23:07:37 +0000 (UTC) Received: from tarsier.geekcn.org (tarsier.geekcn.org [211.166.10.233]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by tarsier.delphij.net (Postfix) with ESMTPS id A6BEB5C071 for ; Tue, 29 Sep 2009 07:07:36 +0800 (CST) Received: from localhost (tarsier.geekcn.org [211.166.10.233]) by tarsier.geekcn.org (Postfix) with ESMTP id 7CCA455CE26F; Tue, 29 Sep 2009 07:07:36 +0800 (CST) X-Virus-Scanned: amavisd-new at geekcn.org Received: from tarsier.geekcn.org ([211.166.10.233]) by localhost (mail.geekcn.org [211.166.10.233]) (amavisd-new, port 10024) with ESMTP id r4f7NHNbda2z; Tue, 29 Sep 2009 07:07:31 +0800 (CST) Received: from charlie.delphij.net (adsl-76-237-33-60.dsl.pltn13.sbcglobal.net [76.237.33.60]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by tarsier.geekcn.org (Postfix) with ESMTPSA id 0C72855CE268; Tue, 29 Sep 2009 07:07:30 +0800 (CST) DomainKey-Signature: a=rsa-sha1; s=default; d=delphij.net; c=nofws; q=dns; h=message-id:date:from:reply-to:organization:user-agent: mime-version:to:subject:x-enigmail-version:openpgp:content-type; b=fmnAja7hu1LTXOX/XdH/EfKLYi8bTGIHKEAMl5+pcrHRZZ/QzAh/HMmXkBJ3HhL0v Ui2tDmmbu9bfAuUB26Ngg== Message-ID: <4AC141B0.4090705@delphij.net> Date: Mon, 28 Sep 2009 16:07:28 -0700 From: Xin LI Organization: The FreeBSD Project User-Agent: Thunderbird 2.0.0.22 (X11/20090803) MIME-Version: 1.0 To: FreeBSD Current X-Enigmail-Version: 0.96.0 OpenPGP: id=18EDEBA0; url=http://www.delphij.net/delphij.asc Content-Type: multipart/mixed; boundary="------------090504090807040407080107" Subject: [PATCH] Shutdown cooloff feature X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: d@delphij.net List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Sep 2009 23:07:38 -0000 This is a multi-part message in MIME format. --------------090504090807040407080107 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit -----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 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 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----- --------------090504090807040407080107 Content-Type: text/plain; name="shutdown-cooloff.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="shutdown-cooloff.diff" 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; --------------090504090807040407080107--