[network-manager-openswan/dcbw/libreswan: 2/16] fixup! core: make find_ipsec() generic



commit 67ed4b42619be5a15e18130643aac89709eaa7ba
Author: Dan Williams <dcbw redhat com>
Date:   Mon Dec 1 19:11:14 2014 -0600

    fixup! core: make find_ipsec() generic

 src/nm-openswan-service.c |   52 ++++++++++++++++++++++++++------------------
 1 files changed, 31 insertions(+), 21 deletions(-)
---
diff --git a/src/nm-openswan-service.c b/src/nm-openswan-service.c
index 35821ee..79b1d16 100644
--- a/src/nm-openswan-service.c
+++ b/src/nm-openswan-service.c
@@ -256,42 +256,52 @@ static gboolean connect_step (NMOpenSwanPlugin *self, GError **error);
 static gboolean pr_cb (GIOChannel *source, GIOCondition condition, gpointer user_data);
 
 static const char *
-find_helper (const char *progname, GError **error)
+_find_helper (const char *progname, const char **paths, GError **error)
 {
-       static const char *paths[] = {
-               PREFIX "/sbin/",
-               PREFIX "/bin/",
-               "/sbin/",
-               "/usr/sbin/",
-               "/usr/local/sbin/",
-               "/usr/bin/",
-               "/usr/local/bin/",
-       };
-       guint i;
+       const char **iter = paths;
        GString *tmp;
-       const char *ret;
+       const char *ret = NULL;
 
        if (error)
                g_return_val_if_fail (*error == NULL, NULL);
 
        tmp = g_string_sized_new (50);
-       for (i = 0; i < G_N_ELEMENTS (paths); i++) {
-               g_string_append_printf (tmp, "%s%s", paths[i], progname);
+       for (iter = paths; iter && *iter; iter++) {
+               g_string_append_printf (tmp, "%s%s", *iter, progname);
                if (g_file_test (tmp->str, G_FILE_TEST_EXISTS)) {
                        ret = g_intern_string (tmp->str);
-                       g_string_free (tmp, TRUE);
-                       return ret;
+                       break;
                }
                g_string_set_size (tmp, 0);
        }
        g_string_free (tmp, TRUE);
 
-       g_set_error (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_LAUNCH_FAILED,
-                    "Could not find %s binary",
-                    progname);
-       return NULL;
+       if (!ret) {
+               g_set_error (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_LAUNCH_FAILED,
+                            "Could not find %s binary",
+                            progname);
+       }
+       return ret;
 }
 
+static const char *
+find_helper_bin (const char *progname, GError **error)
+{
+       static const char *paths[] = {
+               PREFIX "/sbin/",
+               PREFIX "/bin/",
+               "/sbin/",
+               "/usr/sbin/",
+               "/usr/local/sbin/",
+               "/usr/bin/",
+               "/usr/local/bin/",
+               NULL,
+       };
+
+       return _find_helper (progname, paths, error);
+}
+
+
 static void
 pipe_init (Pipe *pipe, int fd, const char *detail)
 {
@@ -990,7 +1000,7 @@ _connect_common (NMVPNPlugin   *plugin,
                return FALSE;
        }
 
-       priv->ipsec_path = find_helper ("ipsec", error);
+       priv->ipsec_path = find_helper_bin ("ipsec", error);
        if (!priv->ipsec_path)
                return FALSE;
 


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