diff options
author | Alexander Larsson <alexl@redhat.com> | 2015-07-09 18:16:44 +0200 |
---|---|---|
committer | Alexander Larsson <alexl@redhat.com> | 2015-07-10 12:15:45 +0200 |
commit | 302f88e69da195ee44d5809a7355320f0072b47e (patch) | |
tree | 30c666f3ec5e1738e3f30fa34d75622b5a8207a8 /session-helper | |
parent | ef223b6a46b2426e0cafa4f58e6346f63856e873 (diff) | |
download | xdg-app-302f88e69da195ee44d5809a7355320f0072b47e.tar.gz |
Restructure directories and build
This moves a all source code into separate subdirs per binary. The
helper and the generic stuff goes into lib/ which is then used by all
the others. For now this is a completely internal library, but at
some point we will probably clean it up and expose some subset.
Also, we move the dbus proxy to libexecdir.
Diffstat (limited to 'session-helper')
-rw-r--r-- | session-helper/Makefile.am.inc | 33 | ||||
-rw-r--r-- | session-helper/xdg-app-session-helper.c | 166 | ||||
-rw-r--r-- | session-helper/xdg-app-session.service.in | 3 | ||||
-rw-r--r-- | session-helper/xdg-app.gresource.xml | 6 |
4 files changed, 208 insertions, 0 deletions
diff --git a/session-helper/Makefile.am.inc b/session-helper/Makefile.am.inc new file mode 100644 index 0000000..e6b438b --- /dev/null +++ b/session-helper/Makefile.am.inc @@ -0,0 +1,33 @@ +resource_files = $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) --generate-dependencies $(srcdir)/session-helper/xdg-app.gresource.xml) + +libexec_PROGRAMS += \ + xdg-app-session-helper \ + $(NULL) + +session-helper/xdg-app-resources.h: session-helper/xdg-app.gresource.xml + $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) $< \ + --target=$@ --sourcedir=$(srcdir) --c-name _gtk --generate-header + +session-helper/xdg-app-resources.c: session-helper/xdg-app.gresource.xml $(resource_files) + $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) $< \ + --target=$@ --sourcedir=$(srcdir) --c-name _gtk --generate-source + +# D-BUS service file +%.service: %.service.in config.log + $(AM_V_GEN) $(SED) -e "s|\@libexecdir\@|$(libexecdir)|" $< > $@ + +servicedir = $(DBUS_SERVICE_DIR) +service_in_files = session-helper/xdg-app-session.service.in +service_DATA = session-helper/xdg-app-session.service +DISTCLEANFILES += $(service_DATA) + +EXTRA_DIST += session-helper/xdg-app.gresource.xml $(service_in_files) + +xdg_app_session_helper_SOURCES = \ + session-helper/xdg-app-session-helper.c \ + session-helper/xdg-app-resources.h \ + session-helper/xdg-app-resources.c \ + $(NULL) + +xdg_app_session_helper_LDADD = $(BASE_LIBS) libxdgapp.la +xdg_app_session_helper_CFLAGS = $(BASE_CFLAGS) diff --git a/session-helper/xdg-app-session-helper.c b/session-helper/xdg-app-session-helper.c new file mode 100644 index 0000000..1fd6653 --- /dev/null +++ b/session-helper/xdg-app-session-helper.c @@ -0,0 +1,166 @@ +/* + * Copyright © 2014 Red Hat, Inc + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + * + * Authors: + * Alexander Larsson <alexl@redhat.com> + */ + +#include "config.h" + +#include <locale.h> +#include <stdlib.h> +#include <string.h> +#include <gio/gio.h> +#include "xdg-app-dbus.h" + +static GDBusNodeInfo *introspection_data = NULL; +static char *monitor_dir; + +static gboolean +handle_request_monitor (XdgAppSessionHelper *object, + GDBusMethodInvocation *invocation, + gpointer user_data) +{ + xdg_app_session_helper_complete_request_monitor (object, invocation, + monitor_dir); + + return TRUE; +} + +static void +on_bus_acquired (GDBusConnection *connection, + const gchar *name, + gpointer user_data) +{ + XdgAppSessionHelper *helper; + GError *error = NULL; + + helper = xdg_app_session_helper_skeleton_new (); + + g_signal_connect (helper, "handle-request-monitor", G_CALLBACK (handle_request_monitor), NULL); + + if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (helper), + connection, + "/org/freedesktop/XdgApp/SessionHelper", + &error)) + { + g_warning ("error: %s\n", error->message); + g_error_free (error); + } +} + +static void +on_name_acquired (GDBusConnection *connection, + const gchar *name, + gpointer user_data) +{ +} + +static void +on_name_lost (GDBusConnection *connection, + const gchar *name, + gpointer user_data) +{ + exit (1); +} + +static void +copy_file (const char *source, + const char *target_dir) +{ + char *basename = g_path_get_basename (source); + char *dest = g_build_filename (target_dir, basename, NULL); + gchar *contents = NULL; + gsize len; + + if (g_file_get_contents (source, &contents, &len, NULL)) + g_file_set_contents (dest, contents, len, NULL); + + g_free (basename); + g_free (dest); + g_free (contents); +} + +static void +file_changed (GFileMonitor *monitor, + GFile *file, + GFile *other_file, + GFileMonitorEvent event_type, + char *source) +{ + if (event_type == G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT || + event_type == G_FILE_MONITOR_EVENT_CREATED) + copy_file (source, monitor_dir); +} + +static void +setup_file_monitor (const char *source) +{ + GFile *s = g_file_new_for_path (source); + GFileMonitor *monitor; + + copy_file (source, monitor_dir); + + monitor = g_file_monitor_file (s, G_FILE_MONITOR_NONE, NULL, NULL); + if (monitor) + g_signal_connect (monitor, "changed", G_CALLBACK (file_changed), (char *)source); +} + +int +main (int argc, + char **argv) +{ + guint owner_id; + GMainLoop *loop; + GBytes *introspection_bytes; + + setlocale (LC_ALL, ""); + + g_set_prgname (argv[0]); + + monitor_dir = g_build_filename (g_get_user_runtime_dir (), "xdg-app-monitor", NULL); + if (g_mkdir_with_parents (monitor_dir, 0755) != 0) + { + g_print ("Can't create %s\n", monitor_dir); + exit (1); + } + + setup_file_monitor ("/etc/resolv.conf"); + setup_file_monitor ("/etc/localtime"); + + introspection_bytes = g_resources_lookup_data ("/org/freedesktop/XdgApp/xdg-app-dbus-interfaces.xml", 0, NULL); + g_assert (introspection_bytes != NULL); + + introspection_data = g_dbus_node_info_new_for_xml (g_bytes_get_data (introspection_bytes, NULL), NULL); + + owner_id = g_bus_own_name (G_BUS_TYPE_SESSION, + "org.freedesktop.XdgApp.SessionHelper", + G_BUS_NAME_OWNER_FLAGS_NONE, + on_bus_acquired, + on_name_acquired, + on_name_lost, + NULL, + NULL); + + loop = g_main_loop_new (NULL, FALSE); + g_main_loop_run (loop); + + g_bus_unown_name (owner_id); + + g_dbus_node_info_unref (introspection_data); + + return 0; +} diff --git a/session-helper/xdg-app-session.service.in b/session-helper/xdg-app-session.service.in new file mode 100644 index 0000000..a8e7099 --- /dev/null +++ b/session-helper/xdg-app-session.service.in @@ -0,0 +1,3 @@ +[D-BUS Service] +Name=org.freedesktop.XdgApp.SessionHelper +Exec=@libexecdir@/xdg-app-session-helper diff --git a/session-helper/xdg-app.gresource.xml b/session-helper/xdg-app.gresource.xml new file mode 100644 index 0000000..c3d3e49 --- /dev/null +++ b/session-helper/xdg-app.gresource.xml @@ -0,0 +1,6 @@ +<?xml version='1.0' encoding='UTF-8'?> +<gresources> + <gresource prefix='/org/freedesktop/XdgApp'> + <file alias="xdg-app-dbus-interfaces.xml">data/xdg-app-dbus-interfaces.xml</file> + </gresource> +</gresources> |