]> git.ipfire.org Git - telemetry.git/commitdiff
command: Map back any negative return codes
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 4 Jun 2026 16:02:47 +0000 (16:02 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 4 Jun 2026 16:02:47 +0000 (16:02 +0000)
This is not perfect, but should be good enough since applications
normally don't use any return codes larger than 128.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/daemon/command.c

index 571a828f8803f89339901ff1568328ca9119fa47..4c426a37bca9ef673024dca99c48ac4b522fadb8 100644 (file)
@@ -398,13 +398,20 @@ static int td_command_exited(sd_event_source* source, const siginfo_t* si, void*
 
        switch (si->si_code) {
                case CLD_EXITED:
-                       DEBUG(self->ctx, "Process has exited with status code %d\n", si->si_status);
-
                        // Store the exit code
                        rc = si->si_status;
 
-                       // Log stderr
+                       // Handle any errors
                        if (rc) {
+                               // Map back -errno
+                               if (rc >= 128)
+                                       rc -= 256;
+
+                               if (rc >= 0)
+                                       DEBUG(self->ctx, "Process has exited with status code %d\n", rc);
+                               else
+                                       DEBUG(self->ctx, "Process has exited with status: %s\n", strerror(-rc));
+
                                // Log all lines
                                r = td_file_walk(stderr, td_command_log_stderr, self);
                                if (r < 0)