Skip to contentSkip to conversation

slirp: Remove unused variable and unused code

PATCH In review Stefan Weil 2 participants 3 messages Jan 7, 2012 – Jan 15, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 slirp: Remove unused variable and unused code

9634d9031c140b24c7ca0d8872632207f6ce7275 disabled unused code. This patch removes what was left.

If do_pty is 2, the function returns immediately, so any later checks for do_pty == 2 will always fail and can be removed together with the code which is never executed. Then variable master is unused and can be removed, too.

This issue was detected by coverity.

---
 slirp/misc.c |   67 ++++++++++++++++++++++-----------------------------------
 1 files changed, 26 insertions(+), 41 deletions(-)
slirp/misc.c +26 -41
index 6c80e69..3432fbf 100644
@@ -113,7 +113,6 @@ fork_exec(struct socket *so, const char *ex, int do_pty)
 	struct sockaddr_in addr;
 	socklen_t addrlen = sizeof(addr);
 	int opt;
-        int master = -1;
 	const char *argv[256];
 	/* don't want to clobber the original */
 	char *bptr;
@@ -148,32 +147,23 @@ fork_exec(struct socket *so, const char *ex, int do_pty)
 	 case -1:
 		lprint("Error: fork failed: %s\n", strerror(errno));
 		close(s);
-		if (do_pty == 2)
-		   close(master);
 		return 0;
 
 	 case 0:
                 setsid();
 
 		/* Set the DISPLAY */
-		if (do_pty == 2) {
-			(void) close(master);
-#ifdef TIOCSCTTY /* XXXXX */
-			ioctl(s, TIOCSCTTY, (char *)NULL);
-#endif
-		} else {
-			getsockname(s, (struct sockaddr *)&addr, &addrlen);
-			close(s);
-			/*
-			 * Connect to the socket
-			 * XXX If any of these fail, we're in trouble!
-	 		 */
-			s = qemu_socket(AF_INET, SOCK_STREAM, 0);
-			addr.sin_addr = loopback_addr;
-                        do {
-                            ret = connect(s, (struct sockaddr *)&addr, addrlen);
-                        } while (ret < 0 && errno == EINTR);
-		}
+                getsockname(s, (struct sockaddr *)&addr, &addrlen);
+                close(s);
+                /*
+                 * Connect to the socket
+                 * XXX If any of these fail, we're in trouble!
+                 */
+                s = qemu_socket(AF_INET, SOCK_STREAM, 0);
+                addr.sin_addr = loopback_addr;
+                do {
+                    ret = connect(s, (struct sockaddr *)&addr, addrlen);
+                } while (ret < 0 && errno == EINTR);
 
 		dup2(s, 0);
 		dup2(s, 1);
@@ -210,26 +200,21 @@ fork_exec(struct socket *so, const char *ex, int do_pty)
 
 	 default:
 		qemu_add_child_watch(pid);
-		if (do_pty == 2) {
-			close(s);
-			so->s = master;
-		} else {
-			/*
-			 * XXX this could block us...
-			 * XXX Should set a timer here, and if accept() doesn't
-		 	 * return after X seconds, declare it a failure
-		 	 * The only reason this will block forever is if socket()
-		 	 * of connect() fail in the child process
-		 	 */
-                        do {
-                            so->s = accept(s, (struct sockaddr *)&addr, &addrlen);
-                        } while (so->s < 0 && errno == EINTR);
-                        closesocket(s);
-			opt = 1;
-			setsockopt(so->s,SOL_SOCKET,SO_REUSEADDR,(char *)&opt,sizeof(int));
-			opt = 1;
-			setsockopt(so->s,SOL_SOCKET,SO_OOBINLINE,(char *)&opt,sizeof(int));
-		}
+                /*
+                 * XXX this could block us...
+                 * XXX Should set a timer here, and if accept() doesn't
+                 * return after X seconds, declare it a failure
+                 * The only reason this will block forever is if socket()
+                 * of connect() fail in the child process
+                 */
+                do {
+                    so->s = accept(s, (struct sockaddr *)&addr, &addrlen);
+                } while (so->s < 0 && errno == EINTR);
+                closesocket(s);
+                opt = 1;
+                setsockopt(so->s, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, sizeof(int));
+                opt = 1;
+                setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, (char *)&opt, sizeof(int));
 		fd_nonblock(so->s);
 
 		/* Append the telnet options now */
Signature · 1 line
1.7.0.4
#1 lore raw

Am 05.01.2012 14:18, schrieb Stefan Weil:

Quoted 105 lines

9634d9031c140b24c7ca0d8872632207f6ce7275 disabled unused code. This patch removes what was left.

If do_pty is 2, the function returns immediately, so any later checks for do_pty == 2 will always fail and can be removed together with the code which is never executed. Then variable master is unused and can be removed, too.

This issue was detected by coverity.

---
  slirp/misc.c |   67 ++++++++++++++++++++++-----------------------------------
  1 files changed, 26 insertions(+), 41 deletions(-)
slirp/misc.c +19 -41
index 6c80e69..3432fbf 100644
@@ -113,7 +113,6 @@ fork_exec(struct socket *so, const char *ex, int do_pty)
  	struct sockaddr_in addr;
  	socklen_t addrlen = sizeof(addr);
  	int opt;
-        int master = -1;
  	const char *argv[256];
  	/* don't want to clobber the original */
  	char *bptr;
@@ -148,32 +147,23 @@ fork_exec(struct socket *so, const char *ex, int do_pty)
  	 case -1:
  		lprint("Error: fork failed: %s\n", strerror(errno));
  		close(s);
-		if (do_pty == 2)
-		   close(master);
  		return 0;
 
  	 case 0:
                  setsid();
 
  		/* Set the DISPLAY */
-		if (do_pty == 2) {
-			(void) close(master);
-#ifdef TIOCSCTTY /* XXXXX */
-			ioctl(s, TIOCSCTTY, (char *)NULL);
-#endif
-		} else {
-			getsockname(s, (struct sockaddr *)&addr,&addrlen);
-			close(s);
-			/*
-			 * Connect to the socket
-			 * XXX If any of these fail, we're in trouble!
-	 		 */
-			s = qemu_socket(AF_INET, SOCK_STREAM, 0);
-			addr.sin_addr = loopback_addr;
-                        do {
-                            ret = connect(s, (struct sockaddr *)&addr, addrlen);
-                        } while (ret<  0&&  errno == EINTR);
-		}
+                getsockname(s, (struct sockaddr *)&addr,&addrlen);
+                close(s);
+                /*
+                 * Connect to the socket
+                 * XXX If any of these fail, we're in trouble!
+                 */
+                s = qemu_socket(AF_INET, SOCK_STREAM, 0);
+                addr.sin_addr = loopback_addr;
+                do {
+                    ret = connect(s, (struct sockaddr *)&addr, addrlen);
+                } while (ret<  0&&  errno == EINTR);
 
  		dup2(s, 0);
  		dup2(s, 1);
@@ -210,26 +200,21 @@ fork_exec(struct socket *so, const char *ex, int do_pty)
 
  	 default:
  		qemu_add_child_watch(pid);
-		if (do_pty == 2) {
-			close(s);
-			so->s = master;
-		} else {
-			/*
-			 * XXX this could block us...
-			 * XXX Should set a timer here, and if accept() doesn't
-		 	 * return after X seconds, declare it a failure
-		 	 * The only reason this will block forever is if socket()
-		 	 * of connect() fail in the child process
-		 	 */
-                        do {
-                            so->s = accept(s, (struct sockaddr *)&addr,&addrlen);
-                        } while (so->s<  0&&  errno == EINTR);
-                        closesocket(s);
-			opt = 1;
-			setsockopt(so->s,SOL_SOCKET,SO_REUSEADDR,(char *)&opt,sizeof(int));
-			opt = 1;
-			setsockopt(so->s,SOL_SOCKET,SO_OOBINLINE,(char *)&opt,sizeof(int));
-		}
+                /*
+                 * XXX this could block us...
+                 * XXX Should set a timer here, and if accept() doesn't
+                 * return after X seconds, declare it a failure
+                 * The only reason this will block forever is if socket()
+                 * of connect() fail in the child process
+                 */
+                do {

slirp/misc.c fork_exec(struct socket *so, const char *ex, int do_pty) · line 220

Quoted 10 lines
slirp/misc.c +7 -0
+                    so->s = accept(s, (struct sockaddr *)&addr,&addrlen);
+                } while (so->s<  0&&  errno == EINTR);
+                closesocket(s);
+                opt = 1;
+                setsockopt(so->s, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, sizeof(int));
+                opt = 1;
+                setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, (char *)&opt, sizeof(int));
  		fd_nonblock(so->s);
 
  		/* Append the telnet options now */

Ping. Please commit this patch.

Thanks,
Stefan W.

#2 lore raw
Quoted 126 lines · Stefan Weil

Am 05.01.2012 14:18, schrieb Stefan Weil:

Quoted 125 lines

9634d9031c140b24c7ca0d8872632207f6ce7275 disabled unused code. This patch removes what was left.

If do_pty is 2, the function returns immediately, so any later checks for do_pty == 2 will always fail and can be removed together with the code which is never executed. Then variable master is unused and can be removed, too.

This issue was detected by coverity.

---
  slirp/misc.c |   67
++++++++++++++++++++++-----------------------------------
  1 files changed, 26 insertions(+), 41 deletions(-)
slirp/misc.c +0 -1
index 6c80e69..3432fbf 100644
@@ -113,7 +113,6 @@ fork_exec(struct socket *so, const char *ex, int
 do_pty)
      struct sockaddr_in addr;
      socklen_t addrlen = sizeof(addr);
      int opt;
-        int master = -1;
      const char *argv[256];
      /* don't want to clobber the original */
      char *bptr;
slirp/misc.c +11 -20
@@ -148,32 +147,23 @@ fork_exec(struct socket *so, const char *ex, int
 do_pty)
       case -1:
          lprint("Error: fork failed: %s\n", strerror(errno));
          close(s);
-        if (do_pty == 2)
-           close(master);
          return 0;
 
       case 0:
                  setsid();
 
          /* Set the DISPLAY */
-        if (do_pty == 2) {
-            (void) close(master);
-#ifdef TIOCSCTTY /* XXXXX */
-            ioctl(s, TIOCSCTTY, (char *)NULL);
-#endif
-        } else {
-            getsockname(s, (struct sockaddr *)&addr,&addrlen);
-            close(s);
-            /*
-             * Connect to the socket
-             * XXX If any of these fail, we're in trouble!
-              */
-            s = qemu_socket(AF_INET, SOCK_STREAM, 0);
-            addr.sin_addr = loopback_addr;
-                        do {
-                            ret = connect(s, (struct sockaddr
 *)&addr, addrlen);
-                        } while (ret<  0&&  errno == EINTR);
-        }
+                getsockname(s, (struct sockaddr *)&addr,&addrlen);
+                close(s);
+                /*
+                 * Connect to the socket
+                 * XXX If any of these fail, we're in trouble!
+                 */
+                s = qemu_socket(AF_INET, SOCK_STREAM, 0);
+                addr.sin_addr = loopback_addr;
+                do {
+                    ret = connect(s, (struct sockaddr *)&addr, addrlen);
+                } while (ret<  0&&  errno == EINTR);
 
          dup2(s, 0);
          dup2(s, 1);
slirp/misc.c +5 -20
@@ -210,26 +200,21 @@ fork_exec(struct socket *so, const char *ex, int
 do_pty)
 
       default:
          qemu_add_child_watch(pid);
-        if (do_pty == 2) {
-            close(s);
-            so->s = master;
-        } else {
-            /*
-             * XXX this could block us...
-             * XXX Should set a timer here, and if accept() doesn't
-              * return after X seconds, declare it a failure
-              * The only reason this will block forever is if socket()
-              * of connect() fail in the child process
-              */
-                        do {
-                            so->s = accept(s, (struct sockaddr
 *)&addr,&addrlen);
-                        } while (so->s<  0&&  errno == EINTR);
-                        closesocket(s);
-            opt = 1;
-            setsockopt(so->s,SOL_SOCKET,SO_REUSEADDR,(char
 *)&opt,sizeof(int));
-            opt = 1;
-            setsockopt(so->s,SOL_SOCKET,SO_OOBINLINE,(char
 *)&opt,sizeof(int));
-        }
+                /*
+                 * XXX this could block us...
+                 * XXX Should set a timer here, and if accept() doesn't
+                 * return after X seconds, declare it a failure
+                 * The only reason this will block forever is if

socket()

slirp/misc.c +4 -0
+                 * of connect() fail in the child process
+                 */
+                do {
+                    so->s = accept(s, (struct sockaddr

*)&addr,&addrlen);

slirp/misc.c +4 -0
+                } while (so->s<  0&&  errno == EINTR);
+                closesocket(s);
+                opt = 1;
+                setsockopt(so->s, SOL_SOCKET, SO_REUSEADDR, (char

*)&opt, sizeof(int));

slirp/misc.c +2 -0
+                opt = 1;
+                setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, (char
*)&opt, sizeof(int));
          fd_nonblock(so->s);
Quoted 5 lines
Quoted 2 lines
          /* Append the telnet options now */

Ping. Please commit this patch.

Thanks, picked up for my slirp queue.

Jan