]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
process-util: introduce prctl_safe()
authorLennart Poettering <lennart@amutable.com>
Mon, 13 Jul 2026 08:12:07 +0000 (10:12 +0200)
committerLennart Poettering <lennart@amutable.com>
Mon, 13 Jul 2026 13:39:16 +0000 (15:39 +0200)
src/basic/process-util.c
src/basic/process-util.h

index 14e58e21ebd0fdd21a9366616ab89f26bd872e3a..74f0d81b2aee0834e191ff6e2bff4c8d3f679536 100644 (file)
@@ -2276,3 +2276,15 @@ int read_errno(int errno_fd) {
 
         return log_debug_errno(SYNTHETIC_ERRNO(EIO), "Received positive errno from child, refusing: %d", r);
 }
+
+int prctl_safe(int op, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5) {
+
+        /* prctl(2) is a bit messy: it's a variadic function, defined with "unsigned long" arguments. This
+         * means that unless people explicitly cast it's quite likely they end up passing a shorter type even
+         * though unsigned long is required. And most of the time it might even kind of work, but not
+         * always. Moreover, some calls insist on all unused arguments being zeroed out, others don't
+         * care. Let's define this wrapper to enforce the right types, and that all arguments are always
+         * passed, to avoid this confusion. */
+
+        return RET_NERRNO(prctl(op, arg2, arg3, arg4, arg5));
+}
index 9d16055d5e28f0ad5f07c05ae894798bd2774627..e2f834a7445747a96d492630a418acdc50babe99 100644 (file)
@@ -255,3 +255,5 @@ int safe_mlockall(int flags);
 
 _noreturn_ void report_errno_and_exit(int errno_fd, int error);
 int read_errno(int errno_fd);
+
+int prctl_safe(int op, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5);