]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-event: make return code of sd_event_get_exit_code() optional
authorLennart Poettering <lennart@poettering.net>
Fri, 23 Feb 2024 20:51:02 +0000 (21:51 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 1 Mar 2024 21:25:42 +0000 (22:25 +0100)
man/sd_event_exit.xml
src/libsystemd/sd-event/sd-event.c

index ccbd04550905b141cc7ebb653f3ab68e691d8c9f..aa3bc29e98d1e9138d5235db4c330468d457348a 100644 (file)
     the exit code stored in the event loop object is updated, but
     otherwise no further operation is executed.</para>
 
-    <para><function>sd_event_get_exit_code()</function> may be used to
-    query the exit code passed into
-    <function>sd_event_exit()</function> earlier.</para>
+    <para><function>sd_event_get_exit_code()</function> may be used to query the exit code passed to an
+    earlier call of <function>sd_event_exit()</function>. The return parameter <parameter>code</parameter>
+    may be set to <constant>NULL</constant>, in order to simply check if <function>sd_event_exit()</function>
+    has been called before (as <function>sd_event_get_exit_code()</function> fails with
+    <constant>-ENODATA</constant> if that's not the case, see below).</para>
 
     <para>While the full positive and negative integer ranges may be used
     for the exit code, care should be taken not pick exit codes that
         <varlistentry>
           <term><constant>-ENODATA</constant></term>
 
-          <listitem><para>The event loop has not been requested to exit yet.</para></listitem>
+          <listitem><para>Returned by <function>sd_event_get_exit_code()</function> in case the event loop has not
+          been requested to exit yet.</para></listitem>
         </varlistentry>
 
       </variablelist>
index c651d5950268087f20d7a17f00dfea38209a53dd..12aa98059381516a805e4eb5fddae02a61d08726 100644 (file)
@@ -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;
 }