summaryrefslogtreecommitdiffstats
path: root/src/basic
diff options
context:
space:
mode:
authorIvan Kruglov <mail@ikruglov.com>2024-11-06 11:11:03 +0100
committerIvan Kruglov <mail@ikruglov.com>2024-11-06 11:18:38 +0100
commita567de392d7e9c93a7673f38ac8c5fd94d3adb6c (patch)
tree497378d9b5cb5b6cbe2eb762a11f9204f83a5bba /src/basic
parentman/systemd-measure: add forgotten "=" (diff)
downloadsystemd-a567de392d7e9c93a7673f38ac8c5fd94d3adb6c.tar.xz
systemd-a567de392d7e9c93a7673f38ac8c5fd94d3adb6c.zip
process-util: introduce report_errno_and_exit() as part of src/basic/process-util.{h,c}
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/process-util.c16
-rw-r--r--src/basic/process-util.h2
2 files changed, 18 insertions, 0 deletions
diff --git a/src/basic/process-util.c b/src/basic/process-util.c
index 75bc65652e..ee0edfaf94 100644
--- a/src/basic/process-util.c
+++ b/src/basic/process-util.c
@@ -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);
+}
diff --git a/src/basic/process-util.h b/src/basic/process-util.h
index cb6d47a5bb..0763b64cff 100644
--- a/src/basic/process-util.h
+++ b/src/basic/process-util.h
@@ -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);