From: Lennart Poettering Date: Mon, 13 Jul 2026 08:12:07 +0000 (+0200) Subject: process-util: introduce prctl_safe() X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d3c0348c8b73102111ac40801b0e299c89435a3c;p=thirdparty%2Fsystemd.git process-util: introduce prctl_safe() --- diff --git a/src/basic/process-util.c b/src/basic/process-util.c index 14e58e21ebd..74f0d81b2ae 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -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)); +} diff --git a/src/basic/process-util.h b/src/basic/process-util.h index 9d16055d5e2..e2f834a7445 100644 --- a/src/basic/process-util.h +++ b/src/basic/process-util.h @@ -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);