History log of /freebsd-current/sbin/reboot/reboot.c
Revision Date Author Comments
# ff7de3b4 30-May-2024 John Baldwin <jhb@FreeBSD.org>

nextboot: Permit ZFS boot filesystems mounted at the pool's root

This restores nextboot -k on ZFS setups where /boot is on the root
dataset of a pool.

Reviewed by: jrtc27, glebius
Fixes: 0c3ade2cf13d nextboot: fix nextboot -k on ZFS
Sponsored by: Chelsio Communications
Differential Revision: https://reviews.freebsd.org/D45306


# 87e63f2e 03-Apr-2024 Mark Johnston <markj@FreeBSD.org>

nextboot: Write nextboot.conf safely

As in the old nextboot.sh script:
- First write everything to a tempfile instead of /boot/nextboot.conf.
- fsync() the tempfile before renaming it to nextboot.conf.

Fixes: fd6d47375a78 ("rescue,nextboot: Install nextboot as a link to reboot, rm nextboot.sh")
Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D44572


# bad90cb4 21-Feb-2024 Warner Losh <imp@FreeBSD.org>

nextboot: check unlink, but only warn on !ENOENT

Emulate rm -f from the nextboot.sh script: Report all errors, except
ENOENT. This problems show through, except the expected one when
nextboot.conf isn't there.

Sponsored by: Netflix
Reviewed by: rew
Differential Revision: https://reviews.freebsd.org/D44013


# 07cba2dd 20-Feb-2024 Warner Losh <imp@FreeBSD.org>

reboot: Emulate nextboot -D better

It used to produce no output when the file couldn't be removed. Emulate
that better by unlinking and ignoring errors. It's used at the end of
reboot always, even when the file isn't going to be there.

Sponsored by: Netflix
Fixes: 2c479548119a


# 0c3ade2c 19-Feb-2024 Gleb Smirnoff <glebius@FreeBSD.org>

nextboot: fix nextboot -k on ZFS

zfsbootcfg(1) expects pool name to operate on, not currently mounted
filesystem name.

Fixes: fd6d47375a78fbf0737012b7cc11180291781e8b


# 3aefe675 19-Feb-2024 Gleb Smirnoff <glebius@FreeBSD.org>

nextboot: fix typo that merged two args into one

Fixes: fd6d47375a78fbf0737012b7cc11180291781e8b


# 2546c543 17-Feb-2024 Warner Losh <imp@FreeBSD.org>

reboot: Move extern for environ

envorin isn't defined in any header, and gcc is cranky with this inside
a function, so move it to global scope. Both clang and gcc are now happy
with this.

Sponsored by: Netflix


# 4d0be398 17-Feb-2024 Warner Losh <imp@FreeBSD.org>

reboot: Remove sys/types.h: it's not needed here...


# 33a2406e 15-Feb-2024 Warner Losh <imp@FreeBSD.org>

reboot: Use posix_spawn instead of system

Use posix_spawn to avoid having to allocate memory needed for the system
command line.

Sponsored by: Netflix
Reviewed by: jrtc27
Differential Revision: https://reviews.freebsd.org/D43860


# e32de962 15-Feb-2024 Warner Losh <imp@FreeBSD.org>

reboot: initialize howto

Make static analyzers happy by initialzing howto to 0. Coverity is
cranky that it could be used unused. But it's analysis is incomplete
because the args to getopt when it wasn't initialized preclude it from
being used.


# 994cc839 12-Feb-2024 Warner Losh <imp@FreeBSD.org>

reboot: Allow this to be installed as nextboot

Allow nextboot to be a symlink link to reboot. It does everything reboot
does, except doesn't actually setup the sytem to reboot and reboot. Also,
don't accept the reboot args related to rebooting when in nextboot mode.

Sponsored by: Netflix
Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D43830


# 91d24077 12-Feb-2024 Warner Losh <imp@FreeBSD.org>

reboot: Implement -o to set kernel options for next boot

Sponsored by: Netflix
Reviewed by: kevans
Differential Revision: https://reviews.freebsd.org/D43829


# 9dcf6cbd 12-Feb-2024 Warner Losh <imp@FreeBSD.org>

reboot: Implement -k in terms of env

kernel isn't special, beyond the sanity checks we do. Add it to the env
rather than pass it into write_nextboot().

Sponsored by: Netflix
Reviewed by: kevans, kib
Differential Revision: https://reviews.freebsd.org/D43828


# ecc83424 12-Feb-2024 Warner Losh <imp@FreeBSD.org>

reboot: Implement -e from nextboot

Implement -e foo=bar to add loader environment variables to
nextboot.conf. bar is enclosed in quotes if it isn't already.

Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D43827


# 0df5f659 12-Feb-2024 Warner Losh <imp@FreeBSD.org>

reboot: Implement zfs support

Implement full support for ZFS -k support. For ZFS, we have to set a
property that gets cleared by the boot loaeder for whether or not to
process nextboot.conf. Do this using system("zfsbootcfg..." rather than
coding the small subset of that program inline to avoid CDDL
contamination of reboot and the complications of disabling CDDL and/or
ZFS. The few bytes needed to implement reboot for systems with zfs is
not worth saving for systems w/o ZFS.

Only set nextboot_enable=YES for UFS filesystems. They are the only one
that need that as the first line. Its presence on ZFS can cause the
kernel to not be oneshot.

Sponsored by: Netflix
Reviewed by: kevans, kib
Differential Revision: https://reviews.freebsd.org/D43824


# 2c479548 12-Feb-2024 Warner Losh <imp@FreeBSD.org>

reboot: Implement -D from nextboot

Implement -D from nextboot.sh which deletes the nextboot.conf file and
exists.

Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D43822


# cfeedadf 12-Feb-2024 Warner Losh <imp@FreeBSD.org>

reboot: Add sanity checking of write to nextboot.conf

Add sanity checking to the write to nextboot. Move to separate function
and allow force to override all errors. If we can't write nextboot.conf,
don't silently fail anymore.

Sponsored by: Netflix
Reviewed by: kevans, kib, markj, jhb
Differential Revision: https://reviews.freebsd.org/D43803


# 7cb1a0e6 12-Feb-2024 Warner Losh <imp@FreeBSD.org>

reboot: Don't reboot if the next kernel isn't there

reboot -k garbage won't boot garbage unless /boot/garbage/kernel is
there. Refuse to reboot if it is missing, though allow -f to force
it for special-use cases. This is in keeping with nextboot.sh.

Sponsored by: Netflix
Reviewed by: kevans, kib, markj, emaste
Differential Revision: https://reviews.freebsd.org/D43802


# 7a3210f2 12-Feb-2024 Warner Losh <imp@FreeBSD.org>

reboot: convert flags to bools

Convert all the command line flags to bools, since that's how we use
them. Sort the includes while adding stdbool.h.

Sponsored by: Netflix
Reviewed by: kevans, kib, emaste
Differential Revision: https://reviews.freebsd.org/D43801


# a78bc42b 12-Feb-2024 Warner Losh <imp@FreeBSD.org>

reboot: Disallow -k and -r, it doesn't make sense.

When we're re-rooting to a new /, there is no next kernel. Error out
rather than leaving a timebomb in /boot/nextboot.conf.

Sponsored by: Netflix
Reviewed by: kevans, kib, emaste
Differential Revision: https://reviews.freebsd.org/D43800


# 0b8224d1 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

Remove copyright strings ifdef'd out

We've ifdef'd out the copyright strings for some time now. Go ahead and
remove the ifdefs. Plus whatever other detritis was left over from other
recent removals. These copyright strings are present in the comments and
are largely from CSRG's attempt at adding their copyright to every
binary file (which modern interpretations of the license doesn't
require).

Sponsored by: Netflix


# 51e16cb8 23-Nov-2023 Warner Losh <imp@FreeBSD.org>

sbin: Remove ancient SCCS tags.

Remove ancient SCCS tags from the tree, automated scripting, with two
minor fixup to keep things compiling. All the common forms in the tree
were removed with a perl script.

Sponsored by: Netflix


# a294b02f 12-Nov-2023 Konstantin Belousov <kib@FreeBSD.org>

reboot(8): print syscall error on sysctl failure

Noted by: markj
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D42561


# 194cc45a 12-Nov-2023 Konstantin Belousov <kib@FreeBSD.org>

reboot(8): adapt for vmmeter v_swappgsin expansion to 64bit

Otherwise reboot(8) requires COMPAT_FREEBSD11 kernel config option.

PR: 275048
Reviewed by: markj
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D42561


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 65f3be91 07-Jul-2023 Alfonso Gregory <gfunni234@gmail.com>

Mark usage function as __dead2 in programs where it does not return

In most cases, usage does not return, so mark them as __dead2. For the
cases where they do return, they have not been marked __dead2.

Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/735


# 7b0a665d 21-Feb-2022 Mitchell Horne <mhorne@FreeBSD.org>

boottrace: annotate init and shutdown utilities

Add boottrace annotations to record events in init(8), shutdown(8), and
reboot(8).

Sponsored by: NetApp, Inc.
Sponsored by: Klara, Inc.
X-NetApp-PR: #23
Differential Revision: https://reviews.freebsd.org/D31928


# 6760585a 14-Sep-2018 Eric van Gyzen <vangyzen@FreeBSD.org>

Fix "fasthalt" to halt instead of reboot

fasthalt has behaved like reboot, instead of like halt, since r228408
(2011, 10.0-RELEASE). Fix it. One wonders if anyone will notice.

Approved by: re (kib)
MFC after: 3 days
Sponsored by: Dell EMC Isilon


# 2e23ded5 05-Apr-2018 Rodney W. Grimes <rgrimes@FreeBSD.org>

Exit with usage when extra arguments are on command line
preventing mistakes such as "halt 0p" for "halt -p".
Approved by: bde (mentor), phk (mentor)
MFC after: 1 week


# 8a16b7a1 20-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

General further adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 3-Clause license.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.


# 25fd0815 30-Oct-2017 Warner Losh <imp@FreeBSD.org>

Add -c to the usage statements.

Submitted by: Maxim Konovalov


# 7d7d9013 25-Oct-2017 Warner Losh <imp@FreeBSD.org>

Add power cycle support to reboot/halt as -c.

When -c is specified, the system will be power cycled if the
underlying hardware supports it. Otherwise the system will be halted
or rebooted depending on which command was used.

Sponsored by: Netflix


# fbbd9655 28-Feb-2017 Warner Losh <imp@FreeBSD.org>

Renumber copyright clause 4

Renumber cluase 4 to 3, per what everybody else did when BSD granted
them permission to remove clause 3. My insistance on keeping the same
numbering for legal reasons is too pedantic, so give up on that point.

Submitted by: Jan Schaumann <jschauma@stevens.edu>
Pull Request: https://github.com/freebsd/freebsd/pull/96


# 89d18e14 06-May-2016 Renato Botelho <garga@FreeBSD.org>

Add missing parameters -N and -l to reroot and halt usage()

Approved by: bapt
Sponsored by: Rubicon Communications (Netgate)
Differential Revision: https://reviews.freebsd.org/D6173


# 0f79b5d7 30-Dec-2015 Steven Hartland <smh@FreeBSD.org>

Fix use of uninitialised Nflag

Initialise Nflag to 0 preventing use of uninitialised value.

Reported by: uqs
MFC after: 1 week
X-MFC-With: r292266
Sponsored by: Multiplay
Differential Revision: https://reviews.freebsd.org/D4449


# 6237ce08 15-Dec-2015 Steven Hartland <smh@FreeBSD.org>

Add flag to disable inital reboot(8) userland sync

Add -N flag to reboot(8) which bypasses the userland sync(2) during
reboot(8) while still allow the kernel sync during the reboot(2) syscall
to occur.

An example use of this is when rebooting with disconnected iSCSI sessions
which would otherwise cause the reboot to hang on BIOs that will never
complete.

Reviewed by: bjk
MFC after: 2 weeks
Sponsored by: Multiplay
Differential Revision: https://reviews.freebsd.org/D4449


# 3f5ac575 08-Nov-2015 Edward Tomasz Napierala <trasz@FreeBSD.org>

Userspace part of reroot support. This makes it possible to change
the root filesystem without full reboot, using "reboot -r". This can
be used to to eg. boot from a temporary md_image preloaded by loader(8),
setup an iSCSI session, and continue booting from rootfs mounted over
iSCSI.

Reviewed by: kib@, bapt@
MFC after: 1 month
Relnotes: yes
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D3693


# e802a0b3 11-Dec-2011 Ed Schouten <ed@FreeBSD.org>

Let reboot(8) use getprogname() to compare the program name.

While there, mark the global variable dohalt static, as reboot(8) only
consists of a single C file.


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# bf8959b0 13-Jan-2010 Ed Schouten <ed@FreeBSD.org>

Port the remaining apps in sbin/ to utmpx; only reboot(8).


# 88a8f792 29-Dec-2009 Ed Schouten <ed@FreeBSD.org>

Add forgotten `void' keyword. This function has no arguments.


# 14c69f21 05-Dec-2009 Ed Schouten <ed@FreeBSD.org>

Let init(8) and reboot(8) use utmpx to log wtmp entries.

logwtmp() gets called with the raw strings that are written to disk. For
regular user entries, this isn't too bad, but when booting/shutting
down, the contents get rather cryptic.

Just call the standardized pututxline().


# c574558f 10-Nov-2009 Dag-Erling Smørgrav <des@FreeBSD.org>

More rational usage()


# c09a6b1a 31-Jan-2009 Bjoern A. Zeeb <bz@FreeBSD.org>

Remove and unused variable.

Submitted by: Christoph Mallon christoph.mallon@gmx.de
MFC after: 2 weeks


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# d8f70938 02-Aug-2006 Bruce M Simpson <bms@FreeBSD.org>

Block a variety of signals which may afffect reboot(8), before killing
init(8), to avoid losing a race to them and dying before being able
to call reboot(2).

PR: bin/64664
Submitted by: maxim
Obtained from: NetBSD
MFC after: 30 days


# b08d1553 01-Aug-2006 Bruce M Simpson <bms@FreeBSD.org>

Block SIGHUP before killing init(8), to avoid a race condition which may
kill the current process and hang the system when attempting reboot.

PR: bin/64664
Reviewed by: ssouhal, phk (historic)
MFC after: 30 days


# 3edf7a78 21-Mar-2005 Pawel Jakub Dawidek <pjd@FreeBSD.org>

Truncate nextboot.conf file on creation, so existing garbage will be removed.

Submitted by: Gary Allan <dragonfly@gallan.plus.com>
Obtained from: DragonFlyBSD
MFC after: 3 days


# 8d646af5 10-Feb-2005 Ruslan Ermilov <ru@FreeBSD.org>

Sync program's usage() with manpage's SYNOPSIS.


# 36737a0b 25-Jan-2005 Xin LI <delphij@FreeBSD.org>

Code style tweaks: Use static and const where suitable.


# faa0ecdd 25-Jan-2005 Xin LI <delphij@FreeBSD.org>

The kernel specified in main() of reboot(8) will be initialized
with -k option and never be used without kflag. This confuses
gcc because we set "kflag" at the same time with "kernel", but
the logic is not that apparant for gcc.

Since we can initialize "kernel" to NULL then know if "k" option
is set through determining whether it is still NULL, don't try
to have gcc to guess why we are connecting "kflag" with "kernel"
and use "kernel" directly in place of kflag.

Bump WARNS?= from 2 to 6


# 4c723140 09-Apr-2004 Mark Murray <markm@FreeBSD.org>

Remove advertising clause from University of California Regent's license,
per letter dated July 22, 1999.

Approved by: core, imp


# c69284ca 03-May-2003 David E. O'Brien <obrien@FreeBSD.org>

Use __FBSDID() to quiet GCC 3.3 warnings.


# 6ab0d6c2 02-Apr-2003 Robert Watson <rwatson@FreeBSD.org>

When kill(-1) returns ESRCH, it could be because the current process
doesn't have a process group, which can occur if you're working with
a custom init that doesn't set up a full tty context. Rather than
refusing to reboot, ignore ESRCH from the kill attempt in reboot(8).


# cfde77fb 06-Oct-2002 Thomas Quinot <thomas@FreeBSD.org>

Set only the RB_POWEROFF flag (not the RB_HALT flag) when
'-p' is used on the reboot(8) command line.

This is intended for use when you want to attempt a power down
action, but you want the system to reboot (not halt) if the
power down action fails.

This is typically useful when the power-off action performed by
the kernel consists in signalling an uninterrupted power supply
that it should shut down its inverter if mains power has not returned.

The behaviour of shutdown(8) and init(8) is not modified;
only the behaviour of invoking 'reboot -p' manually is
modified, and then only in the case when a power-down action
fails.

Sounded reasonable to: phk
Approved by: roberto (mentor)


# a72b2ac6 28-May-2002 Gordon Tetlow <gordon@FreeBSD.org>

Correct the file that reboot -k creates so that it works with the new
nextboot functionality.

Reviewed by: jake (mentor)


# 83739172 26-Apr-2002 Wes Peters <wes@FreeBSD.org>

Rename the file used to specify the nextboot to make it clear that this
is a loader configuration file and can be used for more than just a
kernel name.

Submitted by: Gordon Tetlow <gordont@gnf.org>


# 1de372dc 26-Apr-2002 Wes Peters <wes@FreeBSD.org>

Add a -k option to reboot to specify the kernel to boot next time
around. If the kernel boots successfully, the record of this kernel
is erased, it is intended to be a one-shot option for testing
kernels.

This could be improved by having the loader remove the record of
the next kernel to boot, it is currently removed in /etc/rc immediately
after disks are mounted r/w.

I'd like to MFC this before the 4.6 freeze unless there is violent
objection.

Reviewed by: Several on IRC
MFC after: 4 days


# 8b032500 14-Jul-2001 Dima Dorfman <dd@FreeBSD.org>

Constify and set WARNS=2.

Submitted by: Mike Barcroft <mike@q9media.com>


# cafefe8c 24-Jun-2001 Dima Dorfman <dd@FreeBSD.org>

Include missing header files which define functions for which gcc has
builtins (e.g., exit, strcmp).


# 6714dac4 24-May-2001 Nik Clayton <nik@FreeBSD.org>

Remove the "undocumented" comment in re lflag.


# 85ae580c 20-Mar-2001 Ian Dowse <iedowse@FreeBSD.org>

Reboot(8) normally waits 5 seconds after sending SIGTERMs to all
processes and then sends SIGKILLs. If a lot of processes are swapped
out, this delay may not be long enough, so processes such as an X
server may be killed before they have had time to clean up properly.

Make this delay more dynamic by waiting up to 60 seconds for swap
page-in activity to end. While I'm here, ANSIfy and remove a
`register' specifier.


# 85c981cc 21-Nov-1999 John Polstra <jdp@FreeBSD.org>

Add a "-d" option which causes the system to generate a crash dump.


# 7f3dea24 27-Aug-1999 Peter Wemm <peter@FreeBSD.org>

$Id$ -> $FreeBSD$


# 9448def9 15-Jul-1998 Philippe Charnier <charnier@FreeBSD.org>

Correct use of .Nm. Add rcsid. -Wall. Add -p flag in usage string (was missing).


# 41e964cb 30-Jun-1997 Philippe Charnier <charnier@FreeBSD.org>

Remove lines inside #ifdef 0/#endif.


# 098166ed 16-Jun-1997 Philippe Charnier <charnier@FreeBSD.org>

Use err(3) instead of local copy.


# 8d64695c 28-Mar-1997 Warner Losh <imp@FreeBSD.org>

compare return value from getopt against -1 rather than EOF, per the final
posix standard on the topic.


# 47be7466 23-Aug-1996 Julian Elischer <julian@FreeBSD.org>

Add support to halt, to allow it to request that the power be turned off
(the RB_POWEROFF flag)


# 7f4b19d6 20-Aug-1994 David Greenman <dg@FreeBSD.org>

Install aliases "fasthalt" and "fastboot" for halt and boot respectively.
This is for "backwards compatibility". Documented these aliases in the
manual page.


# 8fae3551 26-May-1994 Rodney W. Grimes <rgrimes@FreeBSD.org>

BSD 4.4 Lite sbin Sources

Note: XNSrouted and routed NOT imported here, they shall be imported with
usr.sbin.