8000 [Bug] `ParseIntError` in `getpid`. · Issue #45 · mdgaziur/findex · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[Bug] ParseIntError in getpid. #45

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

Closed
monomycelium opened this issue Oct 29, 2023 · 3 comments
Closed

[Bug] ParseIntError in getpid. #45

monomycelium opened this issue Oct 29, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@monomycelium
Copy link
monomycelium commented Oct 29, 2023

When I run findex-daemon even though there are a few instances of findex running, I get the following error:

thread 'main' panicked at crates/findex-daemon/src/main.rs:32:28:
called `Result::unwrap()` on an `Err` value: ParseIntError { kind: InvalidDigit }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

After digging in, I realised that the pidof command uses a space to separate multiple PIDs by default (see man), while getpid splits the output using newline bytes. A simple solution is to split using spaces:

--- crates/findex-daemon/src/main.rs.old        2023-10-29 15:20:31.918921390 +0800
+++ crates/findex-daemon/src/main.rs    2023-10-29 15:20:38.391694935 +0800
@@ -24 +24 @@
-        .split('\n')
+        .split(' ')

However, this feels like a naive way as not all Linux systems have procps-ng out of the box. Instead, you could use the processes_by_name method of the sysinfo crate. Of course, that comes at the expense of the binary size. (But this is Rust after all, right?)

Of course, the simpler way would be to store the PIDs in the filesystem (like in /var/run). This way, we would not have to execute syscalls repeatedly. When the process exits, the PID can be removed from the store. (If that is too hard to implement, you could simple use kill(2) with a 0 signal to check if there a process with that PID is running.)

References

@monomycelium monomycelium added the bug Something isn't working label Oct 29, 2023
@mdgaziur
Copy link
Owner

Hi there! Thanks for reporting this issue. I'm looking into this.

mdgaziur added a commit that referenced this issue Nov 1, 2023
Thanks to @monomycelium for suggestions.
mdgaziur added a commit that referenced this issue Nov 1, 2023
Thanks to @monomycelium for suggestions.
@monomycelium
Copy link
Author

Thank you for accepting my suggestion. The latest commit has solved the issue for me.

@mdgaziur
Copy link
Owner
mdgaziur commented Nov 2, 2023

You're welcome 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants
0