net: Remove dead code from net/socket.c
Subsystems (2)
PATCH 1/1 net: Remove dead code from net/socket.c
When a connection is accepted, the handler net_socket_accept() calls net_socket_fd_init(). If the socket is UDP/multicast, net_socket_fd_init() calls net_socket_fd_init_dgram, if the socket is TCP it calls net_socket_fd_init_dgram_stream.
In both cases the info_str string is written inside net_socket_fd_init_(stream|dgram), and after that, it is overwritten on a subsequent snprintf() in net_socket_accept().
net_socket_fd_init_(stream|dgram) always puts into the info_str the fd number, and this information is overwritten latter. No one has noticed this for so long that I believe this code is dead.
--- net/socket.c | 7 ------- 1 files changed, 0 insertions(+), 7 deletions(-)
net/socket.c +0 -7
@@ -267,11 +267,6 @@ static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan, nc =qemu_new_net_client (&net_dgram_socket_info, vlan,NULL , model, name); -snprintf (nc->info_str,sizeof (nc->info_str), -"socket: fd=%d (%s mcast=%s:%d)" , - fd, is_connected ?"cloned" :"" , -inet_ntoa (saddr.sin_addr),ntohs (saddr.sin_port)); - s =DO_UPCAST (NetSocketState, nc, nc); s->fd = fd;
@@ -307,8 +302,6 @@ static NetSocketState *net_socket_fd_init_stream(VLANState *vlan, nc =qemu_new_net_client (&net_socket_info, vlan,NULL , model, name); -snprintf (nc->info_str,sizeof (nc->info_str),"socket: fd=%d" , fd); - s =DO_UPCAST (NetSocketState, nc, nc); s->fd = fd;
Signature · 1 line
1.7.1
Quoted 9 lines · Miguel Di Ciurcio Filho
When a connection is accepted, the handler
net_socket_accept()callsnet_socket_fd_init(). If the socket is UDP/multicast,net_socket_fd_init()callsnet_socket_fd_init_dgram, if the socket is TCP it callsnet_socket_fd_init_dgram_stream.In both cases the
info_strstring is written insidenet_socket_fd_init_(stream|dgram), and after that, it is overwritten on a subsequentsnprintf()innet_socket_accept().
There is non-zero time window between registration and acceptance. And you have the path taken for fd sockets.
Jan
Quoted 34 lines
net_socket_fd_init_(stream|dgram)always puts into theinfo_strthe fd number, and this information is overwritten latter. No one has noticed this for so long that I believe this code is dead.Signed-off-by Miguel Di Ciurcio Filho <[email protected]>--- net/socket.c | 7 ------- 1 files changed, 0 insertions(+), 7 deletions(-)net/socket.c +0
-7@@ -267,11 +267,6 @@ static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan, nc =qemu_new_net_client (&net_dgram_socket_info, vlan,NULL , model, name); -snprintf (nc->info_str,sizeof (nc->info_str), -"socket: fd=%d (%s mcast=%s:%d)" , - fd, is_connected ?"cloned" :"" , -inet_ntoa (saddr.sin_addr),ntohs (saddr.sin_port)); - s =DO_UPCAST (NetSocketState, nc, nc); s->fd = fd;@@ -307,8 +302,6 @@ static NetSocketState *net_socket_fd_init_stream(VLANState *vlan, nc =qemu_new_net_client (&net_socket_info, vlan,NULL , model, name); -snprintf (nc->info_str,sizeof (nc->info_str),"socket: fd=%d" , fd); - s =DO_UPCAST (NetSocketState, nc, nc); s->fd = fd;
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
Quoted 9 lines · Jan Kiszka
Quoted 5 lines
In both cases the
info_strstring is written insidenet_socket_fd_init_(stream|dgram), and after that, it is overwritten on a subsequentsnprintf()innet_socket_accept().There is non-zero time window between registration and acceptance. And you have the path taken for fd sockets.
It is non-zero, yes, but what is the point of writing to info_str with an fd number for less them 5ms, when that value will be overwritten anyway?
I'm an student, just trying to understand what is going on :-D
Regards,
Miguel
Quoted 5 lines · Miguel Di Ciurcio Filho
Quoted 4 lines · Jan Kiszka
Quoted 4 lines
In both cases the
info_strstring is written insidenet_socket_fd_init_(stream|dgram), and after that, it is overwritten on a subsequentsnprintf()innet_socket_accept().
Quoted 7 lines
Quoted 3 lines
There is non-zero time window between registration and acceptance. And you have the path taken for fd sockets.
It is non-zero, yes, but what is the point of writing to
info_strwith an fd number for less them 5ms, when that value will be overwritten anyway?
You are right regarding listen sockets, I forgot that they block, thus there is no chance to request any information about them before the link has been established.
But my point about the sockets created by file descriptor remains valid.
Quoted 2 lines
I'm an student, just trying to understand what is going on :-D
Always welcome! People who look from a different angle at this can often find cruft that others already stopped to realize.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux