Date: Mon, 17 Aug 2009 06:07:39 GMT From: Michael Leun <michael.leun@arcor.net> To: freebsd-gnats-submit@FreeBSD.org Subject: bin/137864: [patch] sysinstall: add possibility to shutdown/poweroff without modifying /etc/rc.conf Message-ID: <200908170607.n7H67dRQ092300@www.freebsd.org> Resent-Message-ID: <200908170610.n7H6A5Qd095886@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 137864 >Category: bin >Synopsis: [patch] sysinstall: add possibility to shutdown/poweroff without modifying /etc/rc.conf >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Mon Aug 17 06:10:05 UTC 2009 >Closed-Date: >Last-Modified: >Originator: Michael Leun >Release: 7.2 >Organization: Vodafone AG & Co. KG >Environment: FreeBSD build72-64.tnd.arcor.net 7.2-RELEASE FreeBSD 7.2-RELEASE #0: Fri May 1 07:18:07 UTC 2009 root@driscoll.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC amd64 >Description: I've created customized install disks doing an unattended installation of the current (current when creating the disk) patchlevel of FreeBSD. At the end of the installation a customized package which brings some configuration files, changes some config and creates /etc/rc.conf from scratch is installed. But with unmodified sysinstall all changes made in the post install script of the custom package get clobbered / commented out. My search for a solution lead to http://lists.freebsd.org/pipermail/freebsd-questions/2005-December/107861.html This patch adds an option "shutdownNoRC" to shutdown without touching /etc/rc.conf (and also "poweroff" to just power off and "poweroffNoRC" to power off without touching rc.conf) at the end of the installation. Note: This fixes bin/69942. >How-To-Repeat: Create an custom install media which installs a package modifying /etc/rc.conf >Fix: Patch attached Adds alternate commands to quit installation, offering the possibility not to change / create /etc/rc.conf by sysinstall. Patch attached with submission follows: # Patch FreeBSD 7.2 sysinstall to have options not to touch /etc/rc.conf # originally created by Antony Mawer see # http://lists.freebsd.org/pipermail/freebsd-questions/2005-December/107861.html # # Adapted to FreeBSD 7.2 by Michael Leun on behalf of Vodafone AG & Co. KG diff -Nur usr.sbin.orig/sysinstall/dispatch.c usr.sbin/sysinstall/dispatch.c --- usr.sbin.orig/sysinstall/dispatch.c 2009-04-15 05:14:26.000000000 +0200 +++ usr.sbin/sysinstall/dispatch.c 2009-06-24 22:53:47.000000000 +0200 @@ -43,6 +43,9 @@ #include "list.h" static int dispatch_shutdown(dialogMenuItem *unused); +static int dispatch_shutdown_norc(dialogMenuItem *unused); +static int dispatch_poweroff(dialogMenuItem *unused); +static int dispatch_poweroff_norc(dialogMenuItem *unused); static int dispatch_systemExecute(dialogMenuItem *unused); static int dispatch_msgConfirm(dialogMenuItem *unused); static int dispatch_mediaOpen(dialogMenuItem *unused); @@ -113,9 +116,13 @@ { "addGroup", userAddGroup }, { "addUser", userAddUser }, { "shutdown", dispatch_shutdown }, + { "shutdownNoRC", dispatch_shutdown_norc }, + { "poweroff", dispatch_poweroff }, + { "poweroffNoRC", dispatch_poweroff_norc }, { "system", dispatch_systemExecute }, { "dumpVariables", dump_variables }, { "tcpMenuSelect", tcpMenuSelect }, + { "configCountry", configCountry }, { NULL, NULL }, }; @@ -180,6 +187,27 @@ } static int +dispatch_shutdown_norc(dialogMenuItem *unused) +{ + systemShutdownNow(0, SHUTDOWN_NO_RC_CONF); + return DITEM_FAILURE; +} + +static int +dispatch_poweroff(dialogMenuItem *unused) +{ + systemShutdownNow(0, SHUTDOWN_POWEROFF); + return DITEM_FAILURE; +} + +static int +dispatch_poweroff_norc(dialogMenuItem *unused) +{ + systemShutdownNow(0, SHUTDOWN_POWEROFF | SHUTDOWN_NO_RC_CONF); + return DITEM_FAILURE; +} + +static int dispatch_systemExecute(dialogMenuItem *unused) { char *cmd = variable_get(VAR_COMMAND); diff -Nur usr.sbin.orig/sysinstall/sysinstall.8 usr.sbin/sysinstall/sysinstall.8 --- usr.sbin.orig/sysinstall/sysinstall.8 2009-04-15 05:14:26.000000000 +0200 +++ usr.sbin/sysinstall/sysinstall.8 2009-06-24 22:51:20.000000000 +0200 @@ -835,6 +835,26 @@ .Pp .Sy Variables : None +.It shutdownNoRC +Stop the script and terminate sysinstall, but do not touch +.Pa /etc/rc.conf . +.Pp +.Sy Variables : +None +.It poweroff +The same as +.Pa shutdown , +only power off the system (if possible) rather than rebooting. +.Pp +.Sy Variables : +None +.It poweroffNoRC +The same as +.Pa shutdownNoRC , +only power off the system (if possible) rather than rebooting. +.Pp +.Sy Variables : +None .It system Execute an arbitrary command with .Xr system 3 diff -Nur usr.sbin.orig/sysinstall/sysinstall.h usr.sbin/sysinstall/sysinstall.h --- usr.sbin.orig/sysinstall/sysinstall.h 2009-04-15 05:14:26.000000000 +0200 +++ usr.sbin/sysinstall/sysinstall.h 2009-06-24 22:51:20.000000000 +0200 @@ -407,6 +407,10 @@ char extras[EXTRAS_FIELD_LEN]; } DevInfo; +/* systemShutdownNow bitfield flags */ +#define SHUTDOWN_POWEROFF 0x1 /* Power off after shutdown */ +#define SHUTDOWN_NO_RC_CONF 0x2 /* Don't attempt to update rc.conf */ + /*** Externs ***/ extern jmp_buf BailOut; /* Used to get the heck out */ @@ -838,6 +842,7 @@ /* system.c */ extern void systemInitialize(int argc, char **argv); extern void systemShutdown(int status); +extern void systemShutdownNow(int status, int shutdown_flags); extern int execExecute(char *cmd, char *name); extern int systemExecute(char *cmd); extern void systemSuspendDialog(void); diff -Nur usr.sbin.orig/sysinstall/system.c usr.sbin/sysinstall/system.c --- usr.sbin.orig/sysinstall/system.c 2009-04-15 05:14:26.000000000 +0200 +++ usr.sbin/sysinstall/system.c 2009-06-24 22:51:20.000000000 +0200 @@ -238,12 +238,20 @@ void systemShutdown(int status) { + systemShutdownNow(status, 0); +} + +void +systemShutdownNow(int status, int shutdown_flags) +{ + /* If some media is open, close it down */ if (status >=0) mediaClose(); /* write out any changes to rc.conf .. */ - configRC_conf(); + if (!(shutdown_flags & SHUTDOWN_NO_RC_CONF)) + configRC_conf(); /* Shut down the dialog library */ if (DialogActive) { @@ -264,7 +272,10 @@ #if defined(__alpha__) || defined(__sparc64__) reboot(RB_HALT); #else - reboot(RB_AUTOBOOT); + if (shutdown_flags & SHUTDOWN_POWEROFF) + reboot(RB_HALT | RB_POWEROFF); + else + reboot(RB_AUTOBOOT); #endif } else >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200908170607.n7H67dRQ092300>