Discussion:
[systemd-devel] Return codes of systemctl (status)
Cecil Westerhof
2018-08-16 11:27:12 UTC
Permalink
The man page of systemctl says:
On success, 0 is returned, a non-zero failure code otherwise.

When I do a systemctl status on a service that is not running I get a 3.
What other values can be returned and where do I find those?
--
Cecil Westerhof
Ryan Gonzalez
2018-08-16 14:35:00 UTC
Permalink
I believe the errors are based on errno:
http://www.virtsync.com/c-error-codes-include-errno

Return status 3 -> ESRCH -> No such process
Post by Cecil Westerhof
On success, 0 is returned, a non-zero failure code otherwise.
When I do a systemctl status on a service that is not running I get a 3.
What other values can be returned and where do I find those?
--
Cecil Westerhof
_______________________________________________
systemd-devel mailing list
https://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
Ryan (ラむアン)
Yoko Shimomura, ryo (supercell/EGOIST), Hiroyuki Sawano >> everyone else
https://refi64.com/
Cecil Westerhof
2018-08-16 16:09:20 UTC
Permalink
I believe the errors are based on errno: http://www.virtsync.com
/c-error-codes-include-errno
Return status 3 -> ESRCH -> No such process
Thanks I will look into that.


I think it is not completely correct. For example if I do:
systemctl status dummy

This gives as description:
Unit dummy.service could not be found.

And the error code that is returned is 4.
I would not say that a non existing service is an interrupted service call.
I would find 22 (invalid argument) more logical. But it all depends how you
interpret things.
Post by Cecil Westerhof
On success, 0 is returned, a non-zero failure code otherwise.
When I do a systemctl status on a service that is not running I get a 3.
What other values can be returned and where do I find those?
--
Cecil Westerhof
Dave Reisner
2018-08-16 16:18:57 UTC
Permalink
    On success, 0 is returned, a non-zero failure code otherwise.
When I do a systemctl status on a service that is not running I get a 3.
What other values can be returned and where do I find those?
I believe exit codes are meant to conform to LSB specs:

http://refspecs.linuxbase.org/LSB_3.0.0/LSB-PDA/LSB-PDA/iniscrptact.html

In general, I'd suggest not depending on the specific values, but
instead using a more appropriate verb. For example, if you want to
know that a service is running, is 'systemctl is-active'.

dR
Filipe Brandenburger
2018-08-16 16:51:54 UTC
Permalink
Post by Dave Reisner
Post by Cecil Westerhof
On success, 0 is returned, a non-zero failure code otherwise.
When I do a systemctl status on a service that is not running I get a 3.
What other values can be returned and where do I find those?
http://refspecs.linuxbase.org/LSB_3.0.0/LSB-PDA/LSB-PDA/iniscrptact.html
Yes, that is correct.

See comments and enum here:
https://github.com/systemd/systemd/blob/v239/src/systemctl/systemctl.c#L80
Post by Dave Reisner
In general, I'd suggest not depending on the specific values, but
instead using a more appropriate verb.
Agreed. In particular, man page for systemctl simply says "on success,
0 is returned, a non-zero failure code otherwise" for exit status. In
other words, the specific non-zero exit codes are undocumented, so
shouldn't be relied upon.

Cheers,
Filipe
Cecil Westerhof
2018-08-16 17:05:20 UTC
Permalink
Post by Filipe Brandenburger
Agreed. In particular, man page for systemctl simply says "on success,
0 is returned, a non-zero failure code otherwise" for exit status. In
other words, the specific non-zero exit codes are undocumented, so
shouldn't be relied upon.
Personally I would say that when asking the status of a non running service
is not a failure, but that does return a 3. So I have to catch that.
--
Cecil Westerhof
Cecil Westerhof
2018-08-16 17:02:48 UTC
Permalink
Post by Dave Reisner
Post by Cecil Westerhof
On success, 0 is returned, a non-zero failure code otherwise.
When I do a systemctl status on a service that is not running I get a 3.
What other values can be returned and where do I find those?
http://refspecs.linuxbase.org/LSB_3.0.0/LSB-PDA/LSB-PDA/iniscrptact.html
That is quite an interesting bit of info. :-D
Post by Dave Reisner
In general, I'd suggest not depending on the specific values, but
instead using a more appropriate verb. For example, if you want to
know that a service is running, is 'systemctl is-active'.
The problem is that I use the commands from Tcl. I use the output, but when
using exec Tcl has 'a problem' with non zero codes. When I ask the status
of a service it can return a 0, 3, or 4. When returning a 3 that is not a
real error and I should inhibit the throw. If it is a 4 (service does not
exist) it is a real error and I should let the throw be fired.
--
Cecil Westerhof
Lennart Poettering
2018-09-10 17:52:36 UTC
Permalink
Post by Dave Reisner
    On success, 0 is returned, a non-zero failure code otherwise.
When I do a systemctl status on a service that is not running I get a 3.
What other values can be returned and where do I find those?
http://refspecs.linuxbase.org/LSB_3.0.0/LSB-PDA/LSB-PDA/iniscrptact.html
In general, I'd suggest not depending on the specific values, but
instead using a more appropriate verb. For example, if you want to
know that a service is running, is 'systemctl is-active'.
This is correct. This is supposed to match LSB status exit codes, but
the mapping is a bit skewed due to different semantics.

In general we return 0 on success, non-zero otherwise, but "systemctl
status" (and a few verbs like it) do this differently to match LSB. We
should probably document that better. I filed a bug requesting this
now, so that we keep track of this.

https://github.com/systemd/systemd/issues/10056

Lennart
--
Lennart Poettering, Red Hat
Loading...