[NetworkManager-libreswan/nm-1-0: 19/51] service: retry the ipsec auto --ready with some timeout



commit 85f14e2e7084c08f233c1ad034e0108439f770bc
Author: Lubomir Rintel <lkundrak v3 sk>
Date:   Fri Aug 21 15:26:09 2015 +0200

    service: retry the ipsec auto --ready with some timeout
    
    ipsec setup start needs some time to start.
    
    (cherry picked from commit 925cde81255d5d9487156833e792f706709e0767)

 src/nm-openswan-service.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
---
diff --git a/src/nm-openswan-service.c b/src/nm-openswan-service.c
index d0e9f64..3a3617b 100644
--- a/src/nm-openswan-service.c
+++ b/src/nm-openswan-service.c
@@ -88,6 +88,7 @@ typedef struct {
 
        GPid pid;
        guint watch_id;
+       guint retries;
        ConnectStep connect_step;
        NMConnection *connection;
 
@@ -443,6 +444,19 @@ connect_failed (NMOpenSwanPlugin *self,
        nm_vpn_plugin_failure (NM_VPN_PLUGIN (self), reason);
 }
 
+static gboolean
+retry_cb (gpointer user_data)
+{
+       NMOpenSwanPlugin *self = NM_OPENSWAN_PLUGIN (user_data);
+       GError *error = NULL;
+
+       if (!connect_step (self, &error))
+               connect_failed (self, TRUE, error, NM_VPN_PLUGIN_FAILURE_CONNECT_FAILED);
+       g_clear_error (&error);
+
+       return FALSE;
+}
+
 static void
 child_watch_cb (GPid pid, gint status, gpointer user_data)
 {
@@ -466,17 +480,25 @@ child_watch_cb (GPid pid, gint status, gpointer user_data)
        if (WIFEXITED (status)) {
                ret = WEXITSTATUS (status);
                if (ret)
-                       g_warning ("Spawn: child %d exited with error code %d", pid, ret);
+                       g_message ("Spawn: child %d exited with error code %d", pid, ret);
        } else
                g_warning ("Spawn: child %d died unexpectedly", pid);
 
        /* Reap child */
        waitpid (pid, NULL, WNOHANG);
 
+       if (ret != 0 && priv->retries) {
+               priv->retries--;
+               g_message ("Spawn: %d more tries...", priv->retries);
+               g_timeout_add (100, retry_cb, self);
+               return;
+       }
+
        if (ret == 0) {
                /* Success; do the next connect step */
                do_stop = TRUE;
                priv->connect_step++;
+               priv->retries = 0;
                if (!connect_step (self, &error))
                        ret = 1;
        }
@@ -1007,6 +1029,8 @@ connect_step (NMOpenSwanPlugin *self, GError **error)
                return TRUE;
 
        case CONNECT_STEP_WAIT_READY:
+               if (!priv->retries)
+                       priv->retries = 30;
                if (!do_spawn (&priv->pid, NULL, NULL, error, priv->ipsec_path, "auto", "--ready", NULL))
                        return FALSE;
                priv->watch_id = g_child_watch_add (priv->pid, child_watch_cb, self);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]