]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
process-util: introduce report_errno_and_exit() as part of src/basic/process-util...
authorIvan Kruglov <mail@ikruglov.com>
Wed, 6 Nov 2024 10:11:03 +0000 (11:11 +0100)
committerIvan Kruglov <mail@ikruglov.com>
Wed, 6 Nov 2024 10:18:38 +0000 (11:18 +0100)
src/basic/process-util.c
src/basic/process-util.h
src/machine/operation.c
src/machine/operation.h

index 75bc65652e2bb8260616135535c7346b2c1f4cce..ee0edfaf94ef617704d8ddb295cd0fac6aff394a 100644 (file)
@@ -35,6 +35,7 @@
 #include "fileio.h"
 #include "fs-util.h"
 #include "hostname-util.h"
+#include "io-util.h"
 #include "locale-util.h"
 #include "log.h"
 #include "macro.h"
@@ -2238,3 +2239,18 @@ static const char* const sched_policy_table[] = {
 };
 
 DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(sched_policy, int, INT_MAX);
+
+_noreturn_ void report_errno_and_exit(int errno_fd, int error) {
+        int r;
+
+        if (error >= 0)
+                _exit(EXIT_SUCCESS);
+
+        assert(errno_fd >= 0);
+
+        r = loop_write(errno_fd, &error, sizeof(error));
+        if (r < 0)
+                log_debug_errno(r, "Failed to write errno to errno_fd=%d: %m", errno_fd);
+
+        _exit(EXIT_FAILURE);
+}
index cb6d47a5bb75cd2a4b8bf2706d97ea5cd6e189ce..0763b64cff0f2529efd729a0f0733fec782f53e1 100644 (file)
@@ -273,3 +273,5 @@ int posix_spawn_wrapper(
 int proc_dir_open(DIR **ret);
 int proc_dir_read(DIR *d, pid_t *ret);
 int proc_dir_read_pidref(DIR *d, PidRef *ret);
+
+_noreturn_ void report_errno_and_exit(int errno_fd, int error);
index 0b2139acf03a0a4337995a7bff75b941a11d460a..7d7bfa50627efdac735515d35e77a8e5fde87f02 100644 (file)
@@ -154,18 +154,3 @@ 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 ee9149854ac1eccfb40fd01818e22fdfa5512131..75bf918c2b1cf52830f02f87c80b9d4bd54599c0 100644 (file)
@@ -39,5 +39,3 @@ 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);