[Openvpn-devel,2/9] Remove getpeername, getpid check

Message ID 20210512131511.1309914-3-arne@rfc2549.org
State Accepted
Headers show
Series
  • Miscellaneous cleanup patches/small fixes
Related show

Commit Message

Arne Schwabe May 12, 2021, 1:15 p.m.
getpeername is part of SUSv3 and Windows also provides the function
as part of winsocks.

getpid is also provided by both Posix and windows and we do not even
use getpid on Windows since we rather call GetCurrentProcessId.

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
---
 configure.ac           | 4 ++--
 src/openvpn/platform.c | 4 ----
 src/openvpn/socket.c   | 7 -------
 3 files changed, 2 insertions(+), 13 deletions(-)

Comments

Gert Doering May 14, 2021, 12:08 p.m. | #1
Acked-by: Gert Doering <gert@greenie.muc.de>

"because it makes sense" (we discussed this on IRC, and I couldn't
find anything in my software museum that has no getpeername() - not
even SCO Unix! - and checking for getpid() borders on ridiculous...)

Stared-at-patch, test compiled on Linux.

Your patch has been applied to the master branch.

commit 84e14209232441fd6601d3efb7c7aa93bee4ce88
Author: Arne Schwabe
Date:   Wed May 12 15:15:04 2021 +0200

     Remove getpeername, getpid check

     Signed-off-by: Arne Schwabe <arne@rfc2549.org>
     Acked-by: Gert Doering <gert@greenie.muc.de>
     Message-Id: <20210512131511.1309914-3-arne@rfc2549.org>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg22340.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering

Patch

diff --git a/configure.ac b/configure.ac
index dce7982cc..cc1dedbb9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -619,10 +619,10 @@  AC_CHECK_DECLS(
 AC_FUNC_FORK
 
 AC_CHECK_FUNCS([ \
-	daemon chroot getpwnam setuid nice system getpid dup dup2 \
+	daemon chroot getpwnam setuid nice system dup dup2 \
 	syslog openlog mlockall getrlimit getgrnam setgid \
 	setgroups flock readv writev time gettimeofday \
-	setsid chdir getpeername \
+	setsid chdir \
 	chsize ftruncate execve getpeereid basename dirname access \
 	epoll_create strsep \
 ])
diff --git a/src/openvpn/platform.c b/src/openvpn/platform.c
index bf7b1aa0a..831cc46b1 100644
--- a/src/openvpn/platform.c
+++ b/src/openvpn/platform.c
@@ -184,11 +184,7 @@  platform_getpid(void)
 #ifdef _WIN32
     return (unsigned int) GetCurrentProcessId();
 #else
-#ifdef HAVE_GETPID
     return (unsigned int) getpid();
-#else
-    return 0;
-#endif
 #endif
 }
 
diff --git a/src/openvpn/socket.c b/src/openvpn/socket.c
index 407e411c0..02a6a7db4 100644
--- a/src/openvpn/socket.c
+++ b/src/openvpn/socket.c
@@ -1227,7 +1227,6 @@  socket_do_accept(socket_descriptor_t sd,
 
     CLEAR(*act);
 
-#ifdef HAVE_GETPEERNAME
     if (nowait)
     {
         new_sd = getpeername(sd, &act->dest.addr.sa, &remote_len);
@@ -1241,12 +1240,6 @@  socket_do_accept(socket_descriptor_t sd,
             new_sd = sd;
         }
     }
-#else  /* ifdef HAVE_GETPEERNAME */
-    if (nowait)
-    {
-        msg(M_WARN, "TCP: this OS does not provide the getpeername() function");
-    }
-#endif
     else
     {
         new_sd = accept(sd, &act->dest.addr.sa, &remote_len);