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

sv status exit code for service masked by its log #20

Open
garthk opened this issue May 27, 2022 · 1 comment
Open

sv status exit code for service masked by its log #20

garthk opened this issue May 27, 2022 · 1 comment

Comments

@garthk
Copy link

garthk commented May 27, 2022

sv(8) says:

The sv program can be sym-linked to /etc/init.d/ to provide an LSB init script interface. The service to be controlled then is specified by the base name of the "init script".

If sv is called with a base name other than sv: it exits 1 on timeout or trouble sending the command; if the command is status, it exits 3 if the service is down, and 4 if the status is unknown; it exits 2 on wrong usage, and 151 on error.

This isn't entirely true. If the service has a log, the exit code instead reflects the status of the log. In src/sv.c:154-176 you'll see rc updated if chdir("log") and svstatus_get() succeed, after which the if (lsb) branch to the switch will call done reflecting the log's status.

This strikes me as a bug in the code, not the man page.

@Goorzhel
Copy link

Goorzhel commented Aug 6, 2022

I can reproduce this:

❯ fd -t f . /etc/sv/issue-20 -X head    
==> /etc/sv/issue-20/run <==
#!/bin/sh
echo 'Sleeping for 60 seconds.'
exec /usr/bin/sleep 60

==> /etc/sv/issue-20/log/run <==
#!/bin/sh
exec /usr/bin/false
❯ ls -l /etc/init.d/issue-20 
lrwxrwxrwx 1 root root 11 Aug  5 18:09 /etc/init.d/issue-20 -> /usr/bin/sv
❯ sudo /etc/init.d/issue-20 status
run: issue-20: (pid 8220) 44s; down: log: 1s, normally up, want up
❯ echo $?  # expecting 0
3

PR up momentarily.

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 a pull request may close this issue.

2 participants