vcl: fix ldp fcntl64 58/27258/2
authorFlorin Coras <fcoras@cisco.com>
Tue, 26 May 2020 19:45:45 +0000 (19:45 +0000)
committerAndrew Yourtchenko <ayourtch@gmail.com>
Wed, 27 May 2020 11:23:34 +0000 (11:23 +0000)
Type: fix
Ticket: VPP-1882

Signed-off-by: Florin Coras <fcoras@cisco.com>
Change-Id: I342d8f928fcc7de74f9bd288c1a5d63ea1f90020
(cherry picked from commit 0ab36f55753d3d1417c41f8a3aec5e79a882555c)

src/vcl/ldp.c
src/vcl/ldp_socket_wrapper.c
src/vcl/ldp_socket_wrapper.h

index 091c7e5..8492f02 100644 (file)
@@ -477,17 +477,11 @@ writev (int fd, const struct iovec * iov, int iovcnt)
   return size;
 }
 
-int
-fcntl (int fd, int cmd, ...)
+static int
+fcntl_internal (int fd, int cmd, va_list ap)
 {
   vls_handle_t vlsh;
   int rv = 0;
-  va_list ap;
-
-  if ((errno = -ldp_init ()))
-    return -1;
-
-  va_start (ap, cmd);
 
   vlsh = ldp_fd_to_vlsh (fd);
   LDBG (0, "fd %u vlsh %d, cmd %u", fd, vlsh, cmd);
@@ -533,6 +527,20 @@ fcntl (int fd, int cmd, ...)
 #endif
     }
 
+  return rv;
+}
+
+int
+fcntl (int fd, int cmd, ...)
+{
+  va_list ap;
+  int rv;
+
+  if ((errno = -ldp_init ()))
+    return -1;
+
+  va_start (ap, cmd);
+  rv = fcntl_internal (fd, cmd, ap);
   va_end (ap);
 
   return rv;
@@ -544,8 +552,11 @@ fcntl64 (int fd, int cmd, ...)
   va_list ap;
   int rv;
 
+  if ((errno = -ldp_init ()))
+    return -1;
+
   va_start (ap, cmd);
-  rv = fcntl (fd, cmd, ap);
+  rv = fcntl_internal (fd, cmd, ap);
   va_end (ap);
   return rv;
 }
index 38ee297..2538471 100644 (file)
@@ -550,45 +550,16 @@ libc_eventfd (int count, int flags)
 int
 libc_vfcntl (int fd, int cmd, va_list ap)
 {
-  long int args[4];
-  int rc;
-  int i;
-
   swrap_bind_symbol_libc (fcntl);
-
-  for (i = 0; i < 4; i++)
-    {
-      args[i] = va_arg (ap, long int);
-    }
-
-  rc = swrap.libc.symbols._libc_fcntl.f (fd,
-                                        cmd,
-                                        args[0], args[1], args[2], args[3]);
-
-  return rc;
+  return swrap.libc.symbols._libc_fcntl.f (fd, cmd, va_arg (ap, long int));
 }
 
 #ifdef HAVE_FCNTL64
 int
 libc_vfcntl64 (int fd, int cmd, va_list ap)
 {
-  long int args[4];
-  int rc;
-  int i;
-
   swrap_bind_symbol_libc (fcntl64);
-
-  for (i = 0; i < 4; i++)
-    {
-      args[i] = va_arg (ap, long int);
-    }
-
-  rc = swrap.libc.symbols._libc_fcntl64.f (fd,
-                                          cmd,
-                                          args[0], args[1], args[2],
-                                          args[3]);
-
-  return rc;
+  return swrap.libc.symbols._libc_fcntl64.f (fd, cmd, va_arg (ap, long int));
 }
 #endif
 
index 94529e3..0d167cf 100644 (file)
@@ -122,7 +122,9 @@ int libc_eventfd (int count, int flags);
 
 int libc_vfcntl (int fd, int cmd, va_list ap);
 
+#ifdef HAVE_FCNTL64
 int libc_vfcntl64 (int fd, int cmd, va_list ap);
+#endif
 
 int libc_vioctl (int fd, int cmd, va_list ap);