]> git.itanic.dy.fi Git - scan-pagemap/blobdiff - pidlib.c
Show full process argument list instead only executable name
[scan-pagemap] / pidlib.c
index d432e9dc907065dd1ecc73198112af2af83e08f7..73247203da432199f6c0a32ee1417069452ce451 100644 (file)
--- a/pidlib.c
+++ b/pidlib.c
@@ -1,3 +1,20 @@
+/*
+ * 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
+ * the Free Software Foundation; either version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
@@ -120,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");
@@ -133,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;
 }