Re: [PATCH] Shutdown cooloff feature

From: CmdLnKid <cmdlnkid_at_gmail.com>
Date: Tue, 29 Sep 2009 05:55:05 -0400
On Tue, 29 Sep 2009 04:16 -0000, danny wrote:

>
>> 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.
>>
> I know we are living in a virtual world, where even shutting down
> a computer is just a 'wish', but lets keep some sanity, now means now.
> On the other hand, you could make it conditional, say an environment
> variable 'GREENOPERATOR', in which case now would mean soon ... :-)
>
> danny
>
>> 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-----
>>
>> --------------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)
>> _at__at_ -103,6 +103,7 _at__at_ static void timewarn(int);
>>  static void usage(const char *);
>>
>>  extern const char **environ;
>> +static char hostname[MAXHOSTNAMELEN];
>>
>>  int
>>  main(int argc, char **argv)
>> _at__at_ -159,6 +160,7 _at__at_ main(int argc, char **argv)
>>  	if (nosync != NULL && !oflag)
>>  		usage("-n requires -o");
>>
>> +	gethostname(hostname, sizeof(hostname));
>>  	getoffset(*argv++);
>>
>>  	if (*argv) {
>> _at__at_ -193,8 +195,22 _at__at_ 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 : "???";
>> _at__at_ -271,14 +287,9 _at__at_ 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
>> Content-Type: text/plain; charset="us-ascii"
>> MIME-Version: 1.0
>> Content-Transfer-Encoding: 7bit
>> Content-Disposition: inline
>>
>> _______________________________________________
>> freebsd-current_at_freebsd.org mailing list
>> http://lists.freebsd.org/mailman/listinfo/freebsd-current
>> To unsubscribe, send any mail to "freebsd-current-unsubscribe_at_freebsd.org"
>> --------------090504090807040407080107--
>>
>
>
> _______________________________________________
> freebsd-current_at_freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-current
> To unsubscribe, send any mail to "freebsd-current-unsubscribe_at_freebsd.org"
>

How about adding this as a kernel tunable that could be placed in 
/boot/loader.conf or tuned via sysctl during operation and then instead of 
having it act upon someone issuing the shutdown command which is a pretty hard 
thing to accidentally do, have it act on the three finger salute aka: 
ctrl+alt+del.

Personally I would love to have something like this in place that could have a 
adjustable time limit or reasonable default time limit that could actually give 
a sysop time to react.

Just my thoughts.

-- 

   - (2^(N-1))
Received on Tue Sep 29 2009 - 07:55:16 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:39:56 UTC