`netstat -ntp` odd 'Program name' presentation

Cristian Ionescu-Idbohrn cristian.ionescu-idbohrn at axis.com
Sat Apr 21 08:26:55 UTC 2012


The 'Program name' part is fetched from /proc/<pid>/cmdline, then mangled
before presentation.  Mangling is done in netstat.c, function 'dir_act'.
The function assumes cmdline is a file path and extracts the basename.
Obviously that assumption is not always correct.  It's not unusual a
cmdline looks like this:

	sshd: foo at pts/48

or like this:

	sshd: foo [priv]

Function 'bb_basename' uses strrchr everything up to and including the
last occurrence och character '/'.  The result is (see first example
above):

	PID/Program name
	12345/48

or (second example):

	PID/Program name
	12345/sshd: foo [priv]

Neither is desirable.
I'd like to propose a different way to do that:

1. strip everything after and including the first whitespace character
2. maybe remove even odd ':' character at the end of the string
3. call bb_basename after that

Output would then look like:

	PID/Program name
	12345/sshd

which is what one would expect.

Thoughts?


Cheers,

-- 
Cristian


More information about the busybox mailing list