-
Notifications
You must be signed in to change notification settings - Fork 672
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
Add gettid #293
Add gettid #293
Conversation
25e50fb
to
8264a61
Compare
Although OSX has
|
It should be noted that libc does expose Use of That being said, I can still imagine use cases where getting access to |
I am not sure it can be added to libc as a function in that case. The syscall number could and should be added though. We have a similar situation with |
Ah I might have found a thing to do on this lazy Saturday afternoon. At least until I go ice skating... :-) |
It turns out I am blind. We are already using the libc getpid/getppid. More time for skating I guess. |
I'm happy to only expose gettid for linux and not for OSX, I just don't know how to do that on the rust side. The SYS_gettid constant is different for different platforms (i.e. arm, 32-bit, and 64-bit x86 all have different constants for SYS_gettid) otherwise I could have done the syscall from rust. Maybe there's a way to create rust constants? |
And @kamalmarhubi is correct, glibc doesn't have a geittid function to expose, which is why the syscall needs to be done directly. Personally, I find it exremely useful to have the tid exposed as shows up in the ps listing (i.e. ps -T shows both pids and tids) and pthread_self would not be useful in this situation. Or for examining /proc/PID/task/TID. |
The right thing to do would be put them in the libc hierarchy, one of the files in here: |
The pattern is something like this: #[cfg(target_os = "linux")]
pub fn gettid() -> pid_t {
...
} Though here you probably want |
Ahh - ok - I'll have a go at adding SYS_gettid in libc then. |
☔ The latest upstream changes (presumably #294) made this pull request unmergeable. Please resolve the merge conflicts. |
I just got SYS_gettid merged into rust-lang/libc (rust-lang/libc#209), so I need to rework this anyways, since I can now do a rust-only solution. |
👍 :-) |
Well done 👍 |
I've updated the PR, but it can't be merged until libc releases 0.2.8 (and then I'll need to update the Cargo.toml file as well). It also looks like I got the type wrong on SYS_gettid, so I put through a libc PR to fix that: rust-lang/libc#213 I can build nix-rust locally (by redirecting libc to my local copy). I had a question about the "as i32" and whether I should use |
7814167
to
17b256b
Compare
Updated PR to use libc 0.2.8 and the one test that doesn't pass seems unrelated (it's for darwin and this PR should only affect linux). The same build on my repository was green: This PR adds a gettid by doing a syscall using libc::SYS_gettid |
@dhylands thanks! You're right, |
@@ -56,6 +56,12 @@ pub fn setpgid(pid: pid_t, pgid: pid_t) -> Result<()> { | |||
Errno::result(res).map(drop) | |||
} | |||
|
|||
#[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.
could you make this #[cfg(any(target_os = "linux", target_os = "android"))]
?
Just a minor change to the conditional compilation, and this is good to go! Thanks! |
ok - fixed up the conditionals. I had to make a few other changes as the tests started to fail in other mysterious ways, so I followed a pattern I found elsewhere in the test files. The only failure is the test_semwait on darwin. |
Made the test retry and it works. @homu r+ |
📌 Commit ca75212 has been approved by |
Thanks @dhylands!! |
⚡ Test exempted - status |
Add gettid I tested this under linux, and I noticed that this seems to also be built for OSX. It would be appreciated if someone could test this under OSX. I'm not familiar enough with rust to know if there is a way of integrating this without creating a sub-crate.
What do you mean by this? Sounds like something we should document if it wasn't clear. |
Of course, I tried to go back and reproduce the problem and can't any more. I was seeing local failures (when running cargo test locally) related to wait and execvpe. It was probably something stale in my build or tree or something. |
The wait and execvpe problems are related to thread parallelism and should not happen with |
I've got some ideas for fixing the tests (#251) which I'll try and do this week... |
@kamalmarhubi Excellent, look forward to seeing what you come up with. As an aside, I put out a feeler in a reddit thread for suggestions on testing out systems code in rust without a good mocking framework: https://www.reddit.com/r/rust/comments/494tkf/looking_for_suggestions_mocking_external_functions/ Calling the actual system calls only lets us test the happy path (and even then not always as consistently as we would like). |
Moving conversation to #251 |
I tested this under linux, and I noticed that this seems to also be built for OSX. It would be appreciated if someone could test this under OSX.
I'm not familiar enough with rust to know if there is a way of integrating this without creating a sub-crate.