Hi,

attached there is a new patch for procfs to improve again the file name 
in stat/status files for PIDs.
Basically, it just considers only the first word in case the process 
name has more (e.g. when it changed its own).

Thanks,
-- 
Pino Toscano
From ebf2b049ea6963026766763df1697467f5806327 Mon Sep 17 00:00:00 2001
From: Pino Toscano <toscano.p...@tiscali.it>
Date: Fri, 7 Sep 2012 19:14:48 +0200
Subject: [PATCH] PID stat/status: show only the first word

If a process changed its title to a multiword string, show only the first word
of it.

* process.c (args_filename_length): New function.
(process_file_gc_stat): Use args_filename_length.
(process_file_gc_status): Likewise.
---
 process.c |   18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/process.c b/process.c
index 17a38ea..003bb2d 100644
--- a/process.c
+++ b/process.c
@@ -87,6 +87,14 @@ static const char *args_filename (const char *name)
   return sp != NULL && *(sp + 1) != '\0' ? sp + 1 : name;
 }
 
+static int args_filename_length (const char *name)
+{
+  const char *p = name;
+  while (*p != '\0' && *p != ' ')
+    ++p;
+  return p - name;
+}
+
 /* Actual content generators */
 
 static ssize_t
@@ -109,11 +117,12 @@ process_file_gc_stat (struct proc_stat *ps, char **contents)
   struct procinfo *pi = proc_stat_proc_info (ps);
   task_basic_info_t tbi = proc_stat_task_basic_info (ps);
   thread_basic_info_t thbi = proc_stat_thread_basic_info (ps);
+  const char *fn = args_filename (proc_stat_args (ps));
 
   /* See proc(5) for more information about the contents of each field for the
      Linux procfs.  */
   return asprintf (contents,
-      "%d (%s) %c "		/* pid, command, state */
+      "%d (%.*s) %c "		/* pid, command, state */
       "%d %d %d "		/* ppid, pgid, session */
       "%d %d "			/* controling tty stuff */
       "%u "			/* flags, as defined by <linux/sched.h> */
@@ -132,7 +141,7 @@ process_file_gc_stat (struct proc_stat *ps, char **contents)
       "%u %u "			/* RT priority and policy */
       "%llu "			/* aggregated block I/O delay */
       "\n",
-      proc_stat_pid (ps), args_filename (proc_stat_args (ps)), state_char (ps),
+      proc_stat_pid (ps), args_filename_length (fn), fn, state_char (ps),
       pi->ppid, pi->pgrp, pi->session,
       0, 0,		/* no such thing as a major:minor for ctty */
       0,		/* no such thing as CLONE_* flags on Hurd */
@@ -171,9 +180,10 @@ static ssize_t
 process_file_gc_status (struct proc_stat *ps, char **contents)
 {
   task_basic_info_t tbi = proc_stat_task_basic_info (ps);
+  const char *fn = args_filename (proc_stat_args (ps));
 
   return asprintf (contents,
-      "Name:\t%s\n"
+      "Name:\t%.*s\n"
       "State:\t%s\n"
       "Tgid:\t%u\n"
       "Pid:\t%u\n"
@@ -184,7 +194,7 @@ process_file_gc_status (struct proc_stat *ps, char **contents)
       "VmRSS:\t%8u kB\n"
       "VmHWM:\t%8u kB\n" /* ie. resident peak */
       "Threads:\t%u\n",
-      args_filename (proc_stat_args (ps)),
+      args_filename_length (fn), fn,
       state_string (ps),
       proc_stat_pid (ps), /* XXX will need more work for threads */
       proc_stat_pid (ps),
-- 
1.7.10.4

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to