[network-manager-openvpn/th/chroot-rh1377708: 6/7] service: create runstate dir for management socket



commit 648c6b1a4487a146ed3a98c456648b266c03797e
Author: Thomas Haller <thaller redhat com>
Date:   Tue Sep 20 22:30:03 2016 +0200

    service: create runstate dir for management socket
    
    Without this, the directory for the management socket
    must already exist. That is usually not the case
    when installing to a separate prefix.

 src/nm-openvpn-service.c |   43 ++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 40 insertions(+), 3 deletions(-)
---
diff --git a/src/nm-openvpn-service.c b/src/nm-openvpn-service.c
index 11fccd6..e9d2b50 100644
--- a/src/nm-openvpn-service.c
+++ b/src/nm-openvpn-service.c
@@ -54,6 +54,8 @@
 # define DIST_VERSION VERSION
 #endif
 
+#define RUNDIR  LOCALSTATEDIR"/run/NetworkManager"
+
 static struct {
        gboolean debug;
        int log_level;
@@ -1029,6 +1031,40 @@ update_io_data_from_vpn_setting (NMOpenvpnPluginIOData *io_data,
        io_data->proxy_password = tmp ? g_strdup (tmp) : NULL;
 }
 
+static char *
+mgt_path_create (NMConnection *connection, GError **error)
+{
+       int errsv;
+       gs_free char *s = NULL;
+
+       /* Setup runtime directory */
+       if (g_mkdir_with_parents (RUNDIR, 0755) != 0) {
+               errsv = errno;
+               if (errsv != EEXIST) {
+                       g_set_error (error,
+                                    NM_VPN_PLUGIN_ERROR,
+                                    NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
+                                    "Cannot create run-dir %s (%s)",
+                                    RUNDIR, g_strerror (errsv));
+                       return NULL;
+               }
+       }
+
+       s = g_strdup_printf (RUNDIR"/nm-openvpn-%s",
+                            nm_connection_get_uuid (connection));
+
+       if (g_file_test (s, G_FILE_TEST_EXISTS)) {
+               g_set_error (error,
+                            NM_VPN_PLUGIN_ERROR,
+                            NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
+                            "management socket %s already exists",
+                            s);
+               return NULL;
+       }
+
+       return g_steal_pointer (&s);
+}
+
 #define MAX_GROUPS 128
 static gboolean
 is_dir_writable (const char *dir, const char *user)
@@ -1566,10 +1602,11 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
        add_openvpn_arg (args, "--persist-tun");
 
        /* Management socket for localhost access to supply username and password */
+       g_clear_pointer (&priv->mgt_path, g_free);
+       priv->mgt_path = mgt_path_create (connection, error);
+       if (!priv->mgt_path)
+               return FALSE;
        add_openvpn_arg (args, "--management");
-       g_warn_if_fail (priv->mgt_path == NULL);
-       priv->mgt_path = g_strdup_printf (LOCALSTATEDIR "/run/NetworkManager/nm-openvpn-%s",
-                                         nm_connection_get_uuid (connection));
        add_openvpn_arg (args, priv->mgt_path);
        add_openvpn_arg (args, "unix");
        add_openvpn_arg (args, "--management-client-user");


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