]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
machine: introduce report_errno_and_exit()
authorIvan Kruglov <mail@ikruglov.com>
Thu, 31 Oct 2024 09:58:21 +0000 (10:58 +0100)
committerIvan Kruglov <mail@ikruglov.com>
Fri, 1 Nov 2024 14:21:22 +0000 (15:21 +0100)
src/machine/operation.c
src/machine/operation.h

index 7d7bfa50627efdac735515d35e77a8e5fde87f02..0b2139acf03a0a4337995a7bff75b941a11d460a 100644 (file)
@@ -154,3 +154,18 @@ Operation *operation_free(Operation *o) {
 
         return mfree(o);
 }
+
+_noreturn_ void report_errno_and_exit(int errno_fd, int r) {
+        if (r >= 0)
+                _exit(EXIT_SUCCESS);
+
+        assert(errno_fd >= 0);
+
+        ssize_t n = write(errno_fd, &r, sizeof(r));
+        if (n < 0)
+                log_debug_errno(errno, "Failed to write operation's errno: %m");
+        if (n != sizeof(r))
+                log_debug_errno(SYNTHETIC_ERRNO(EIO), "Sent unexpectedly short message");
+
+        _exit(EXIT_FAILURE);
+}
index 75bf918c2b1cf52830f02f87c80b9d4bd54599c0..ee9149854ac1eccfb40fd01818e22fdfa5512131 100644 (file)
@@ -39,3 +39,5 @@ static inline int operation_new_with_bus_reply(Manager *manager, Machine *machin
 static inline int operation_new_with_varlink_reply(Manager *manager, Machine *machine, pid_t child, sd_varlink *link, int errno_fd, Operation **ret) {
         return operation_new(manager, machine, child, /* message = */ NULL, link, errno_fd, ret);
 }
+
+void report_errno_and_exit(int errno_fd, int r);