]> git.sur5r.net Git - i3/i3/commitdiff
i3 --moreversion: use readlink /proc/$pid/exe instead of realpath(argv[0])
authorMichael Stapelberg <michael@stapelberg.de>
Mon, 13 Aug 2012 11:38:04 +0000 (13:38 +0200)
committerMichael Stapelberg <michael@stapelberg.de>
Mon, 13 Aug 2012 11:38:04 +0000 (13:38 +0200)
The latter is actually wrong. For example, when running i3
--moreversion, it will print $(pwd)/i3 instead of $(which i3). In my
previous tests, this coincidentally was the same.

src/display_version.c

index 7460a1a2ca9acb7155a0df9efa7dac8b6fdb6024..ac1a622c6ece3e90bf91b027304576177406652f 100644 (file)
@@ -123,18 +123,25 @@ void display_running_version(void) {
         errx(EXIT_FAILURE, "Could not parse my own reply. That's weird. reply is %.*s", (int)reply_length, reply);
 
     printf("\rRunning i3 version: %s (pid %s)\n", human_readable_version, pid_from_atom);
-    printf("\n");
-    char resolved_path[PATH_MAX];
-    if (realpath(start_argv[0], resolved_path) == NULL)
-        err(EXIT_FAILURE, "realpath(%s)", start_argv[0]);
-    printf("The i3 binary you just called: %s\n", resolved_path);
 
 #ifdef __linux__
     char exepath[PATH_MAX],
          destpath[PATH_MAX];
+    ssize_t linksize;
+
+    snprintf(exepath, sizeof(exepath), "/proc/%d/exe", getpid());
+
+    if ((linksize = readlink(exepath, destpath, sizeof(destpath))) == -1)
+        err(EXIT_FAILURE, "readlink(%s)", exepath);
+
+    /* readlink() does not NULL-terminate strings, so we have to. */
+    destpath[linksize] = '\0';
+
+    printf("\n");
+    printf("The i3 binary you just called: %s\n", destpath);
+
     snprintf(exepath, sizeof(exepath), "/proc/%s/exe", pid_from_atom);
 
-    ssize_t linksize;
     if ((linksize = readlink(exepath, destpath, sizeof(destpath))) == -1)
         err(EXIT_FAILURE, "readlink(%s)", exepath);