8000 Make sure we don't kill ourselves if pgrep matches by daethnir · Pull Request #1 · dustinkirkland/run-one · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Make sure we don't kill ourselves if pgrep matches #1

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

daethnir
Copy link

pgrep could get confused when the command contains regular xpressions that match the run-* command itself, e.g. an argument like foo 'a|b'

$ cat /tmp/sleepforever
#!/bin/bash
echo Sleeping for 99 days...
sleep +99d



# version in HEAD
$ run-this-one /tmp/sleepforever
Sleeping for 99 days...
<ctrl-c>

$ run-this-one /tmp/sleepforever  "a|b"
Terminated

Run with -x you find the problem is this:

+ base=run-this-one
+ ps=/tmp/sleepforever a|b
+ pgrep -u wbagg -f ^/tmp/sleepforever a|b$
+ kill 768759
Terminated

pgrep is matching our run-this-one command and itself. The $$ check verifies that we don't kill run-this-one, the ps addition assures we don't kill the (no longer running) pgrep.

pgrep could get confused when the command contains regular
expressions that match the run-* command itself, e.g. an argument
like `foo 'a|b'`

* exclude our own pid from kill (check $$)
* exclude the pgrep process which was found bit is gone (ps before kill)
@daethnir
Copy link
Author

Note that there's still a race condition - if we find a matching process but it exits before we run kill then run-this-one fails because kill exits unsuccessfully. It may make sense to convert that to

kill $p || true

so we don't care about the exit code.

@daethnir
Copy link
Author

Posted bug at https://bugs.launchpad.net/ubuntu/+source/run-one/+bug/2081328

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.

1 participant
0