-
Notifications
You must be signed in to change notification settings - Fork 689
Add wrappers for posix_spawn related functions. #2007
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
Conversation
064f913
to
fe9e28b
Compare
CI failures seem to indicates that |
Hi @kosayoda, thanks for your interest in contributing to Nix! I am sorry that this PR hasn't been reviewed for such a long time! I plan to take a look at this PR in the near future (possibly 3 days later) :) |
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.
Hi, sorry for the late reply, I have left some comments, the PR generally looks great! Thanks for this!
if res != 0 { | ||
return Err(Errno::from_raw(res)); | ||
} |
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.
Nix has a nice syscall/libc-fn error handling function, we can use it here:
if res != 0 { | |
return Err(Errno::from_raw(res)); | |
} | |
Errno::result(res)?; |
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 think I should document this in CONVENTIONS.md
:<
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.
Emm, is this resolved?
Update: they seem to be accidentally reverted in https://github.com/nix-rust/nix/compare/13141854a4fd506765fb187344cb1ea5569dbe63..ab833286c906ffed4779fa08ce3643fd42f7316c
src/spawn.rs
Outdated
} | ||
|
||
// Specifically for use with posix_spawn and posix_spawnp. | ||
// https://github.com/rust-lang/libc/issues/1272 |
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.
IIUC, the interfaces exposed by the libc crate are actually correct (for posix_spawn and posix_spawnp), it is the POSIX standard's interfaces that are erroneous, so I think we do not need to link to that issue, simply documenting it like this would work:
// The POSIX standard requires those `args` and `envp` to be of type `*const *mut [c_char]`,
// but implementations won't modify them, making the `mut` type redundant. Considering this,
// Nix does not expose this mutability, but we have to change the interface when calling the
// underlying libc interfaces , this helper function does the conversion job.
//
// SAFETY:
// It is safe to add the mutability in types as implementations won't mutable them.
And we can remove the unsafe
keyword
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.
"implementations won't mutable them" I think you mean mutate here?
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.
"implementations won't mutable them" I think you mean mutate here?
Ahh, right, sorry for the typo:)
And we can remove the unsafe keyword
// SAFETY:
// It is safe to add the mutability in types as implementations won't mutable them.
Just realized tha we should not make this function safe but document the SAFETY
section in its usage
I think we can give it a test, perhaps simply spawning a child process and waiting for it would be good.
That's exactly what Nix is for! Even though some error cases won't happen with Nix interface, we don't do any thing special about the error handling and the return type:>
I guess yes? Standards are just standards, implementations can always do extra stuff. Though I think we don't need to do extra job here either as
You can test this locally if you can cross-compile for those targets. It is also ok if you don't, since our CI gets you covered
Emm, seems that the As for that allocation issue, do |
BTW, a CHANGELOG entry is needed, please see this on how to add one:) |
@kosayoda are you still working on this / would you mind if I tried picking it up? |
Close as superseded by #2475. |
Hello! This is my first PR to nix so I'd appreciate some guidance/patience.
This PR adds support for
posix_spawn*
related functions. All functions are added with the exception ofposix_spawnattr_{get, set}schedpolicy
andposix_spawnattr_{get, set}schedparam
, since those require fullsched.h
support not yet in nix.Implemented functions use I/O safe versions of file descriptors.
Blockers/Notes
posix_spawn
-related functions.Result
, as to my understanding even though the safe wrapper will prevent most failures listed by POSIX (eg.EINVAL
forposix_spawnattr_setflags
), implementations may return an error for other reasons not specified by the standard. Is that a correct assumption?cfg
), and if there is a way to determine that locally.posix_spawn*
currently take theargs
andenvp
arguments similar toexec*
functions, with slight modification due to The signature of "execv" | "execve" | "execvp" | "fexecve" is incorrect rust-lang/libc#1272. Can this be fixed together with Allocation in execv, execvp, and execve #555?In the meantime, existing code is ready for review.
Closes #1740.