diff --git a/man/sd_event_exit.xml b/man/sd_event_exit.xml index ccbd0455090..aa3bc29e98d 100644 --- a/man/sd_event_exit.xml +++ b/man/sd_event_exit.xml @@ -65,9 +65,11 @@ the exit code stored in the event loop object is updated, but otherwise no further operation is executed. - sd_event_get_exit_code() may be used to - query the exit code passed into - sd_event_exit() earlier. + sd_event_get_exit_code() may be used to query the exit code passed to an + earlier call of sd_event_exit(). The return parameter code + may be set to NULL, in order to simply check if sd_event_exit() + has been called before (as sd_event_get_exit_code() fails with + -ENODATA if that's not the case, see below). While the full positive and negative integer ranges may be used for the exit code, care should be taken not pick exit codes that @@ -122,7 +124,8 @@ -ENODATA - The event loop has not been requested to exit yet. + Returned by sd_event_get_exit_code() in case the event loop has not + been requested to exit yet. diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c index c651d595026..12aa9805938 100644 --- a/src/libsystemd/sd-event/sd-event.c +++ b/src/libsystemd/sd-event/sd-event.c @@ -4915,13 +4915,13 @@ _public_ int sd_event_get_state(sd_event *e) { _public_ int sd_event_get_exit_code(sd_event *e, int *code) { assert_return(e, -EINVAL); assert_return(e = event_resolve(e), -ENOPKG); - assert_return(code, -EINVAL); assert_return(!event_origin_changed(e), -ECHILD); if (!e->exit_requested) return -ENODATA; - *code = e->exit_code; + if (code) + *code = e->exit_code; return 0; }