vcl: fix ldp read on closing session
[vpp.git] / src / vcl / ldp.c
index 70a4299..95c0edc 100644 (file)
@@ -109,7 +109,11 @@ typedef struct
 
 #define LDBG(_lvl, _fmt, _args...)                                     \
   if (ldp->debug > _lvl)                                               \
-    clib_warning ("ldp<%d>: " _fmt, getpid(), ##_args)
+    {                                                                  \
+      int errno_saved = errno;                                         \
+      clib_warning ("ldp<%d>: " _fmt, getpid(), ##_args);              \
+      errno = errno_saved;                                             \
+    }
 
 static ldp_main_t ldp_main = {
   .vlsh_bit_val = (1 << LDP_SID_BIT_MIN),
@@ -132,11 +136,8 @@ ldp_worker_get_current (void)
 static inline void
 ldp_set_app_name (char *app_name)
 {
-  int rv = snprintf (ldp->app_name, LDP_APP_NAME_MAX,
-                    "ldp-%d-%s", getpid (), app_name);
-
-  if (rv >= LDP_APP_NAME_MAX)
-    app_name[LDP_APP_NAME_MAX - 1] = 0;
+  snprintf (ldp->app_name, LDP_APP_NAME_MAX,
+           "ldp-%d-%s", getpid (), app_name);
 }
 
 static inline char *
@@ -379,24 +380,19 @@ readv (int fd, const struct iovec * iov, int iovcnt)
   vlsh = ldp_fd_to_vlsh (fd);
   if (vlsh != VLS_INVALID_HANDLE)
     {
-      do
+      for (i = 0; i < iovcnt; ++i)
        {
-         for (i = 0; i < iovcnt; ++i)
+         rv = vls_read (vlsh, iov[i].iov_base, iov[i].iov_len);
+         if (rv <= 0)
+           break;
+         else
            {
-             rv = vls_read (vlsh, iov[i].iov_base, iov[i].iov_len);
-             if (rv < 0)
+             total += rv;
+             if (rv < iov[i].iov_len)
                break;
-             else
-               {
-                 total += rv;
-                 if (rv < iov[i].iov_len)
-                   break;
-               }
            }
        }
-      while ((rv >= 0) && (total == 0));
-
-      if (rv < 0)
+      if (rv < 0 && total == 0)
        {
          errno = -rv;
          size = -1;
@@ -485,8 +481,13 @@ writev (int fd, const struct iovec * iov, int iovcnt)
   return size;
 }
 
+#ifdef HAVE_FCNTL64
+int
+fcntl64 (int fd, int cmd, ...)
+#else
 int
 fcntl (int fd, int cmd, ...)
+#endif
 {
   vls_handle_t vlsh;
   int rv = 0;
@@ -534,7 +535,11 @@ fcntl (int fd, int cmd, ...)
     }
   else
     {
+#ifdef HAVE_FCNTL64
+      rv = libc_vfcntl64 (fd, cmd, ap);
+#else
       rv = libc_vfcntl (fd, cmd, ap);
+#endif
     }
 
   va_end (ap);
@@ -643,6 +648,7 @@ ldp_select_vcl_map_to_libc (clib_bitmap_t * vclb, fd_set * __restrict libcb)
   /* *INDENT-OFF* */
   clib_bitmap_foreach (si, vclb, ({
     vlsh = vls_session_index_to_vlsh (si);
+    ASSERT (vlsh != VLS_INVALID_HANDLE);
     fd = ldp_vlsh_to_fd (vlsh);
     if (PREDICT_FALSE (fd < 0))
       {