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

Expose termination signal option in clone #343

Closed
tailhook opened this issue Apr 7, 2016 · 9 comments · Fixed by #344
Closed

Expose termination signal option in clone #343

tailhook opened this issue Apr 7, 2016 · 9 comments · Fixed by #344
Labels

Comments

@tailhook
Copy link
Contributor

tailhook commented Apr 7, 2016

I'm talking about this commit:
53cae89

The issue is that according to a man page you need to mix a signal name to a flags in clone function, like this:

pid = clone(childFunc, stackTop, CLONE_NEWUTS | SIGCHLD, argv[1]);

But with bitflags you can't do it. E.g. CloneFlags::from_bits(SIGCHLD) returns None.

Any good idea how to fix it? Revert the commit?

@fiveop
Copy link
Contributor

fiveop commented Apr 7, 2016

I would prefer to change the signature of clone to take two parameters, which we then combine in the function. This way we can have our cake and eat it too :)

Thank you for reporting the issue.

@tailhook
Copy link
Contributor Author

tailhook commented Apr 7, 2016

@fiveop, well, in the docs there are variable argument list for the clone system call. So adding an argument might confuse users.

Maybe some another type, like struct CloneConfig(CloneFlags, i32) ? Or just a tuple?

@fiveop
Copy link
Contributor

fiveop commented Apr 7, 2016

Our wrapper does not pass any additional arguments currently. And even if we did, I would prefer not to create a type for that. However, documentation for our wrapper would certainly help. Lamentably, this holds for pretty much all of nix-rust.

@tailhook
Copy link
Contributor Author

tailhook commented Apr 7, 2016

Our wrapper does not pass any additional arguments currently

Sure. I mean if I see clone(a, b, c, d) I believe that I can just look at man clone to find out what the arguments mean. I don't think it's reasonable to make documentation better than linux man, so people will always look at man pages on system calls to reason how this system call work.

kamalmarhubi added a commit to kamalmarhubi/nix-rust that referenced this issue Apr 12, 2016
DO NOT MERGE: proof of concept for comment

Fixes nix-rust#343
@kamalmarhubi kamalmarhubi changed the title Converting CloneFlags to a bitflags was probably a mistake Expose termination signal option in clone Apr 18, 2016
@kamalmarhubi
Copy link
Member

On #348, we came to the conclusion that directly following libc's flags | termination_signal parameter doesn't make sense, even though it's possible via std::ops::BitOr. @posborne said it very clearly:

I've come around to the argument that in this case having a separate argument exposed from nix for signal/flags probably makes most sense. The combination of the signal/flags in the kernel interface (and libc by extension) appears to be purely an optimization.

@kamalmarhubi
Copy link
Member

In terms of "maximal Rustiness", at least for matching the APIs in libstd, I think something like this would work:

struct CloneOptions {
    flags : CloneFlags,
    termination_signal: Signal,
}

impl CloneOptions {
    pub fn new() -> CloneOptions { ... }
    pub fn flags(&mut self, flags: CloneFlags) -> &mut CloneOptions { ... }
    pub fn termination_signal(&mut self, signal: Signal) -> &mut CloneOptions { ... }
    pub fn clone(&self, stack: &mut [u8], mut cb: CloneCb) -> Result<pid_t> { ... }
}

This would get used like this:

let stack = vec![0u8; 1024 * 1024];
let child_pid = CloneOptions::new().flags(CLONE_NEWUSER | CLONE_NEWNS)
                                   .termination_signal(SIGUSR1)
                                   .clone(&mut stack[..], || { ... })
                                   .expect("clone");

@kamalmarhubi
Copy link
Member

NB I don't think this fits in our current API style, but does fit a vision that @carllerche for either base nix or a higher level crate on top.

@tailhook
Copy link
Contributor Author

Well, I don't think we should make it so complex. From #348 it looks like most people are comfortable with a separate argument. I think we should do it and move on.

@fiveop
Copy link
Contributor

fiveop commented Apr 21, 2016

Which I implemented in my #344.

@homu homu closed this as completed in #344 Apr 21, 2016
homu added a commit that referenced this issue Apr 21, 2016
Allow to specify signal when calling clone.

This is my suggestion on how to fix #343.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants