Add reboot syscall#839
Conversation
|
The For rustix, it'd be ok to declare those constants as Also, |
Feels like we should do the same but localized for that module. Otherwise we risk diverging from the behavior of the libc backend
I wasn't actually sure about that myself but I'll move it there then |
|
I moved everything to system and properly documented everything. There are only a couple issues remaining:
|
|
On testing, I'd say it's enough to add a test that checks if the process has On |
That seems reasonable, I won't be able to work on this until monday so if someone else wants to tackle it that'd be swell
That's what I thought too but at the same time, it might be a chicken and egg problem where no one uses it because it's not implemented and no one implements it because it's not used. It's probably fine to ignore for now but it does make me wonder if rustix should provide an api that diverges from libc in some cases. I am not sure a project like this should bear the burden of the historical issues that plague libc/posix |
If you are specifically planning to use |
At first I was planning on using it but I am wondering if there is a technical reason to avoid it. It'd probably be trivial to implement it if necessary so I'll open another pr if needed |
|
The Linux I'm ok either way. We can add it, and use the |
LINUX_REBOOT_CMD_RESTART does also print a message so there is some kind of logging facility, I'm not sure that's the reason
I do not think it's a good idea to add it right now. I am not sure if I have a use case yet and I wouldn't want to implement something that's never used or worst case, shouldn't be used. I will investigate further the history of this command to see if it makes sense and open an appropiate issue then. If it turns out it's "bad" for some reason it might even be worth removing it entirely. I do actually wonder if we should include a warning of some kind or hide/remove it for now since it can't actually be called and will always cause an error if used. |
|
Yeah, if we don't add a way to pass the argument, we should remove |
I don't know if we should outright remove it. If we do then adding it back in the future for any reason would need a semver bump. Unless we mark the enum as non_exaustive, which might actually be a good idea regardless as it would future proof rustix in the unlikely event that the kernel adds more commands. |
|
Marking it non_exhaustive makes sense. |
|
I have added a test as discussed above, it should work fine but I think it might be worth thinking about a more thorough test suite in the future. I have also marked the enum as non_exhaustive and hidden the Restart2 variant. I think it should be ready to merge. |
| pub enum RebootCommand { | ||
| /// CAD is disabled. | ||
| /// This means that the CAD keystroke will cause a SIGINT signal to be sent to init (process 1), | ||
| /// whereupon this process may decide upon a proper action (maybe: kill all processes, sync, reboot). |
There was a problem hiding this comment.
My general goal for rustix is that we should either write documentation ourself, or link to Linux's documentation, but not copy and paste whole paragraphs from Linux's documentation. If we're copying and pasting, developers would often be better off referring to Linux's documentation, which often has more context. In this case, Linux's documentation includes context like what "CAD" stands for, and the fact that the key sequence can be changed.
I know that having docs in Rust comments is more convenient for Rust developers. On the other hand, this is reboot and it's not something anyone is going to be using on a regular basis, and it has some subtle behavior not included here, so it really would be better to encourage developers to read the Linux docs directly, rather than copying and pasting parts of them here.
There was a problem hiding this comment.
What would you recommend we do then? I copied and pasted it because I felt like it made sense but I can see it is missing a bunch of context. Maybe we can just not document it and refer user to the man page, something like reboot should probably not be touched by someone who hasn't read it.
There was a problem hiding this comment.
Yeah, I'd say leave most of the text out, perhaps just add short one-line descriptions if anything, and add a link to the Linux docs in RebootCommand's doc comment to help people find it.
|
I updated the docs the reboot function to be more clear about its usage. I also changed the RebootCommand docs to be a bit more friendly instead of just being copy-pasted from the man page. Now the ci is failing but I could swear I only update the docs unless I'm missing something |
|
Could you rebase this on origin/main? I expect that'll clear up the CI failures. |
Doesn't look like it worked. However I just realized that the latest commit is actually failing on main 707c51e |
|
I think the problem was a stale cache of the qemu build. I've now removed the old cache; could you try again? |
I think that solved the problem |
|
This is now released in rustix 0.38.17. |
This pr tries to implement a reboot syscall. Fixes #826.
Unfortunately I hit a roadblock so I'm opening a draft pr in hope of resolving it. To implement reboot we also need some constants defined in reboot.h. This are supposedly c_int (or i32) but the rust compiler tells me their out of range and refuses to compile them:
Perhaps I'm missing something obvious since the libc crate also defines them as c_int and compiles without issues. Any help would be appreciated.