Skip to content
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

unistd: add fexecve() #727

Merged
merged 1 commit into from
Aug 20, 2017
Merged

unistd: add fexecve() #727

merged 1 commit into from
Aug 20, 2017

Conversation

lucab
Copy link
Contributor

@lucab lucab commented Aug 9, 2017

This adds fexecve(). It is available in libc since 0.2.29.

Ref: http://pubs.opengroup.org/onlinepubs/9699919799/functions/fexecve.html

Copy link
Member

@asomers asomers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Don't forget to add a CHANGELOG entry.

src/unistd.rs Outdated
///
/// If an error occurs, this function will return with an indication of the
/// cause of failure. See
/// [fexecve(3)#errors](http://man7.org/linux/man-pages/man3/fexecve.3.html#ERRORS)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since fexecve is not linux-specific, could you please link to the Open Group man page instead?

@Susurrus
Copy link
Contributor

One thing that hasn't been addressed with this functions is their use of CString as arguments. This is partially touched on in #358.

@lucab
Copy link
Contributor Author

lucab commented Aug 11, 2017

@asomers amended after review, PTAL.

@Susurrus right. For reference this is also affected by #594. I don't have good answers/proposals for any of those. I would refrain from tackling those here, I can personally accept a later breaking change around this.

src/unistd.rs Outdated
/// command that is run. On success, this function will not return. Instead,
/// the new program will run until it exits.
///
/// If an error occurs, this function will return with an indication of the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be in an "Errors" section (see the book).

src/unistd.rs Outdated
/// [fexecve(2)#errors](http://pubs.opengroup.org/onlinepubs/9699919799/functions/fexecve.html#tag_16_111_05)
/// for a list of error conditions.
///
/// This function is similar to `execve`, except that the program to be executed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this above the errors section.

@lucab
Copy link
Contributor Author

lucab commented Aug 11, 2017

@Susurrus docstring amended.

@Susurrus
Copy link
Contributor

@asomers Can you confirm that your review changes have been addressed?

@lucab Any way we can implement some tests for this? Or maybe even some code examples?

@lucab
Copy link
Contributor Author

lucab commented Aug 16, 2017

I have a full example/demo at https://github.com/lucab/fxe-rs. Not sure if you want to extrapolate anything from there, as it makes more sense as part of the whole explanation.

Regarding tests, I guess I can try adapting this test macro to receive the first exec parameter from the outside.

@Susurrus let me know if you want me too add more stuff in here, or if it is fine already fine having an external demo/consumer for the moment.

@Susurrus
Copy link
Contributor

@lucab That'd be great if you could get a test working for this! The examples aren't as important, I just want something in-tree that uses this code, and having a test is the best, an example is second-best, and we're trying to avoid adding anything that doesn't include tests.

@lucab
Copy link
Contributor Author

lucab commented Aug 16, 2017

@Susurrus pushed one more commit with the test (CI is mostly green by now but still ongoing). PTAL.

@Susurrus
Copy link
Contributor

LGTM. @asomers can you wrap up your review? Then I think we're ready to merge!

@Susurrus
Copy link
Contributor

There are build failures on mac because fexecve is declared there in libc, but doesn't actually exist. Can you remove it from macos and ios for this PR? I've already filed some work with upstream to be libc cleaned up (rust-lang/libc#732).

@lucab
Copy link
Contributor Author

lucab commented Aug 17, 2017

@Susurrus I feel that bad that I didn't catch this when wiring-in the libc bits. Thanks for spotting it and promptly fixing there. I've amended to exclude macos/ios, CI is greeen now.

src/unistd.rs Outdated
/// cause of failure. See
/// [fexecve(2)#errors](http://pubs.opengroup.org/onlinepubs/9699919799/functions/fexecve.html#tag_16_111_05)
/// for a list of error conditions.
#[cfg(not(any(target_os = "macos", target_os = "ios")))]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We prefer to use white-lists here instead of black-lists as it makes it easier to support new platforms. Can you change this and the other ones below?

@@ -156,6 +150,15 @@ macro_rules! execve_test_factory(
)
);

#[cfg(not(target_os = "android"))]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be cleaner if you use cfg_if! and group the platform-specific code together.

@Susurrus
Copy link
Contributor

@lucab No worries. I have a Mac, so i wanted to check that support for it was in fact missing as I assumed you didn't have access to one (most people don't). Not a big deal at all!

@asomers
Copy link
Member

asomers commented Aug 17, 2017

Don't forget to squash your commits before we merge.

This adds fexecve() to `nix::unistd`. It is available in libc since 0.2.29.

Ref: http://pubs.opengroup.org/onlinepubs/9699919799/functions/fexecve.html
@lucab
Copy link
Contributor Author

lucab commented Aug 18, 2017

@Susurrus I've switched to cfg_if! and turned all conditionals into explicit whitelists, PTAL. (I am however not really sure this is the aesthetic result you were suggesting; if you had something different in mind, feel free to explicitly detail how you wanted this to look like)

@Susurrus
Copy link
Contributor

Awesome, this looks pretty solid, thanks @lucab!

bors r+

bors bot added a commit that referenced this pull request Aug 20, 2017
727: unistd: add fexecve() r=Susurrus

This adds fexecve(). It is available in libc since 0.2.29.

Ref: http://pubs.opengroup.org/onlinepubs/9699919799/functions/fexecve.html
@bors
Copy link
Contributor

bors bot commented Aug 20, 2017

@bors bors bot merged commit d9f1b3d into nix-rust:master Aug 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants