libmemif: fix autoconnect 19/20819/2
authorJakub Grajciar <jgrajcia@cisco.com>
Wed, 24 Jul 2019 08:33:11 +0000 (10:33 +0200)
committerDamjan Marion <dmarion@me.com>
Fri, 26 Jul 2019 14:51:59 +0000 (14:51 +0000)
Type: fix

Change-Id: I426e210c47869904a01712b765db2356439f706f
Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
extras/libmemif/src/main.c

index 5f92f02..42dfeaf 100644 (file)
@@ -901,8 +901,6 @@ memif_create (memif_conn_handle_t * c, memif_conn_args_t * args,
     }
   else
     {
-      lm->disconn_slaves++;
-
       elt.key = -1;
       elt.data_struct = conn;
       if ((index =
@@ -916,7 +914,7 @@ memif_create (memif_conn_handle_t * c, memif_conn_args_t * args,
 
       /* try connectiong to master */
       err = memif_request_connection (conn);
-      if ((err < 0) && (lm->disconn_slaves == 1))
+      if ((err != MEMIF_ERR_SUCCESS) && (lm->disconn_slaves == 0))
        {
          /* connection failed, arm reconnect timer (if not armed) */
          if (timerfd_settime (lm->timerfd, 0, &lm->arm, NULL) < 0)
@@ -925,6 +923,7 @@ memif_create (memif_conn_handle_t * c, memif_conn_args_t * args,
              goto error;
            }
        }
+       lm->disconn_slaves++;
     }
 
   *c = conn;
@@ -995,8 +994,9 @@ memif_request_connection (memif_conn_handle_t c)
     }
   else
     {
+      err = memif_syscall_error_handler (errno);
       strcpy ((char *) conn->remote_disconnect_string,
-             memif_strerror (memif_syscall_error_handler (errno)));
+             memif_strerror (err));
       goto error;
     }