Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F161020659
D54117.id167677.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D54117.id167677.diff
View Options
diff --git a/sbin/reboot/reboot.8 b/sbin/reboot/reboot.8
--- a/sbin/reboot/reboot.8
+++ b/sbin/reboot/reboot.8
@@ -25,7 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd April 12, 2025
+.Dd December 8, 2025
.Dt REBOOT 8
.Os
.Sh NAME
@@ -60,14 +60,21 @@
.Nm halt
and
.Nm
-utilities flush the file system cache to disk, send all running processes
-a
+utilities stop and restart the system, respectively.
+.Pp
+Both utilities have two distinct modes of operation.
+In normal mode, they send a signal to the
+.Xr init 8
+process, which shuts down running services and stops or restarts the
+system.
+In forced mode, they flush the file system cache to disk, send all
+running processes a
.Dv SIGTERM
(and subsequently a
.Dv SIGKILL )
-and, respectively, halt or restart the system.
-The action is logged, including entering a shutdown record into the user
-accounting database.
+and stop or restart the system themselves.
+In either mode, the action is logged, including entering a shutdown
+record into the user accounting database.
.Pp
The options are as follows:
.Bl -tag -width indent
@@ -111,14 +118,25 @@
contains any characters that are special to the shell or loader's configuration
parsing code.
.It Fl f
-Force reboot.
+Forced mode.
Normally,
+.Nm halt
+or
.Nm
checks for the presence of the next kernel,
and absence of the
.Pa /var/run/noshutdown
file.
-Without this flag, reboot is denied if one of the conditions failed.
+Without this flag, the operation is rejected if one of these checks
+failed.
+With this flag, these checks are skipped and
+.Nm halt
+or
+.Nm
+stops or restarts the system itself instead of signaling the
+.Xr init 8
+process to do it.
+Services are killed, not shut down, which may result in data loss.
.It Fl k Ar kname
Boot the specified kernel
.Ar kname
@@ -201,11 +219,14 @@
.Nm
utilities.
.Pp
-Normally, the
+The
.Xr shutdown 8
-utility is used when the system needs to be halted or restarted, giving
-users advance warning of their impending doom and cleanly terminating
-specific programs.
+utility can be used to not only stop or restart the system right away,
+but also schedule a stop or restart in the future, and will, unlike
+.Nm halt
+and
+.Nm ,
+give users advance warning of their impending doom.
.Sh EXAMPLES
Replace current root filesystem with UFS mounted from
.Pa /dev/ada0s1a :
@@ -236,3 +257,18 @@
.Nm
utility appeared in
.Bx 4.0 .
+.Pp
+Historically, the
+.Xr shutdown 8
+utility was used when the system needed to be halted or restarted
+cleanly in the normal course of operations, and the
+.Nm halt
+and
+.Nm
+utilities were blunt instruments used only in single-user mode or if
+exceptional circumstances made a normal shutdown impractical.
+As other operating systems did away with this distinction, and it
+became clear that many users were unaware of it and were using
+.Nm
+in the belief that it performed a clean shutdown, it was rewritten to
+conform to that expectation.
diff --git a/sbin/reboot/reboot.c b/sbin/reboot/reboot.c
--- a/sbin/reboot/reboot.c
+++ b/sbin/reboot/reboot.c
@@ -212,6 +212,24 @@
free(oldenv);
}
+static void
+shutdown(int howto)
+{
+ char sigstr[SIG2STR_MAX];
+ int signo =
+ howto & RB_HALT ? SIGUSR1 :
+ howto & RB_POWEROFF ? SIGUSR2 :
+ howto & RB_POWERCYCLE ? SIGWINCH :
+ howto & RB_REROOT ? SIGEMT :
+ SIGINT;
+
+ (void)sig2str(signo, sigstr);
+ BOOTTRACE("SIG%s to init(8)...", sigstr);
+ if (kill(1, signo) == -1)
+ err(1, "SIG%s init", sigstr);
+ exit(0);
+}
+
/*
* Different options are valid for different programs.
*/
@@ -309,8 +327,8 @@
errx(1, "-N cannot be used with -n");
if ((howto & RB_POWEROFF) && (howto & RB_POWERCYCLE))
errx(1, "-c and -p cannot be used together");
- if ((howto & RB_REROOT) != 0 && howto != RB_REROOT)
- errx(1, "-r cannot be used with -c, -d, -n, or -p");
+ if ((howto & RB_REROOT) != 0 && (howto != RB_REROOT || fflag))
+ errx(1, "-r cannot be used with -c, -d, -f, -n, or -p");
if ((howto & RB_REROOT) != 0 && kernel != NULL)
errx(1, "-r and -k cannot be used together, there is no next kernel");
@@ -418,14 +436,10 @@
(void)signal(SIGPIPE, SIG_IGN);
/*
- * Only init(8) can perform rerooting.
+ * Common case: clean shutdown.
*/
- if (howto & RB_REROOT) {
- if (kill(1, SIGEMT) == -1)
- err(1, "SIGEMT init");
-
- return (0);
- }
+ if (!fflag)
+ shutdown(howto);
/* Just stop init -- if we fail, we'll restart it. */
BOOTTRACE("SIGTSTP to init(8)...");
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Jun 30, 10:05 PM (1 h, 50 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
34525861
Default Alt Text
D54117.id167677.diff (4 KB)
Attached To
Mode
D54117: reboot: Default to a clean shutdown
Attached
Detach File
Event Timeline
Log In to Comment