aboutsummaryrefslogtreecommitdiff
path: root/sbin/reboot/reboot.c
Commit message (Collapse)AuthorAgeFilesLines
* reboot(8): add support for noshutdownKonstantin Belousov2025-07-221-0/+7
| | | | | | | | | | Similar to shutdown(8), refuse to reboot if /var/run/noshutdown is present. The -f option can be used to force operation. Reviewed by: imp Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D51241
* nextboot: Smarter warning about deleting nextbootWarner Losh2025-01-141-1/+16
| | | | | | | | | | | | | | | | | | | | | | Read only filesystems always error when trying to remove something with EROFS. However, that's true even if the file isn't there. The code assumed it would always get a ENOENT if the file wasn't there, but produced a gross message on read only systems. This message was harmless, but annoying. Instead, stat the file first and return if it's already not there. Some readings of POSIX require that the ENOENT error take precidence over the EROFS error. Linux made this change years ago, and we should too. POSIX.1-2024 isn't explicit, but does say for unlink() does say "[EROFS] The directory entry to be unlinked is part of a read-only file system" and "[ENOENT] A component of path does not name an existing file" implying that EROFS should only be returned for an existing file. FreeBSD doesn't implement this, so this workaround is necessary. Ideally, we'd fix this in the kernel in the future. Sponsored by: Netflix Discussed with: jrtc23 Differential Revision: https://reviews.freebsd.org/D48425
* nextboot: Permit ZFS boot filesystems mounted at the pool's rootJohn Baldwin2024-05-301-3/+3
| | | | | | | | | | 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
* nextboot: Write nextboot.conf safelyMark Johnston2024-04-031-9/+29
| | | | | | | | | | 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
* nextboot: check unlink, but only warn on !ENOENTWarner Losh2024-02-221-1/+2
| | | | | | | | | | 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
* reboot: Emulate nextboot -D betterWarner Losh2024-02-211-2/+1
| | | | | | | | | 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
* nextboot: fix nextboot -k on ZFSGleb Smirnoff2024-02-201-0/+5
| | | | | | | zfsbootcfg(1) expects pool name to operate on, not currently mounted filesystem name. Fixes: fd6d47375a78fbf0737012b7cc11180291781e8b
* nextboot: fix typo that merged two args into oneGleb Smirnoff2024-02-201-1/+1
| | | | Fixes: fd6d47375a78fbf0737012b7cc11180291781e8b
* reboot: Move extern for environWarner Losh2024-02-181-1/+2
| | | | | | | | 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
* reboot: Remove sys/types.h: it's not needed here...Warner Losh2024-02-181-1/+0
|
* reboot: Use posix_spawn instead of systemWarner Losh2024-02-161-16/+38
| | | | | | | | | 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
* reboot: initialize howtoWarner Losh2024-02-151-1/+2
| | | | | | | 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.
* reboot: Allow this to be installed as nextbootWarner Losh2024-02-121-8/+26
| | | | | | | | | | 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
* reboot: Implement -o to set kernel options for next bootWarner Losh2024-02-121-1/+4
| | | | | | Sponsored by: Netflix Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D43829
* reboot: Implement -k in terms of envWarner Losh2024-02-121-7/+6
| | | | | | | | | 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
* reboot: Implement -e from nextbootWarner Losh2024-02-121-4/+45
| | | | | | | | 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
* reboot: Implement zfs supportWarner Losh2024-02-121-9/+49
| | | | | | | | | | | | | | | | | | 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
* reboot: Implement -D from nextbootWarner Losh2024-02-121-3/+14
| | | | | | | | Implement -D from nextboot.sh which deletes the nextboot.conf file and exists. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D43822
* reboot: Add sanity checking of write to nextboot.confWarner Losh2024-02-121-10/+37
| | | | | | | | | | 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
* reboot: Don't reboot if the next kernel isn't thereWarner Losh2024-02-121-2/+19
| | | | | | | | | | 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
* reboot: convert flags to boolsWarner Losh2024-02-121-11/+13
| | | | | | | | | 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
* reboot: Disallow -k and -r, it doesn't make sense.Warner Losh2024-02-121-0/+2
| | | | | | | | | 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
* Remove copyright strings ifdef'd outWarner Losh2023-11-271-9/+0
| | | | | | | | | | | 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
* sbin: Remove ancient SCCS tags.Warner Losh2023-11-271-3/+0
| | | | | | | | 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
* reboot(8): print syscall error on sysctl failureKonstantin Belousov2023-11-131-1/+1
| | | | | | | Noted by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D42561
* reboot(8): adapt for vmmeter v_swappgsin expansion to 64bitKonstantin Belousov2023-11-131-5/+5
| | | | | | | | | | 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
* Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-161-2/+0
| | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
* Mark usage function as __dead2 in programs where it does not returnAlfonso Gregory2023-07-071-1/+1
| | | | | | | | 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
* boottrace: annotate init and shutdown utilitiesMitchell Horne2022-02-221-2/+8
| | | | | | | | | | 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
* Fix "fasthalt" to halt instead of rebootEric van Gyzen2018-09-141-1/+1
| | | | | | | | | | | | 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 Notes: svn path=/head/; revision=338688
* Exit with usage when extra arguments are on command lineRodney W. Grimes2018-04-051-0/+2
| | | | | | | | | preventing mistakes such as "halt 0p" for "halt -p". Approved by: bde (mentor), phk (mentor) MFC after: 1 week Notes: svn path=/head/; revision=332075
* General further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-201-1/+3
| | | | | | | | | | | | | | | | | 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. Notes: svn path=/head/; revision=326025
* Add -c to the usage statements.Warner Losh2017-10-311-2/+2
| | | | | | | Submitted by: Maxim Konovalov Notes: svn path=/head/; revision=325206
* Add power cycle support to reboot/halt as -c.Warner Losh2017-10-251-2/+13
| | | | | | | | | | | 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 Notes: svn path=/head/; revision=324986
* Renumber copyright clause 4Warner Losh2017-02-281-1/+1
| | | | | | | | | | | | 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 Notes: svn path=/head/; revision=314436
* Add missing parameters -N and -l to reroot and halt usage()Renato Botelho2016-05-061-2/+2
| | | | | | | | | Approved by: bapt Sponsored by: Rubicon Communications (Netgate) Differential Revision: https://reviews.freebsd.org/D6173 Notes: svn path=/head/; revision=299196
* Fix use of uninitialised NflagSteven Hartland2015-12-301-1/+1
| | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=292947
* Add flag to disable inital reboot(8) userland syncSteven Hartland2015-12-151-2/+8
| | | | | | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=292266
* Userspace part of reroot support. This makes it possible to changeEdward Tomasz Napierala2015-11-081-1/+19
| | | | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=290548
* Let reboot(8) use getprogname() to compare the program name.Ed Schouten2011-12-111-3/+3
| | | | | | | | While there, mark the global variable dohalt static, as reboot(8) only consists of a single C file. Notes: svn path=/head/; revision=228408
* Port the remaining apps in sbin/ to utmpx; only reboot(8).Ed Schouten2010-01-131-2/+1
| | | | Notes: svn path=/head/; revision=202195
* Add forgotten `void' keyword. This function has no arguments.Ed Schouten2009-12-291-1/+1
| | | | Notes: svn path=/head/; revision=201182
* Let init(8) and reboot(8) use utmpx to log wtmp entries.Ed Schouten2009-12-051-2/+7
| | | | | | | | | | | 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(). Notes: svn path=/head/; revision=200161
* More rational usage()Dag-Erling Smørgrav2009-11-101-3/+5
| | | | Notes: svn path=/head/; revision=199130
* Remove and unused variable.Bjoern A. Zeeb2009-01-311-2/+1
| | | | | | | | Submitted by: Christoph Mallon christoph.mallon@gmx.de MFC after: 2 weeks Notes: svn path=/head/; revision=187956
* Block a variety of signals which may afffect reboot(8), before killingBruce M Simpson2006-08-021-2/+15
| | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=160916
* Block SIGHUP before killing init(8), to avoid a race condition which mayBruce M Simpson2006-08-021-3/+3
| | | | | | | | | | | kill the current process and hang the system when attempting reboot. PR: bin/64664 Reviewed by: ssouhal, phk (historic) MFC after: 30 days Notes: svn path=/head/; revision=160914
* Truncate nextboot.conf file on creation, so existing garbage will be removed.Pawel Jakub Dawidek2005-03-211-1/+2
| | | | | | | | | Submitted by: Gary Allan <dragonfly@gallan.plus.com> Obtained from: DragonFlyBSD MFC after: 3 days Notes: svn path=/head/; revision=143948
* Sync program's usage() with manpage's SYNOPSIS.Ruslan Ermilov2005-02-101-2/+2
| | | | Notes: svn path=/head/; revision=141611
* Code style tweaks: Use static and const where suitable.Xin LI2005-01-251-7/+6
| | | | Notes: svn path=/head/; revision=140795