Hi,

Alle sabato 24 dicembre 2011, Guillem Jover ha scritto:
>  * If Hurd's procfs interface is supposed to provide a Linux
> compatible output, then it needs to switch to only a program name,
> not a full path in /proc/<pid>/stat, /statm, etc.

Attached there is a patch (for the jkoenig/master branch) to fix this 
behaviour in per-process `stat' and `status' files.

Thanks,
-- 
Pino Toscano
From 3eec2e26d3c4cf83004eed079f0455ed4485095e Mon Sep 17 00:00:00 2001
From: Pino Toscano <toscano.p...@tiscali.it>
Date: Sat, 14 Jan 2012 14:47:58 +0100
Subject: [PATCH] PID stat/status: show only the file name of processes

The Linux /proc fs shows only the file name of processes in the
`stat' and `status' files of every process directory, so adapt also
procfs to show process file names.

Add a new `args_filename` function, much similar to GNU's `basename'
but returning the original string also when the resulting file name
is an empty string.

* process.c (args_filename): New function.
(process_file_gc_stat): Wrap the `proc_stat_args' result with
`args_filename'.
(process_file_gc_status): Likewise.
---
 process.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/process.c b/process.c
index 6652a4e..17a38ea 100644
--- a/process.c
+++ b/process.c
@@ -81,6 +81,12 @@ static long long int timeval_jiffies (time_value_t tv)
   return secs * opt_clk_tck / 1000000.;
 }
 
+static const char *args_filename (const char *name)
+{
+  char *sp = strrchr (name, '/');
+  return sp != NULL && *(sp + 1) != '\0' ? sp + 1 : name;
+}
+
 /* Actual content generators */
 
 static ssize_t
@@ -126,7 +132,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), proc_stat_args (ps), state_char (ps),
+      proc_stat_pid (ps), args_filename (proc_stat_args (ps)), 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 */
@@ -178,7 +184,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",
-      proc_stat_args (ps),
+      args_filename (proc_stat_args (ps)),
       state_string (ps),
       proc_stat_pid (ps), /* XXX will need more work for threads */
       proc_stat_pid (ps),
-- 
1.7.7.3

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

Reply via email to