]> git.itanic.dy.fi Git - scan-pagemap/blobdiff - pidlib.c
Show full process argument list instead only executable name
[scan-pagemap] / pidlib.c
index ce825c9eb0dec383cddcc17c5abe41b11ae157f3..73247203da432199f6c0a32ee1417069452ce451 100644 (file)
--- a/pidlib.c
+++ b/pidlib.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010 Timo Kokkonen <kaapeli@itanic.dy.fi>
+ * Copyright (C) 2010 Timo Kokkonen <timo.t.kokkonen@iki.fi>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -137,7 +137,7 @@ int read_cmdline(int pid, int tid, char *cmdline, size_t len)
 {
        FILE *file;
        char path[512];
-       int ret;
+       int ret, i;
 
        snprintf(path, sizeof(path), "/proc/%d/task/%d/cmdline", pid, tid);
        file = fopen(path, "rb");
@@ -150,6 +150,15 @@ int read_cmdline(int pid, int tid, char *cmdline, size_t len)
                cmdline[ret - 1] = 0;
        fclose(file);
 
+       /*
+        * Process arguments are separated by NULL bytes. Replace
+        * these with spacese so that the arguments become visible
+        * too.
+        */
+       for (i = 0; i < ret - 1; i++)
+               if (cmdline[i] == '\0')
+                       cmdline[i] = ' ';
+
        return ret > 0 ? 0 : -1;
 }