]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
missing: define kernel internal limit TASK_COMM_LEN in userspace too
authorLennart Poettering <lennart@poettering.net>
Fri, 1 Jun 2018 19:43:43 +0000 (21:43 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 1 Jun 2018 19:49:16 +0000 (21:49 +0200)
We already use it at two places, and we are about to add one too.
Arbitrary literally hardcoded limits suck.

src/basic/missing.h
src/basic/process-util.c
src/test/test-process-util.c

index e714078f31ed50d7c90ffa48545f0ba4dc64fffb..dbdbd6f26090b4acdd4f5e1f05951f11b1fc1a80 100644 (file)
@@ -1407,4 +1407,11 @@ struct statx {
 #define AT_STATX_DONT_SYNC 0x4000
 #endif
 
+/* The maximum thread/process name length including trailing NUL byte. This mimics the kernel definition of the same
+ * name, which we need in userspace at various places but is not defined in userspace currently, neither under this
+ * name nor any other. */
+#ifndef TASK_COMM_LEN
+#define TASK_COMM_LEN 16
+#endif
+
 #include "missing_syscall.h"
index a503aa50dc4ce449792c67853ea6a8c2889286ec..058f077de06b53f15deaa9943210a172896b3ea3 100644 (file)
@@ -296,7 +296,7 @@ int rename_process(const char name[]) {
          * can use PR_SET_NAME, which sets the thread name for the calling thread. */
         if (prctl(PR_SET_NAME, name) < 0)
                 log_debug_errno(errno, "PR_SET_NAME failed: %m");
-        if (l > 15) /* Linux process names can be 15 chars at max */
+        if (l >= TASK_COMM_LEN) /* Linux process names can be 15 chars at max */
                 truncated = true;
 
         /* Second step, change glibc's ID of the process name. */
index fd5b44dc13ea65e8ac49030d926519ddb1e35d66..8b975ff9888b7a55c4fe4800d5ffab247a9b7880 100644 (file)
@@ -366,7 +366,7 @@ static void test_rename_process_now(const char *p, int ret) {
 
         assert_se(get_process_comm(0, &comm) >= 0);
         log_info("comm = <%s>", comm);
-        assert_se(strneq(comm, p, 15));
+        assert_se(strneq(comm, p, TASK_COMM_LEN-1));
 
         assert_se(get_process_cmdline(0, 0, false, &cmdline) >= 0);
         /* we cannot expect cmdline to be renamed properly without privileges */