-
Notifications
You must be signed in to change notification settings - Fork 666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: reboot(2) for OpenBSD/NetBSD #2251
Conversation
src/sys/reboot.rs
Outdated
/// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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:
bootstr
is 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
argument removed
src/sys/reboot.rs
Outdated
} | ||
|
||
/// Reboots or shuts down the system. | ||
#[cfg(target_os = "linux")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is redundant with line 11
#[cfg(target_os = "linux")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am sorry about this, removed
src/sys/reboot.rs
Outdated
/// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line too.
#[cfg(target_os = "linux")] |
src/sys/reboot.rs
Outdated
/// `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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/sys/reboot.rs
Outdated
/// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This flag and that bootstr
argument are now removed
src/sys/reboot.rs
Outdated
/// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
RebootMode
type, different from the one defined on Linux, is a bitflag rather than an enum, so I defined a new type. On NetBSD, there is aRebootMode
RB_RDONLY
:which is deprecated, so I didn't add it.
Checklist:
CONTRIBUTING.md