summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans de Goede <hdegoede@redhat.com>2012-03-19 15:03:33 +0100
committerHans de Goede <hdegoede@redhat.com>2012-03-20 16:45:06 +0100
commit93003ec27d98cb47b8ea0435179a66c14ff610ce (patch)
tree6fdf14193dad5e391ed16719c6f6366f699d0f04
parent3f82bced6c22b9bb04a04a83e952af0bfdcdaeba (diff)
vdagentd: Add support for libsystemd-login
This allows us to get session information on new systemd enabled distros, which no longer come with consolekit. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
-rw-r--r--Makefile.am7
-rw-r--r--configure.ac67
-rw-r--r--src/session-info.h2
-rw-r--r--src/systemd-login.c104
4 files changed, 168 insertions, 12 deletions
diff --git a/Makefile.am b/Makefile.am
index c6aa647..e75d694 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -7,8 +7,8 @@ src_spice_vdagent_CFLAGS = $(X_CFLAGS) $(SPICE_CFLAGS)
src_spice_vdagent_LDADD = $(X_LIBS) $(SPICE_LIBS)
src_spice_vdagent_SOURCES = src/vdagent.c src/vdagent-x11.c src/udscs.c
-src_spice_vdagentd_CFLAGS = $(DBUS_CFLAGS) $(PCIACCESS_CFLAGS) $(SPICE_CFLAGS)
-src_spice_vdagentd_LDADD = $(DBUS_LIBS) $(PCIACCESS_LIBS) $(SPICE_LIBS)
+src_spice_vdagentd_CFLAGS = $(DBUS_CFLAGS) $(LIBSYSTEMD_LOGIN_CFLAGS) $(PCIACCESS_CFLAGS) $(SPICE_CFLAGS)
+src_spice_vdagentd_LDADD = $(DBUS_LIBS) $(LIBSYSTEMD_LOGIN_LIBS) $(PCIACCESS_LIBS) $(SPICE_LIBS)
src_spice_vdagentd_SOURCES = src/vdagentd.c \
src/vdagentd-uinput.c \
src/vdagentd-xorg-conf.c \
@@ -17,6 +17,9 @@ src_spice_vdagentd_SOURCES = src/vdagentd.c \
if HAVE_CONSOLE_KIT
src_spice_vdagentd_SOURCES += src/console-kit.c
endif
+if HAVE_LIBSYSTEMD_LOGIN
+src_spice_vdagentd_SOURCES += src/systemd-login.c
+endif
noinst_HEADERS = src/session-info.h \
src/vdagentd-proto-strings.h \
diff --git a/configure.ac b/configure.ac
index 0ac9505..a753b5d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,5 +1,5 @@
AC_PREREQ(2.59)
-AC_INIT([spice-vdagent], [0.8.2])
+AC_INIT([spice-vdagent], [0.10.0])
AC_CONFIG_SRCDIR([configure.ac])
AM_CONFIG_HEADER([src/config.h])
@@ -14,10 +14,14 @@ AC_PROG_INSTALL
AC_PROG_LN_S
AC_DEFINE(_GNU_SOURCE, [1], [Enable GNU extensions])
-AC_ARG_ENABLE([console-kit],
- [AS_HELP_STRING([--enable-console-kit], [Enable ConsoleKit use (default: yes)])],
- [enable_console_kit="$enableval"],
- [enable_console_kit="yes"])
+AC_ARG_WITH([session-info],
+ [AS_HELP_STRING([--with-session-info=@<:@auto/console-kit/systemd/none@:>@],
+ [Session-info source to use @<:@default=auto@:>@])],
+ [case "$with_session_info" in
+ auto|console-kit|systemd|none) ;;
+ *) AC_MSG_ERROR([invalid session-info type specified]) ;;
+ esac],
+ [with_session_info="auto"])
AC_ARG_ENABLE([pciaccess],
[AS_HELP_STRING([--enable-pciaccess], [Enable libpciaccess use for auto generation of Xinerama xorg.conf (default: yes)])],
@@ -33,11 +37,39 @@ PKG_PROG_PKG_CONFIG
PKG_CHECK_MODULES(X, [xfixes xrandr xinerama x11])
PKG_CHECK_MODULES(SPICE, [spice-protocol >= 0.8.0])
-if test x"$enable_console_kit" = "xyes" ; then
- PKG_CHECK_MODULES(DBUS, [dbus-1])
- AC_DEFINE([HAVE_CONSOLE_KIT], [1], [If defined, vdagentd will be compiled with ConsoleKit support] )
+if test "$with_session_info" = "auto" || test "$with_session_info" = "systemd"; then
+ PKG_CHECK_MODULES([LIBSYSTEMD_LOGIN],
+ [libsystemd-login >= 42],
+ [have_libsystemd_login="yes"],
+ [have_libsystemd_login="no"])
+ if test x"$have_libsystemd_login" = "xno" && test "$with_session_info" = "systemd"; then
+ AC_MSG_ERROR([libsystemd-login support explicitly requested, but some required packages are not available])
+ fi
+ if test x"$have_libsystemd_login" = "xyes"; then
+ AC_DEFINE(HAVE_LIBSYSTEMD_LOGIN, [1], [If defined, vdagentd will be compiled with libsystemd-login support])
+ with_session_info="systemd"
+ fi
+else
+ have_libsystemd_login="no"
fi
-AM_CONDITIONAL(HAVE_CONSOLE_KIT, test x"$enable_console_kit" = "xyes")
+AM_CONDITIONAL(HAVE_LIBSYSTEMD_LOGIN, test x"$have_libsystemd_login" = "xyes")
+
+if test "$with_session_info" = "auto" || test "$with_session_info" = "console-kit"; then
+ PKG_CHECK_MODULES([DBUS],
+ [dbus-1],
+ [have_console_kit="yes"],
+ [have_console_kit="no"])
+ if test x"$have_console_kit" = "xno" && test "$with_session_info" = "console-kit"; then
+ AC_MSG_ERROR([console-kit support explicitly requested, but some required packages are not available])
+ fi
+ if test x"$have_console_kit" = "xyes"; then
+ AC_DEFINE([HAVE_CONSOLE_KIT], [1], [If defined, vdagentd will be compiled with ConsoleKit support])
+ with_session_info="console-kit"
+ fi
+else
+ have_console_kit="no"
+fi
+AM_CONDITIONAL(HAVE_CONSOLE_KIT, test x"$have_console_kit" = "xyes")
if test x"$enable_pciaccess" = "xyes" ; then
PKG_CHECK_MODULES(PCIACCESS, [pciaccess >= 0.10])
@@ -53,3 +85,20 @@ AC_CONFIG_FILES([
Makefile
])
AC_OUTPUT
+
+dnl ==========================================================================
+AC_MSG_NOTICE([
+
+ spice-vdagent $VERSION
+ ====================
+
+ prefix: ${prefix}
+ c compiler: ${CC}
+
+ session-info: ${with_session_info}
+ pciaccess: ${enable_pciaccess}
+ static uinput: ${enable_static_uinput}
+
+ Now type 'make' to build $PACKAGE
+
+])
diff --git a/src/session-info.h b/src/session-info.h
index fb3de07..054aa6c 100644
--- a/src/session-info.h
+++ b/src/session-info.h
@@ -25,7 +25,7 @@
#include <stdio.h>
#include <stdint.h>
-#if defined HAVE_CONSOLE_KIT
+#if defined HAVE_CONSOLE_KIT || defined HAVE_LIBSYSTEMD_LOGIN
#define HAVE_SESSION_INFO
#endif
diff --git a/src/systemd-login.c b/src/systemd-login.c
new file mode 100644
index 0000000..277cb03
--- /dev/null
+++ b/src/systemd-login.c
@@ -0,0 +1,104 @@
+/* systemd-login.c vdagentd libsystemd-login integration code
+
+ Copyright 2012 Red Hat, Inc.
+
+ Red Hat Authors:
+ Hans de Goede <hdegoede@redhat.com>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "session-info.h"
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <systemd/sd-login.h>
+
+struct session_info {
+ FILE *logfile;
+ int verbose;
+ sd_login_monitor *mon;
+ char *session;
+};
+
+struct session_info *session_info_create(FILE *logfile, int verbose)
+{
+ struct session_info *si;
+ int r;
+
+ si = calloc(1, sizeof(*si));
+ if (!si)
+ return NULL;
+
+ si->logfile = logfile;
+ si->verbose = verbose;
+
+ r = sd_login_monitor_new("session", &si->mon);
+ if (r < 0) {
+ fprintf(logfile, "Error creating login monitor: %s\n", strerror(-r));
+ free(si);
+ return NULL;
+ }
+
+ return si;
+}
+
+void session_info_destroy(struct session_info *si)
+{
+ sd_login_monitor_unref(si->mon);
+ free(si->session);
+ free(si);
+}
+
+int session_info_get_fd(struct session_info *si)
+{
+ return sd_login_monitor_get_fd(si->mon);
+}
+
+const char *session_info_get_active_session(struct session_info *si)
+{
+ int r;
+ char *old_session = si->session;
+
+ si->session = NULL;
+ r = sd_seat_get_active("seat0", &si->session, NULL);
+ /* ENOENT happens when a seat is switching from one session to another */
+ if (r < 0 && r != ENOENT)
+ fprintf(si->logfile, "Error getting active session: %s\n",
+ strerror(-r));
+
+ if (si->verbose && si->session &&
+ (!old_session || strcmp(old_session, si->session)))
+ fprintf(si->logfile, "Active session: %s\n", si->session);
+
+ sd_login_monitor_flush(si->mon);
+ free(old_session);
+
+ return si->session;
+}
+
+char *session_info_session_for_pid(struct session_info *si, uint32_t pid)
+{
+ int r;
+ char *session = NULL;
+
+ r = sd_pid_get_session(pid, &session);
+ if (r < 0)
+ fprintf(si->logfile, "Error getting session for pid %u: %s\n",
+ pid, strerror(-r));
+ else if (si->verbose)
+ fprintf(si->logfile, "Session for pid %u: %s\n", pid, session);
+
+ return session;
+}