[network-manager-openvpn/lr/multiple-vpn: 4/5] service: add --bus-name argument



commit 52d635a85039e9a825017f791c20ec837b368a1e
Author: Lubomir Rintel <lkundrak v3 sk>
Date:   Wed Aug 19 11:36:01 2015 +0200

    service: add --bus-name argument
    
    Make it possible to specify a different bus name to acquire.

 nm-openvpn-service.name.in |    1 +
 src/nm-openvpn-service.c   |   15 +++++++++------
 src/nm-openvpn-service.h   |    2 +-
 3 files changed, 11 insertions(+), 7 deletions(-)
---
diff --git a/nm-openvpn-service.name.in b/nm-openvpn-service.name.in
index 403105b..973fa0a 100644
--- a/nm-openvpn-service.name.in
+++ b/nm-openvpn-service.name.in
@@ -2,6 +2,7 @@
 name=openvpn
 service=org.freedesktop.NetworkManager.openvpn
 program= LIBEXECDIR@/nm-openvpn-service
+supports-multiple-connections=true
 
 [libnm]
 plugin= PLUGINDIR@/libnm-vpn-plugin-openvpn.so
diff --git a/src/nm-openvpn-service.c b/src/nm-openvpn-service.c
index aad65f8..ba2adc6 100644
--- a/src/nm-openvpn-service.c
+++ b/src/nm-openvpn-service.c
@@ -947,6 +947,7 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
        char *stmp;
        const char *defport, *proto_tcp;
        const char *nm_openvpn_user, *nm_openvpn_group, *nm_openvpn_chroot;
+       gchar *bus_name;
 
        /* Find openvpn */
        openvpn_binary = nm_find_openvpn ();
@@ -1295,8 +1296,9 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
 
        /* Up script, called when connection has been established or has been restarted */
        add_openvpn_arg (args, "--up");
-       stmp = g_strdup_printf ("%s%s %s --", NM_OPENVPN_HELPER_PATH, debug ? " --helper-debug" : "",
-                               dev_type_is_tap ? "--tap" : "--tun");
+       g_object_get (plugin, NM_VPN_SERVICE_PLUGIN_DBUS_SERVICE_NAME, &bus_name, NULL);
+       stmp = g_strdup_printf ("%s%s --bus-name %s %s --", NM_OPENVPN_HELPER_PATH, debug ? " --helper-debug" 
: "",
+                               bus_name, dev_type_is_tap ? "--tap" : "--tun");
        add_openvpn_arg (args, stmp);
        g_free (stmp);
        add_openvpn_arg (args, "--up-restart");
@@ -1771,14 +1773,13 @@ plugin_state_changed (NMOpenvpnPlugin *plugin,
 }
 
 NMOpenvpnPlugin *
-nm_openvpn_plugin_new (void)
+nm_openvpn_plugin_new (const char *bus_name)
 {
        NMOpenvpnPlugin *plugin;
        GError *error = NULL;
 
        plugin =  (NMOpenvpnPlugin *) g_initable_new (NM_TYPE_OPENVPN_PLUGIN, NULL, &error,
-                                                     NM_VPN_SERVICE_PLUGIN_DBUS_SERVICE_NAME,
-                                                     NM_DBUS_SERVICE_OPENVPN,
+                                                     NM_VPN_SERVICE_PLUGIN_DBUS_SERVICE_NAME, bus_name,
                                                      NULL);
 
        if (plugin) {
@@ -1824,10 +1825,12 @@ main (int argc, char *argv[])
        NMOpenvpnPlugin *plugin;
        gboolean persist = FALSE;
        GOptionContext *opt_ctx = NULL;
+       gchar *bus_name = NM_DBUS_SERVICE_OPENVPN;
 
        GOptionEntry options[] = {
                { "persist", 0, 0, G_OPTION_ARG_NONE, &persist, N_("Don't quit when VPN connection 
terminates"), NULL },
                { "debug", 0, 0, G_OPTION_ARG_NONE, &debug, N_("Enable verbose debug logging (may expose 
passwords)"), NULL },
+               { "bus-name", 0, 0, G_OPTION_ARG_STRING, &bus_name, N_("DBus name to use for this instance"), 
NULL },
                {NULL}
        };
 
@@ -1866,7 +1869,7 @@ main (int argc, char *argv[])
            && (system ("/sbin/modprobe tun") == -1))
                exit (EXIT_FAILURE);
 
-       plugin = nm_openvpn_plugin_new ();
+       plugin = nm_openvpn_plugin_new (bus_name);
        if (!plugin)
                exit (EXIT_FAILURE);
 
diff --git a/src/nm-openvpn-service.h b/src/nm-openvpn-service.h
index 5c3b0a4..df2ce60 100644
--- a/src/nm-openvpn-service.h
+++ b/src/nm-openvpn-service.h
@@ -46,6 +46,6 @@ typedef struct {
 
 GType nm_openvpn_plugin_get_type (void);
 
-NMOpenvpnPlugin *nm_openvpn_plugin_new (void);
+NMOpenvpnPlugin *nm_openvpn_plugin_new (const char *bus_name);
 
 #endif /* NM_OPENVPN_SERVICE_H */


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