Should reboot(8) be modified so that it can become the recommended way to reboot a system?
Daniel Tameling <[email protected]>
| Newsgroups | gmane.os.freebsd.architechture |
|---|---|
| Message-ID | <[email protected]> |
(Warner suggested I should move the discussion to this mailing list.) Right now reboot(8) and halt(8) don't execute rc.shutdown scripts. Thus, both generally shouldn't be used to initiate a reboot/halt and, instead, one usually wants to use the shutdown command. The problem is that people regularly still use reboot and are then surprised that their scripts aren't executed. Part of the problem is that reboot indeed reboots the system, so it is hard to discover that you are using the wrong command. This is also not a documentation issue: official guides all use shutdown and the reboot man page is quite explicit that you probably want to use shutdown instead. People just see the name "reboot" and use it without consulting the docs. To be honest, I find that the current behaviour is a POLA violation, but it has historical reasons. Last year somebody encountered this behaviour and submitted a bug asking for a change in reboot(8) and halt(8) so that they can become the recommended commands (https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=280941). Part of the argument is that fastboot and fasthalt are currently alias to reboot and halt, so anybody who wants the old behaviour can just switch to those commands. Another wrinkle is that the poweroff command is implemented through shutdown and is therefore completely safe to use. While in the bug report there where some voices in favour of the change, there also was a dissenting opinion that wants to keep the current behavior. Overall the discussion had low participation, so the first step should be to figure out what we want to do. Do we want to make reboot and halt safe r or do we want to keep the current behaviour? So it would be good if you express your opinion, if you have any, so that we can reach a well-founded decision. Regarding a potential implementation: the easiest solution would be to piggyback on the poweroff implementation. I attached a patch to show how something like that could potentially look like. However, should we decide to actually change reboot and halt, there are further decisions that we need to agree upon. In particular: - do we want to add a flag to reboot/halt/poweroff for a fast shutdown? (maybe -f) In the bug report there was a slight preference to do this. - include/paths.h contains _PATH_REBOOT and _PATH_HALT as definitions for reboot and halt. Those can be defined as fastboot and fasthalt without problem, but should the variables be renamed? In src the only consumer is shutdown, but do we care about other users? - The permissions of reboot and halt are currently "-r-xr-xr-x root wheel" but shutdown and poweroff are "-r-sr-xr-- root operator". Do we want to change this if reboot/halt become safer? - The folder with reboot/halt etc is currently sbin/reboot. Do we want to rename it? Best regards, Daniel
0001-make-reboot-and-halt-aliases-for-shutdown--r-now-and-.patch
(text/plain, 9.6 KB)
From b001b5259c1d506310ab19267b303fb5da45539d Mon Sep 17 00:00:00 2001 From: Daniel Tameling <[email protected]> Date: Tue, 28 Jan 2025 14:06:44 +0100 Subject: [PATCH] make reboot and halt aliases for shutdown -r now and shutdown -h now Until now the reboot and halt commands don't shut the system down cleanly. For instance, they don't execute the shutdown scripts of rc and are thus not the recommended for rebooting and halting a system. As this behaviour is not obvious, make them aliases to the safer shutdown command in the same way it already provides the poweroff command. The old behaviour is still available as fastboot and fasthalt. --- include/paths.h | 8 +++---- sbin/reboot/Makefile | 12 ++++------ sbin/reboot/boot_i386.8 | 4 ++-- sbin/reboot/{reboot.8 => fastboot.8} | 34 +++++----------------------- sbin/reboot/{reboot.c => fastboot.c} | 0 sbin/shutdown/Makefile | 6 +++-- sbin/shutdown/shutdown.8 | 24 +++++++++++++++++--- sbin/shutdown/shutdown.c | 23 +++++++++++-------- 8 files changed, 56 insertions(+), 55 deletions(-) rename sbin/reboot/{reboot.8 => fastboot.8} (94%) rename sbin/reboot/{reboot.c => fastboot.c} (100%) diff --git a/include/paths.h b/include/paths.h index f8861ea4e5a8..01316277d3fe 100644 --- a/include/paths.h +++ b/include/paths.h @@ -62,7 +62,7 @@ #define _PATH_FTPUSERS "/etc/ftpusers" #define _PATH_FWMEM "/dev/fwmem" #define _PATH_GELI "/sbin/geli" -#define _PATH_HALT "/sbin/halt" +#define _PATH_HALT "/sbin/fasthalt" #ifdef COMPAT_libcompat #define _PATH_I18NMODULE "/usr/lib" COMPAT_libcompat "/i18n" #else @@ -82,7 +82,7 @@ #define _PATH_NEWFS "/sbin/newfs" #define _PATH_NOLOGIN "/var/run/nologin" #define _PATH_RCP "/bin/rcp" -#define _PATH_REBOOT "/sbin/reboot" +#define _PATH_REBOOT "/sbin/fastboot" #define _PATH_RLOGIN "/usr/bin/rlogin" #define _PATH_RM "/bin/rm" #define _PATH_RSH "/usr/bin/rsh" @@ -124,7 +124,7 @@ __END_DECLS #undef _PATH_CSHELL #define _PATH_CSHELL "/rescue/csh" #undef _PATH_HALT -#define _PATH_HALT "/rescue/halt" +#define _PATH_HALT "/rescue/fasthalt" #undef _PATH_IFCONFIG #define _PATH_IFCONFIG "/rescue/ifconfig" #undef _PATH_MDCONFIG @@ -136,7 +136,7 @@ __END_DECLS #undef _PATH_RCP #define _PATH_RCP "/rescue/rcp" #undef _PATH_REBOOT -#define _PATH_REBOOT "/rescue/reboot" +#define _PATH_REBOOT "/rescue/fastboot" #undef _PATH_RM #define _PATH_RM "/rescue/rm" #undef _PATH_TUNEFS diff --git a/sbin/reboot/Makefile b/sbin/reboot/Makefile index 27805d307794..611c9771c798 100644 --- a/sbin/reboot/Makefile +++ b/sbin/reboot/Makefile @@ -1,7 +1,7 @@ PACKAGE=runtime -PROG= reboot -MAN= reboot.8 nextboot.8 -MLINKS= reboot.8 halt.8 reboot.8 fastboot.8 reboot.8 fasthalt.8 +PROG= fastboot +MAN= fastboot.8 nextboot.8 +MLINKS= fastboot.8 fasthalt.8 .if exists(${.CURDIR}/boot_${MACHINE}.8) MAN+= boot_${MACHINE}.8 @@ -12,9 +12,7 @@ MAN+= boot_i386.8 MLINKS+= boot_i386.8 boot.8 .endif -LINKS= ${BINDIR}/reboot ${BINDIR}/halt \ - ${BINDIR}/reboot ${BINDIR}/fastboot \ - ${BINDIR}/reboot ${BINDIR}/fasthalt \ - ${BINDIR}/reboot ${BINDIR}/nextboot +LINKS= ${BINDIR}/fastboot ${BINDIR}/fasthalt \ + ${BINDIR}/fastboot ${BINDIR}/nextboot .include <bsd.prog.mk> diff --git a/sbin/reboot/boot_i386.8 b/sbin/reboot/boot_i386.8 index 5e97a7594684..456a049c3b2b 100644 --- a/sbin/reboot/boot_i386.8 +++ b/sbin/reboot/boot_i386.8 @@ -326,13 +326,13 @@ requirement has not been adhered to. .Xr config 8 , .Xr efibootmgr 8 , .Xr efivar 8 , +.Xr fasthalt 8 , +.Xr fastboot 8 , .Xr gpart 8 , .Xr gptboot 8 , .Xr gptzfsboot 8 , -.Xr halt 8 , .Xr loader 8 , .Xr nextboot 8 , -.Xr reboot 8 , .Xr shutdown 8 , .Xr uefi 8 , .Xr zfsbootcfg 8 diff --git a/sbin/reboot/reboot.8 b/sbin/reboot/fastboot.8 similarity index 94% rename from sbin/reboot/reboot.8 rename to sbin/reboot/fastboot.8 index 59cbd9de7519..474e9f526f34 100644 --- a/sbin/reboot/reboot.8 +++ b/sbin/reboot/fastboot.8 @@ -29,35 +29,23 @@ .Dt REBOOT 8 .Os .Sh NAME -.Nm reboot , -.Nm halt , .Nm fastboot , .Nm fasthalt .Nd stopping and restarting the system .Sh SYNOPSIS -.Nm halt -.Op Fl DflNnpq -.Op Fl e Ar variable=value -.Op Fl k Ar kernel -.Op Fl o Ar options -.Nm -.Op Fl cDdflNnpqr -.Op Fl e Ar variable=value -.Op Fl k Ar kernel -.Op Fl o Ar options .Nm fasthalt .Op Fl DflNnpq .Op Fl e Ar variable=value .Op Fl k Ar kernel .Op Fl o Ar options -.Nm fastboot +.Nm .Op Fl dDflNnpq .Op Fl e Ar variable=value .Op Fl k Ar kernel .Op Fl o Ar options .Sh DESCRIPTION The -.Nm halt +.Nm fasthalt and .Nm utilities flush the file system cache to disk, send all running processes @@ -75,7 +63,7 @@ The options are as follows: The system will turn off the power and then turn it back on if it can. If the power down action fails, the system will halt or reboot normally, depending on whether -.Nm halt +.Nm fasthalt or .Nm was called. @@ -135,7 +123,7 @@ This option is intended for applications such as that call .Nm or -.Nm halt +.Nm fasthalt and log this themselves. .It Fl N The file system cache is not flushed during the initial process clean-up, @@ -157,7 +145,7 @@ allows the passing of kernel flags for the next boot. The system will turn off the power if it can. If the power down action fails, the system will halt or reboot normally, depending on whether -.Nm halt +.Nm fasthalt or .Nm was called. @@ -182,16 +170,6 @@ needs a place to store itself after the old root is unmounted, but before the new root is in place. .El .Pp -The -.Nm fasthalt -and -.Nm fastboot -utilities are nothing more than aliases for the -.Nm halt -and -.Nm -utilities. -.Pp Normally, the .Xr shutdown 8 utility is used when the system needs to be halted or restarted, giving @@ -223,6 +201,6 @@ reboot -r .Xr sync 8 .Sh HISTORY A -.Nm +.Nm reboot utility appeared in .Bx 4.0 . diff --git a/sbin/reboot/reboot.c b/sbin/reboot/fastboot.c similarity index 100% rename from sbin/reboot/reboot.c rename to sbin/reboot/fastboot.c diff --git a/sbin/shutdown/Makefile b/sbin/shutdown/Makefile index 6c5d6e4487e2..d2e612db3488 100644 --- a/sbin/shutdown/Makefile +++ b/sbin/shutdown/Makefile @@ -1,8 +1,10 @@ PACKAGE=runtime PROG= shutdown MAN= shutdown.8 -LINKS= ${BINDIR}/shutdown ${BINDIR}/poweroff -MLINKS= shutdown.8 poweroff.8 +LINKS= ${BINDIR}/shutdown ${BINDIR}/halt \ + ${BINDIR}/shutdown ${BINDIR}/poweroff \ + ${BINDIR}/shutdown ${BINDIR}/reboot +MLINKS= shutdown.8 halt.8 shutdown.8 poweroff.8 shutdown.8 reboot.8 BINOWN= root BINGRP= operator diff --git a/sbin/shutdown/shutdown.8 b/sbin/shutdown/shutdown.8 index ab90af6244e9..0aac0f6676eb 100644 --- a/sbin/shutdown/shutdown.8 +++ b/sbin/shutdown/shutdown.8 @@ -30,7 +30,9 @@ .Os .Sh NAME .Nm shutdown , -.Nm poweroff +.Nm halt , +.Nm poweroff , +.Nm reboot .Nd "close down the system at a given time" .Sh SYNOPSIS .Nm @@ -46,7 +48,9 @@ .Op Fl q .Ar time .Op Ar warning-message ... +.Nm halt .Nm poweroff +.Nm reboot .Sh DESCRIPTION The .Nm @@ -213,11 +217,25 @@ utility will place the system into single user mode at the specified. .Pp Calling +.Dq Nm halt +is equivalent to running: +.Bd -literal -offset indent +shutdown -h now +.Ed +.Pp +Calling .Dq Nm poweroff is equivalent to running: .Bd -literal -offset indent shutdown -p now .Ed +.Pp +Calling +.Dq Nm reboot +is equivalent to running: +.Bd -literal -offset indent +shutdown -r now +.Ed .Sh FILES .Bl -tag -width /var/run/nologin -compact .It Pa /var/run/nologin @@ -238,9 +256,9 @@ a colon (``:'') for backward compatibility. .Xr login 1 , .Xr wall 1 , .Xr nologin 5 , -.Xr halt 8 , +.Xr fasthalt 8 , .Xr init 8 , -.Xr reboot 8 +.Xr fastboot 8 .Sh HISTORY A .Nm diff --git a/sbin/shutdown/shutdown.c b/sbin/shutdown/shutdown.c index e92d41220a20..7535b884db82 100644 --- a/sbin/shutdown/shutdown.c +++ b/sbin/shutdown/shutdown.c @@ -120,14 +120,19 @@ main(int argc, char **argv) p = argv[0]; else ++p; - if (strcmp(p, "poweroff") == 0) { + if (strcmp(p, "halt") == 0) + dohalt = 1; + else if (strcmp(p, "poweroff") == 0) + dopower = 1; + else if (strcmp(p, "reboot") == 0) + doreboot = 1; + if (dohalt || dopower || doreboot) { if (getopt(argc, argv, "") != -1) usage((char *)NULL); argc -= optind; argv += optind; if (argc != 0) usage((char *)NULL); - dopower = 1; offset = 0; (void)time(&shuttime); goto poweroff; @@ -394,31 +399,31 @@ die_you_gravy_sucking_pig_dog(void) SIGTERM); /* single-user */ } else { if (doreboot) { - BOOTTRACE("exec reboot(8) -l..."); - execle(_PATH_REBOOT, "reboot", "-l", nosync, + BOOTTRACE("exec fastboot(8) -l..."); + execle(_PATH_REBOOT, "fastboot", "-l", nosync, (char *)NULL, empty_environ); syslog(LOG_ERR, "shutdown: can't exec %s: %m.", _PATH_REBOOT); warn(_PATH_REBOOT); } else if (dohalt) { - BOOTTRACE("exec halt(8) -l..."); - execle(_PATH_HALT, "halt", "-l", nosync, + BOOTTRACE("exec fasthalt(8) -l..."); + execle(_PATH_HALT, "fasthalt", "-l", nosync, (char *)NULL, empty_environ); syslog(LOG_ERR, "shutdown: can't exec %s: %m.", _PATH_HALT); warn(_PATH_HALT); } else if (dopower) { - BOOTTRACE("exec halt(8) -l -p..."); - execle(_PATH_HALT, "halt", "-l", "-p", nosync, + BOOTTRACE("exec fasthalt(8) -l -p..."); + execle(_PATH_HALT, "fasthalt", "-l", "-p", nosync, (char *)NULL, empty_environ); syslog(LOG_ERR, "shutdown: can't exec %s: %m.", _PATH_HALT); warn(_PATH_HALT); } else if (docycle) { - execle(_PATH_HALT, "halt", "-l", "-c", nosync, + execle(_PATH_HALT, "fasthalt", "-l", "-c", nosync, (char *)NULL, empty_environ); syslog(LOG_ERR, "shutdown: can't exec %s: %m.", _PATH_HALT); -- 2.48.1