misc/114059: shutdown should fall back to exec reboot/halt when
init is not running
Stef Walter
stef at memberwebs.com
Wed Jun 27 02:10:05 UTC 2007
>Number: 114059
>Category: misc
>Synopsis: shutdown should fall back to exec reboot/halt when init is not running
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Wed Jun 27 02:10:04 GMT 2007
>Closed-Date:
>Last-Modified:
>Originator: Stef Walter
>Release: FreeBSD 6.2
>Organization:
>Environment:
FreeBSD jail-devel-6x.ws.local 6.2-RELEASE-p1 FreeBSD 6.2-RELEASE-p1 #2: Tue Jun 26 15:55:31 UTC 2007 root at jail-devel-6x.ws.local:/usr/src/sys/i386/compile/JAIL-DEVEL i386
>Description:
When running in a jail or other environment where where init (ie: process 1) is not running, shutdown should call the reboot/halt commands. In a jail environment these are often replaced by custom scripts which handle restarting the jail.
Currently it is possible to call shutdown with the '-o' flag.
This patch adds adds a fallback if the kill() call fails. The patch also displays an error message if the kill() call fails for some other reason.
>How-To-Repeat:
>Fix:
Patch attached with submission follows:
--- sbin/shutdown/shutdown.c.orig Wed Jun 27 01:41:11 2007
+++ sbin/shutdown/shutdown.c Wed Jun 27 01:52:21 2007
@@ -57,6 +57,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <errno.h>
#ifdef DEBUG
#undef _PATH_NOLOGIN
@@ -328,6 +329,7 @@
die_you_gravy_sucking_pig_dog()
{
char *empty_environ[] = { NULL };
+ int sig;
syslog(LOG_NOTICE, "%s by %s: %s",
doreboot ? "reboot" : dohalt ? "halt" : dopower ? "power-down" :
@@ -351,11 +353,20 @@
(void)printf("\nkill -HUP 1\n");
#else
if (!oflag) {
- (void)kill(1, doreboot ? SIGINT : /* reboot */
- dohalt ? SIGUSR1 : /* halt */
- dopower ? SIGUSR2 : /* power-down */
- SIGTERM); /* single-user */
- } else {
+ sig = doreboot ? SIGINT : /* reboot */
+ dohalt ? SIGUSR1 : /* halt */
+ dopower ? SIGUSR2 : /* power-down */
+ SIGTERM; /* single-user */
+
+ if (kill(1, sig) < 0) {
+ if (errno == ESRCH)
+ oflag = 1; /* try calling reboot */
+ else
+ syslog(LOG_ERR, "shutdown: can't signal init (process 1): %m");
+ }
+ }
+
+ if (oflag) {
if (doreboot) {
execle(_PATH_REBOOT, "reboot", "-l", nosync,
(char *)NULL, empty_environ);
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-bugs
mailing list