diff options
-rw-r--r-- | meson_options.txt | 11 | ||||
-rw-r--r-- | src/backend/dbus/dbus.c | 38 | ||||
-rw-r--r-- | src/backend/dbus/meson.build | 49 | ||||
-rw-r--r-- | src/backend/dbus/org.libproxy.proxy-system.service.in | 4 | ||||
-rw-r--r-- | src/backend/dbus/org.libproxy.proxy.service.in | 2 | ||||
-rw-r--r-- | src/backend/dbus/proxyd.service.in | 14 | ||||
-rw-r--r-- | src/libproxy/proxy-dbus.c | 14 | ||||
-rw-r--r-- | src/tools/proxy.c | 6 |
8 files changed, 89 insertions, 49 deletions
diff --git a/meson_options.txt b/meson_options.txt index 04389b9..2927b76 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -16,7 +16,14 @@ option( 'dbus', type: 'feature', value: 'auto', - description: 'Whether to build dbus service' + description: 'Whether to build D-Bus service' +) + +option( + 'dbus-system-user', + type: 'string', + value: 'root', + description: 'Which user should be used on D-Bus system session' ) option( @@ -87,4 +94,4 @@ option( type: 'boolean', value: true, description: 'Whether to build introspection support' -)
\ No newline at end of file +) diff --git a/src/backend/dbus/dbus.c b/src/backend/dbus/dbus.c index a04c0f9..645b5e9 100644 --- a/src/backend/dbus/dbus.c +++ b/src/backend/dbus/dbus.c @@ -124,7 +124,8 @@ on_name_lost (GDBusConnection *connection, g_warning ("Can't connect proxy bus"); g_main_loop_quit (user_data); } else { - g_error ("Unknown name lost error"); + g_warning ("Unknown name lost error"); + g_main_loop_quit (user_data); } } @@ -133,12 +134,43 @@ main (int argc, char **argv) { GMainLoop *loop; + GBusNameOwnerFlags flags; + gboolean replace; + gboolean use_system; + GOptionContext *context; + g_autoptr (GError) error = NULL; + const GOptionEntry options[] = { + { "replace", 'r', 0, G_OPTION_ARG_NONE, &replace, "Replace old daemon.", NULL }, + { "system", 's', 0, G_OPTION_ARG_NONE, &use_system, "Use system session.", NULL }, + { NULL } + }; + + replace = FALSE; + use_system = FALSE; + + context = g_option_context_new (""); + g_option_context_set_summary (context, "Libproxy D-Bus Service"); + g_option_context_add_main_entries (context, options, "libproxy"); + + if (!g_option_context_parse (context, &argc, &argv, &error)) { + g_printerr ("%s: %s", g_get_application_name (), error->message); + g_printerr ("\n"); + g_printerr ("Try \"%s --help\" for more information.", + g_get_prgname ()); + g_printerr ("\n"); + g_option_context_free (context); + return 1; + } loop = g_main_loop_new (NULL, FALSE); - g_bus_own_name (G_BUS_TYPE_SESSION, + flags = G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT; + if (replace) + flags |= G_BUS_NAME_OWNER_FLAGS_REPLACE; + + g_bus_own_name (use_system ? G_BUS_TYPE_SYSTEM : G_BUS_TYPE_SESSION, "org.libproxy.proxy", - G_BUS_NAME_OWNER_FLAGS_NONE, + flags, on_bus_acquired, NULL, on_name_lost, diff --git a/src/backend/dbus/meson.build b/src/backend/dbus/meson.build index eb64fcd..250a105 100644 --- a/src/backend/dbus/meson.build +++ b/src/backend/dbus/meson.build @@ -4,13 +4,10 @@ if build_dbus unitdir = '' dbus_data_dir = join_paths(get_option('prefix'), get_option('datadir'), 'dbus-1') dbus_interfaces_dir = join_paths(dbus_data_dir, 'interfaces') - dbus_services_dir = join_paths(dbus_data_dir, 'services') - dbus_sysconf_dir = join_paths(dbus_data_dir, 'session.d') - - systemd = dependency('systemd', required: false) - if systemd.found() - unitdir = systemd.get_variable(pkgconfig: 'systemduserunitdir') - endif + dbus_user_services_dir = join_paths(dbus_data_dir, 'services') + dbus_system_services_dir = join_paths(dbus_data_dir, 'system-services') + dbus_user_conf_dir = join_paths(dbus_data_dir, 'session.d') + dbus_system_conf_dir = join_paths(dbus_data_dir, 'system.d') px_interface = [ 'org.libproxy.proxy.xml' @@ -59,29 +56,29 @@ if build_dbus install: true, ) - service_data = configuration_data() - service_data.set('LIBEXECDIR', join_paths(px_prefix, get_option('libexecdir'))) + # D-Bus Interface + install_data('org.libproxy.proxy.xml', install_dir : dbus_interfaces_dir) - dbus_service = configure_file( + # D-Bus User Service + user_service_data = configuration_data() + user_service_data.set('LIBEXECDIR', join_paths(px_prefix, get_option('libexecdir'))) + dbus_user_service = configure_file( input: 'org.libproxy.proxy.service.in', output: 'org.libproxy.proxy.service', - configuration: service_data + configuration: user_service_data ) + install_data(dbus_user_service, install_dir : dbus_user_services_dir) + install_data('org.libproxy.proxy.conf', install_dir : dbus_user_conf_dir) - install_data('org.libproxy.proxy.conf', install_dir : dbus_sysconf_dir) - install_data(dbus_service, install_dir : dbus_services_dir) - install_data('org.libproxy.proxy.xml', install_dir : dbus_interfaces_dir) - - service_data = configuration_data() - service_data.set('LIBEXECDIR', join_paths(px_prefix, get_option('libexecdir'))) - - service = configure_file( - input: 'proxyd.service.in', - output: 'proxyd.service', - configuration: service_data + # D-Bus System Service + system_service_data = configuration_data() + system_service_data.set('LIBEXECDIR', join_paths(px_prefix, get_option('libexecdir'))) + system_service_data.set('USER', get_option('dbus-system-user')) + dbus_system_service = configure_file( + input: 'org.libproxy.proxy-system.service.in', + output: 'org.libproxy.proxy-system.service', + configuration: system_service_data ) - - if unitdir != '' - install_data(service, install_dir: unitdir) - endif + install_data(dbus_system_service, rename : 'org.libproxy.proxy.service', install_dir : dbus_system_services_dir) + install_data('org.libproxy.proxy.conf', install_dir : dbus_system_conf_dir) endif diff --git a/src/backend/dbus/org.libproxy.proxy-system.service.in b/src/backend/dbus/org.libproxy.proxy-system.service.in new file mode 100644 index 0000000..2af960b --- /dev/null +++ b/src/backend/dbus/org.libproxy.proxy-system.service.in @@ -0,0 +1,4 @@ +[D-BUS Service] +Name=org.libproxy.proxy +Exec=@LIBEXECDIR@/proxyd --system +User=@USER@ diff --git a/src/backend/dbus/org.libproxy.proxy.service.in b/src/backend/dbus/org.libproxy.proxy.service.in index e958cd2..d1ac5f4 100644 --- a/src/backend/dbus/org.libproxy.proxy.service.in +++ b/src/backend/dbus/org.libproxy.proxy.service.in @@ -1,3 +1,3 @@ [D-BUS Service] Name=org.libproxy.proxy -Exec=@LIBEXECDIR@/proxyd
\ No newline at end of file +Exec=@LIBEXECDIR@/proxyd diff --git a/src/backend/dbus/proxyd.service.in b/src/backend/dbus/proxyd.service.in deleted file mode 100644 index 038e86d..0000000 --- a/src/backend/dbus/proxyd.service.in +++ /dev/null @@ -1,14 +0,0 @@ -[Unit] -Description=Libproxy user service - -[Service] -Type=dbus -BusName=org.libproxy.proxy -ExecStart=@LIBEXECDIR@/proxyd -#Environment="G_MESSAGES_DEBUG=all" - -MemoryDenyWriteExecute=yes -PrivateTmp=yes -ProtectHome=yes -ProtectSystem=full -RestrictRealtime=yes
\ No newline at end of file diff --git a/src/libproxy/proxy-dbus.c b/src/libproxy/proxy-dbus.c index 1587c73..6b594e3 100644 --- a/src/libproxy/proxy-dbus.c +++ b/src/libproxy/proxy-dbus.c @@ -73,6 +73,20 @@ px_proxy_factory_new (void) "org.libproxy.proxy", self->cancellable, /* GCancellable */ &error); + + if (!self->proxy) { + g_clear_error (&error); + + self->proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + NULL, /* GDBusInterfaceInfo */ + "org.libproxy.proxy", + "/org/libproxy/proxy", + "org.libproxy.proxy", + self->cancellable, /* GCancellable */ + &error); + } + if (!self->proxy) g_warning ("Could not create libproxy dbus proxy: %s", error->message); diff --git a/src/tools/proxy.c b/src/tools/proxy.c index 2d46578..2561265 100644 --- a/src/tools/proxy.c +++ b/src/tools/proxy.c @@ -54,7 +54,7 @@ print_proxies (char **proxies) return; } - for (j = 0; proxies[j] ; j++) + for (j = 0; proxies[j]; j++) printf ("%s%s", proxies[j], proxies[j + 1] ? " " : "\n"); } @@ -74,7 +74,7 @@ main (int argc, } /* User entered some arguments on startup. skip interactive */ if (argc > 1) { - for (i = 1; i < argc ; i++) { + for (i = 1; i < argc; i++) { /* * Get an array of proxies to use. These should be used * in the order returned. Only move on to the next proxy @@ -88,7 +88,7 @@ main (int argc, /* Interactive mode */ else { /* For each URL we read on STDIN, get the proxies to use */ - for (url[0] = '\0' ; fgets (url, 102400, stdin) != NULL ; ) { + for (url[0] = '\0'; fgets (url, 102400, stdin) != NULL;) { if (url[strlen (url) - 1] == '\n') url[strlen (url) - 1] = '\0'; /* |