feat: reboot(2) for OpenBSD/NetBSD#2251
Conversation
| /// For more information, see [`reboot(2)`](https://man.netbsd.org/reboot.2). | ||
| #[cfg(target_os = "netbsd")] | ||
| pub fn reboot<S: AsRef<OsStr>>(how: RebootMode, bootstr: S) -> Result<Infallible> { | ||
| let bootstr = bootstr.as_ref().as_bytes().as_ptr().cast_mut().cast(); |
There was a problem hiding this comment.
int reboot(int howto, char *bootstr);
fn reboot(mode: ::c_int, bootstr: *mut ::c_char) -> ::c_int;If the underlying shutdown procedure will modify bootstr, then we will get a UB here. I am not sure if reboot(2) would change it or not, the manual does not mention this:
bootstris a string passed to the firmware on the machine, if possible, if this option is set. Currently this is only implemented on the sparc and the sun3 ports.
But practically, it has little point in writing to that piece of memory given that everything will be gone after shutdown.
There was a problem hiding this comment.
The man page seems to suggest that bootstr is entirely ignored unless RB_STRING is specified, and that can only happen on sparc64. So I suggest that we simply remove this argument and the RB_STRING flag until such a time as there is a least one known user of Nix on sparc64-unknown-netbsd.
| } | ||
|
|
||
| /// Reboots or shuts down the system. | ||
| #[cfg(target_os = "linux")] |
There was a problem hiding this comment.
This line is redundant with line 11
| #[cfg(target_os = "linux")] |
There was a problem hiding this comment.
I am sorry about this, removed
| /// Enable or disable the reboot keystroke (Ctrl-Alt-Delete). | ||
| /// | ||
| /// Corresponds to calling `reboot(RB_ENABLE_CAD)` or `reboot(RB_DISABLE_CAD)` in C. | ||
| #[cfg(target_os = "linux")] |
There was a problem hiding this comment.
This line too.
| #[cfg(target_os = "linux")] |
| /// `init(8)`) other than `/sbin/init` to be run when the system | ||
| /// reboots. | ||
| /// | ||
| /// This switch is not currently available. |
There was a problem hiding this comment.
What does it mean that it isn't currently available? Does that mean that NetBSD defines it but does not implement it? If so, I think that Nix shouldn't expose it.
There was a problem hiding this comment.
| /// on the machine, if possible, if this option is set. | ||
| /// | ||
| /// Currently this is only implemented on the sparc and the sun3 ports. | ||
| #[cfg(target_os = "netbsd")] |
There was a problem hiding this comment.
Let's define it for sparc64 only. It looks like NetBSD doesn't have a Rust package for sun3, so we don't have to worry about that. https://ftp.netbsd.org/pub/pkgsrc/current/pkgsrc/lang/rust/index.html
| #[cfg(target_os = "netbsd")] | |
| #[cfg(all(target_os = "netbsd", target_arch = "sparc64"))] |
There was a problem hiding this comment.
This flag and that bootstr argument are now removed
| /// For more information, see [`reboot(2)`](https://man.netbsd.org/reboot.2). | ||
| #[cfg(target_os = "netbsd")] | ||
| pub fn reboot<S: AsRef<OsStr>>(how: RebootMode, bootstr: S) -> Result<Infallible> { | ||
| let bootstr = bootstr.as_ref().as_bytes().as_ptr().cast_mut().cast(); |
There was a problem hiding this comment.
The man page seems to suggest that bootstr is entirely ignored unless RB_STRING is specified, and that can only happen on sparc64. So I suggest that we simply remove this argument and the RB_STRING flag until such a time as there is a least one known user of Nix on sparc64-unknown-netbsd.
eab2bf4 to
d48d66a
Compare
What does this PR do
Implements
reboot(2)for NetBSD/OpenBSD, closes #2174.Manual:
The
RebootModetype, different from the one defined on Linux, is a bitflag rather than an enum, so I defined a new type. On NetBSD, there is aRebootModeRB_RDONLY:which is deprecated, so I didn't add it.
Checklist:
CONTRIBUTING.md