]> err.no Git - systemd/commitdiff
exec: include path name of binary we are about to execute when renaming forked off...
authorLennart Poettering <lennart@poettering.net>
Wed, 1 Feb 2012 21:33:15 +0000 (22:33 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 1 Feb 2012 21:33:15 +0000 (22:33 +0100)
Immediately after forking off a process change the comm name and argv[0]
to "(foobar)" where "foobar" is the basename of the path we are about to
execute.

This should be useful when charting boot progress.

src/execute.c
src/main.c
src/util.c

index 13f4561f277611aa7a377fd9d0d4c35d2621735c..536877d68c2a8877e1346889100a61a622a26df9 100644 (file)
@@ -770,8 +770,8 @@ static int setup_pam(
                  * termination */
 
                 /* This string must fit in 10 chars (i.e. the length
-                 * of "/sbin/init") */
-                rename_process("sd(PAM)");
+                 * of "/sbin/init"), to look pretty in /bin/ps */
+                rename_process("(sd-pam)");
 
                 /* Make sure we don't keep open the passed fds in this
                 child. We assume that otherwise only those fds are
@@ -919,6 +919,37 @@ finish:
         return r;
 }
 
+static void rename_process_from_path(const char *path) {
+        char process_name[11];
+        const char *p;
+        size_t l;
+
+        /* This resulting string must fit in 10 chars (i.e. the length
+         * of "/sbin/init") to look pretty in /bin/ps */
+
+        p = file_name_from_path(path);
+        if (isempty(p)) {
+                rename_process("(...)");
+                return;
+        }
+
+        l = strlen(p);
+        if (l > 8) {
+                /* The end of the process name is usually more
+                 * interesting, since the first bit might just be
+                 * "systemd-" */
+                p = p + l - 8;
+                l = 8;
+        }
+
+        process_name[0] = '(';
+        memcpy(process_name+1, p, l);
+        process_name[1+l] = ')';
+        process_name[1+l+1] = 0;
+
+        rename_process(process_name);
+}
+
 int exec_spawn(ExecCommand *command,
                char **argv,
                const ExecContext *context,
@@ -997,9 +1028,7 @@ int exec_spawn(ExecCommand *command,
 
                 /* child */
 
-                /* This string must fit in 10 chars (i.e. the length
-                 * of "/sbin/init") */
-                rename_process("sd(EXEC)");
+                rename_process_from_path(command->path);
 
                 /* We reset exactly these signals, since they are the
                  * only ones we set to SIG_IGN in the main daemon. All
index 94e6ec63ccebd817b722cea2b09f6731e03d15f5..738db6c264e94abd5e3e772e8c682163a33d62b7 100644 (file)
@@ -1138,7 +1138,7 @@ int main(int argc, char *argv[]) {
         bool reexecute = false;
         const char *shutdown_verb = NULL;
         dual_timestamp initrd_timestamp = { 0ULL, 0ULL };
-        char systemd[] = "systemd";
+        static char systemd[] = "systemd";
         bool is_reexec = false;
         int j;
         bool loaded_policy = false;
@@ -1169,9 +1169,9 @@ int main(int argc, char *argv[]) {
            called 'init'. After a subsequent reexecution we are then
            called 'systemd'. That is confusing, hence let's call us
            systemd right-away. */
-
         program_invocation_short_name = systemd;
         prctl(PR_SET_NAME, systemd);
+
         saved_argv = argv;
         saved_argc = argc;
 
index ce7f1c9f84052718e623c4d0cdddec9b618bb6b1..58a0aebad3d3d2ad596658396ab970c7da6d3d0b 100644 (file)
@@ -3263,11 +3263,15 @@ fallback:
 void rename_process(const char name[8]) {
         assert(name);
 
-        prctl(PR_SET_NAME, name);
+        /* This is a like a poor man's setproctitle(). It changes the
+         * comm field, argv[0], and also the glibc's internally used
+         * name of the process. For the first one a limit of 16 chars
+         * applies, to the second one usually one of 10 (i.e. length
+         * of "/sbin/init"), to the third one one of 7 (i.e. length of
+         * "systemd"). If you pass a longer string it will be
+         * truncated */
 
-        /* This is a like a poor man's setproctitle(). The string
-         * passed should fit in 7 chars (i.e. the length of
-         * "systemd") */
+        prctl(PR_SET_NAME, name);
 
         if (program_invocation_name)
                 strncpy(program_invocation_name, name, strlen(program_invocation_name));