From owner-freebsd-bugs@FreeBSD.ORG Wed Jun 27 02:10:05 2007 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 81A7516A469 for ; Wed, 27 Jun 2007 02:10:05 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [69.147.83.40]) by mx1.freebsd.org (Postfix) with ESMTP id 5D2ED13C44B for ; Wed, 27 Jun 2007 02:10:05 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id l5R2A4md097073 for ; Wed, 27 Jun 2007 02:10:04 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id l5R2A4kI097072; Wed, 27 Jun 2007 02:10:04 GMT (envelope-from gnats) Resent-Date: Wed, 27 Jun 2007 02:10:04 GMT Resent-Message-Id: <200706270210.l5R2A4kI097072@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Stef Walter Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 48C1116A41F for ; Wed, 27 Jun 2007 02:00:37 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [69.147.83.33]) by mx1.freebsd.org (Postfix) with ESMTP id 2145D13C448 for ; Wed, 27 Jun 2007 02:00:37 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.13.1/8.13.1) with ESMTP id l5R20bTD011730 for ; Wed, 27 Jun 2007 02:00:37 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.13.1/8.13.1/Submit) id l5R20anl011729; Wed, 27 Jun 2007 02:00:36 GMT (envelope-from nobody) Message-Id: <200706270200.l5R20anl011729@www.freebsd.org> Date: Wed, 27 Jun 2007 02:00:36 GMT From: Stef Walter To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.0 Cc: Subject: misc/114059: shutdown should fall back to exec reboot/halt when init is not running X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Jun 2007 02:10:05 -0000 >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@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 #include #include +#include #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: