vcl: avoid updating errno on ldp init check

Type: fix

Signed-off-by: Florin Coras <fcoras@cisco.com>
Change-Id: I7f5887865aa29c9881b5063be1d7d42369a493c1
diff --git a/src/vcl/ldp.c b/src/vcl/ldp.c
index 4d62a73..b51d2e0 100644
--- a/src/vcl/ldp.c
+++ b/src/vcl/ldp.c
@@ -179,14 +179,13 @@
   pool_alloc (ldp->workers, LDP_MAX_NWORKERS);
 }
 
-static inline int
+static int
 ldp_init (void)
 {
   ldp_worker_ctx_t *ldpw;
   int rv;
 
-  if (PREDICT_TRUE (ldp->init))
-    return 0;
+  ASSERT (!ldp->init);
 
   ldp->init = 1;
   ldp->vcl_needs_real_epoll = 1;
@@ -295,14 +294,20 @@
   return 0;
 }
 
+#define ldp_init_check()                                                      \
+  if (PREDICT_FALSE (!ldp->init))                                             \
+    {                                                                         \
+      if ((errno = -ldp_init ()))                                             \
+	return -1;                                                            \
+    }
+
 int
 close (int fd)
 {
   vls_handle_t vlsh;
   int rv, epfd;
 
-  if ((errno = -ldp_init ()))
-    return -1;
+  ldp_init_check ();
 
   vlsh = ldp_fd_to_vlsh (fd);
   if (vlsh != VLS_INVALID_HANDLE)
@@ -353,8 +358,7 @@
   vls_handle_t vlsh;
   ssize_t size;
 
-  if ((errno = -ldp_init ()))
-    return -1;
+  ldp_init_check ();
 
   vlsh = ldp_fd_to_vlsh (fd);
   if (vlsh != VLS_INVALID_HANDLE)
@@ -381,8 +385,7 @@
   vls_handle_t vlsh;
   ssize_t size = 0;
 
-  if ((errno = -ldp_init ()))
-    return -1;
+  ldp_init_check ();
 
   vlsh = ldp_fd_to_vlsh (fd);
   if (vlsh != VLS_INVALID_HANDLE)
@@ -421,8 +424,7 @@
   vls_handle_t vlsh;
   ssize_t size = 0;
 
-  if ((errno = -ldp_init ()))
-    return -1;
+  ldp_init_check ();
 
   vlsh = ldp_fd_to_vlsh (fd);
   if (vlsh != VLS_INVALID_HANDLE)
@@ -449,8 +451,7 @@
   vls_handle_t vlsh;
   int i, rv = 0;
 
-  if ((errno = -ldp_init ()))
-    return -1;
+  ldp_init_check ();
 
   vlsh = ldp_fd_to_vlsh (fd);
   if (vlsh != VLS_INVALID_HANDLE)
@@ -543,8 +544,7 @@
   va_list ap;
   int rv;
 
-  if ((errno = -ldp_init ()))
-    return -1;
+  ldp_init_check ();
 
   va_start (ap, cmd);
   rv = fcntl_internal (fd, cmd, ap);
@@ -559,8 +559,7 @@
   va_list ap;
   int rv;
 
-  if ((errno = -ldp_init ()))
-    return -1;
+  ldp_init_check ();
 
   va_start (ap, cmd);
   rv = fcntl_internal (fd, cmd, ap);
@@ -575,8 +574,7 @@
   va_list ap;
   int rv;
 
-  if ((errno = -ldp_init ()))
-    return -1;
+  ldp_init_check ();
 
   va_start (ap, cmd);
 
@@ -980,8 +978,7 @@
   u8 is_nonblocking = type & SOCK_NONBLOCK ? 1 : 0;
   vls_handle_t vlsh;
 
-  if ((errno = -ldp_init ()))
-    return -1;
+  ldp_init_check ();
 
   if (((domain == AF_INET) || (domain == AF_INET6)) &&
       ((sock_type == SOCK_STREAM) || (sock_type == SOCK_DGRAM)))
@@ -1035,8 +1032,7 @@
 {
   int rv, sock_type = type & ~(SOCK_CLOEXEC | SOCK_NONBLOCK);
 
-  if ((errno = -ldp_init ()))
-    return -1;
+  ldp_init_check ();
 
   if (((domain == AF_INET) || (domain == AF_INET6)) &&
       ((sock_type == SOCK_STREAM) || (sock_type == SOCK_DGRAM)))
@@ -1060,8 +1056,7 @@
   vls_handle_t vlsh;
   int rv;
 
-  if ((errno = -ldp_init ()))
-    return -1;
+  ldp_init_check ();
 
   vlsh = ldp_fd_to_vlsh (fd);
   if (vlsh != VLS_INVALID_HANDLE)
@@ -1134,8 +1129,7 @@
   int rv = 0;
   int sa_len, copy_len;
 
-  if ((errno = -ldp_init ()))
-    return -1;
+  ldp_init_check ();
 
   if (addr && len && ep)
     {
@@ -1179,8 +1173,7 @@
   vls_handle_t vlsh;
   int rv;
 
-  if ((errno = -ldp_init ()))
-    return -1;
+  ldp_init_check ();
 
   vlsh = ldp_fd_to_vlsh (fd);
   if (vlsh != VLS_INVALID_HANDLE)
@@ -1221,8 +1214,7 @@
   vls_handle_t vlsh;
   int rv;
 
-  if ((errno = -ldp_init ()))
-    return -1;
+  ldp_init_check ();
 
   if (!addr)
     {
@@ -1303,8 +1295,7 @@
   vls_handle_t vlsh;
   int rv;
 
-  if ((errno = -ldp_init ()))
-    return -1;
+  ldp_init_check ();
 
   vlsh = ldp_fd_to_vlsh (fd);
   if (vlsh != VLS_INVALID_HANDLE)
@@ -1344,8 +1335,7 @@
   vls_handle_t vlsh = ldp_fd_to_vlsh (fd);
   ssize_t size;
 
-  if ((errno = -ldp_init ()))
-    return -1;
+  ldp_init_check ();
 
   if (vlsh != VLS_INVALID_HANDLE)
     {
@@ -1371,8 +1361,7 @@
   vls_handle_t vlsh;
   ssize_t size = 0;
 
-  if ((errno = -ldp_init ()))
-    return -1;
+  ldp_init_check ();
 
   vlsh = ldp_fd_to_vlsh (out_fd);
   if (vlsh != VLS_INVALID_HANDLE)
@@ -1521,8 +1510,7 @@
   vls_handle_t vlsh;
   ssize_t size;
 
-  if ((errno = -ldp_init ()))
-    return -1;
+  ldp_init_check ();
 
   vlsh = ldp_fd_to_vlsh (fd);
   if (vlsh != VLS_INVALID_HANDLE)
@@ -1612,8 +1600,7 @@
   vls_handle_t vlsh;
   ssize_t size;
 
-  if ((errno = -ldp_init ()))
-    return -1;
+  ldp_init_check ();
 
   vlsh = ldp_fd_to_vlsh (fd);
   if (vlsh != INVALID_SESSION_ID)
@@ -1640,8 +1627,7 @@
   vls_handle_t vlsh;
   ssize_t size;
 
-  if ((errno = -ldp_init ()))
-    return -1;
+  ldp_init_check ();
 
   vlsh = ldp_fd_to_vlsh (fd);
   if (vlsh != VLS_INVALID_HANDLE)
@@ -1667,8 +1653,7 @@
   vls_handle_t vlsh;
   ssize_t size;
 
-  if ((errno = -ldp_init ()))
-    return -1;
+  ldp_init_check ();
 
   vlsh = ldp_fd_to_vlsh (fd);
   if (vlsh != VLS_INVALID_HANDLE)
@@ -1715,8 +1700,7 @@
   const char *func_str;
   u32 sh = ldp_fd_to_vlsh (fd);
 
-  if ((errno = -ldp_init ()))
-    return -1;
+  ldp_init_check ();
 
   if (sh != INVALID_SESSION_ID)
     {
@@ -1761,8 +1745,7 @@
   vls_handle_t vlsh;
   ssize_t size;
 
-  if ((errno = -ldp_init ()))
-    return -1;
+  ldp_init_check ();
 
   vlsh = ldp_fd_to_vlsh (fd);
   if (vlsh != VLS_INVALID_HANDLE)
@@ -1817,8 +1800,7 @@
   const char *func_str;
   u32 sh = ldp_fd_to_vlsh (fd);
 
-  if ((errno = -ldp_init ()))
-    return -1;
+  ldp_init_check ();
 
   if (sh != INVALID_SESSION_ID)
     {
@@ -1865,8 +1847,7 @@
   vls_handle_t vlsh;
   int rv;
 
-  if ((errno = -ldp_init ()))
-    return -1;
+  ldp_init_check ();
 
   vlsh = ldp_fd_to_vlsh (fd);
   if (vlsh != VLS_INVALID_HANDLE)
@@ -1995,8 +1976,7 @@
   vls_handle_t vlsh;
   int rv;
 
-  if ((errno = -ldp_init ()))
-    return -1;
+  ldp_init_check ();
 
   vlsh = ldp_fd_to_vlsh (fd);
   if (vlsh != VLS_INVALID_HANDLE)
@@ -2100,8 +2080,7 @@
   vls_handle_t vlsh;
   int rv;
 
-  if ((errno = -ldp_init ()))
-    return -1;
+  ldp_init_check ();
 
   vlsh = ldp_fd_to_vlsh (fd);
   if (vlsh != VLS_INVALID_HANDLE)
@@ -2132,8 +2111,7 @@
   vls_handle_t listen_vlsh, accept_vlsh;
   int rv;
 
-  if ((errno = -ldp_init ()))
-    return -1;
+  ldp_init_check ();
 
   listen_vlsh = ldp_fd_to_vlsh (listen_fd);
   if (listen_vlsh != VLS_INVALID_HANDLE)
@@ -2200,8 +2178,7 @@
   int rv = 0, flags;
   u32 flags_len = sizeof (flags);
 
-  if ((errno = -ldp_init ()))
-    return -1;
+  ldp_init_check ();
 
   vlsh = ldp_fd_to_vlsh (fd);
   if (vlsh != VLS_INVALID_HANDLE)
@@ -2241,8 +2218,7 @@
   vls_handle_t vlsh;
   int rv;
 
-  if ((errno = -ldp_init ()))
-    return -1;
+  ldp_init_check ();
 
   if (ldp->vcl_needs_real_epoll || vls_use_real_epoll ())
     {
@@ -2285,8 +2261,7 @@
   vls_handle_t vep_vlsh, vlsh;
   int rv;
 
-  if ((errno = -ldp_init ()))
-    return -1;
+  ldp_init_check ();
 
   vep_vlsh = ldp_fd_to_vlsh (epfd);
   if (PREDICT_FALSE (vep_vlsh == VLS_INVALID_HANDLE))
@@ -2373,8 +2348,7 @@
   int libc_epfd, rv = 0;
   vls_handle_t ep_vlsh;
 
-  if ((errno = -ldp_init ()))
-    return -1;
+  ldp_init_check ();
 
   if (PREDICT_FALSE (!events || (timeout < -1)))
     {
@@ -2450,8 +2424,7 @@
   int libc_epfd, rv = 0, num_ev;
   vls_handle_t ep_vlsh;
 
-  if ((errno = -ldp_init ()))
-    return -1;
+  ldp_init_check ();
 
   if (PREDICT_FALSE (!events || (timeout < -1)))
     {
@@ -2686,8 +2659,7 @@
 ppoll (struct pollfd *fds, nfds_t nfds,
        const struct timespec *timeout, const sigset_t * sigmask)
 {
-  if ((errno = -ldp_init ()))
-    return -1;
+  ldp_init_check ();
 
   clib_warning ("LDP<%d>: LDP-TBD", getpid ());
   errno = ENOSYS;