Skip to contentSkip to conversation

unix: show socket peer if no addr is given in /proc/net/unix

PATCH In review Masatake YAMATO 3 participants 4 messages Jan 8, 2014

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 unix: show socket peer if no addr is given in /proc/net/unix

Path field of /proc/net/unix is empty if an address is not given to a socket. Typical way to create such socket is calling socketpair. The empty fields make it difficult to understand the communication between processes. e.g. lsof cannot resolve the role of file descriptors well.

This patch fills the empty fields with unix_peer.

---
 net/unix/af_unix.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/unix/af_unix.c +4 -1
index 800ca61..1700133 100644
@@ -2340,7 +2340,9 @@ static int unix_seq_show(struct seq_file *seq, void *v)
 	else {
 		struct sock *s = v;
 		struct unix_sock *u = unix_sk(s);
+		struct sock *s_peer;
 		unix_state_lock(s);
+		s_peer = unix_peer(s);
 
 		seq_printf(seq, "%pK: %08X %08X %08X %04X %02X %5lu",
 			s,
@@ -2367,7 +2369,8 @@ static int unix_seq_show(struct seq_file *seq, void *v)
 			}
 			for ( ; i < len; i++)
 				seq_putc(seq, u->addr->name->sun_path[i]);
-		}
+		} else if (s_peer)
+			seq_printf(seq, " #%pK", s_peer);
 		unix_state_unlock(s);
 		seq_putc(seq, '\n');
 	}
Signature · 1 line
1.8.4.2
maintainer
#1 lore raw

From: Masatake YAMATO <[email protected]>
Date: Wed, 8 Jan 2014 14:18:08 +0900

Quoted 9 lines

Path field of /proc/net/unix is empty if an address is not given to a socket. Typical way to create such socket is calling socketpair. The empty fields make it difficult to understand the communication between processes. e.g. lsof cannot resolve the role of file descriptors well.

This patch fills the empty fields with unix_peer.

You cannot change the format of a procfs file without potentially breaking some application which might interpret the output.

In this case an application might be looking for an empty field as meaning the sockhad has no given address.

I cannot apply this patch. People have repeatedly tried making changes to these networking socket procfs files, and I really wish people would stop trying to do so.

If you want specific pieces of new information, extend the socket dumping facility that is actually extensible in a way which will not break existing applications, and that's netlink.

#2 lore raw

Thank you for reviwing.
I'll use netlink diag facility.

Masatake YAMATO

Quoted 26 lines · David Miller

From: Masatake YAMATO <[email protected]>
Date: Wed, 8 Jan 2014 14:18:08 +0900

Quoted 9 lines

Path field of /proc/net/unix is empty if an address is not given to a socket. Typical way to create such socket is calling socketpair. The empty fields make it difficult to understand the communication between processes. e.g. lsof cannot resolve the role of file descriptors well.

This patch fills the empty fields with unix_peer.

You cannot change the format of a procfs file without potentially breaking some application which might interpret the output.

In this case an application might be looking for an empty field as meaning the sockhad has no given address.

I cannot apply this patch. People have repeatedly tried making changes to these networking socket procfs files, and I really wish people would stop trying to do so.

If you want specific pieces of new information, extend the socket dumping facility that is actually extensible in a way which will not break existing applications, and that's netlink.

#3 lore raw
In reply to Masatake YAMATO

Hello.

Quoted 28 lines · Masatake YAMATO

Path field of /proc/net/unix is empty if an address is not given to a socket. Typical way to create such socket is calling socketpair. The empty fields make it difficult to understand the communication between processes. e.g. lsof cannot resolve the role of file descriptors well.

This patch fills the empty fields with unix_peer.

---
  net/unix/af_unix.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
net/unix/af_unix.c +2 -0
index 800ca61..1700133 100644
@@ -2340,7 +2340,9 @@ static int unix_seq_show(struct seq_file *seq, void *v)
  	else {
  		struct sock *s = v;
  		struct unix_sock *u = unix_sk(s);
+		struct sock *s_peer;
  		unix_state_lock(s);
+		s_peer = unix_peer(s);
 
  		seq_printf(seq, "%pK: %08X %08X %08X %04X %02X %5lu",
  			s,

net/unix/af_unix.c static int unix_seq_show(struct seq_file *seq, void *v) · line 2373

Quoted 6 lines
net/unix/af_unix.c +2 -1
@@ -2367,7 +2369,8 @@ static int unix_seq_show(struct seq_file *seq, void *v)
  			}
  			for ( ; i < len; i++)
  				seq_putc(seq, u->addr->name->sun_path[i]);
-		}
+		} else if (s_peer)
+			seq_printf(seq, " #%pK", s_peer);

According to Documentation/CodingStyle, both arms of the *if* statement
should have {} if one has it.

WBR, Sergei