Skip to content

Commit

Permalink
Add initial systemd support
Browse files Browse the repository at this point in the history
  • Loading branch information
stefano-k committed Mar 5, 2013
1 parent 29e5cd2 commit 31fdf9e
Show file tree
Hide file tree
Showing 7 changed files with 1,238 additions and 39 deletions.
26 changes: 25 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,29 @@ dnl GSettings
dnl ====================================================================
GLIB_GSETTINGS


dnl ====================================================================
dnl Systemd
dnl ====================================================================

AC_ARG_WITH(systemd,
AS_HELP_STRING([--with-systemd],
[Add systemd support]),,
with_systemd=auto)

use_systemd=no
if test "x$with_systemd" != "xno" ; then
PKG_CHECK_MODULES(SYSTEMD, libsystemd-login libsystemd-daemon, use_systemd=yes, use_systemd=no)

if test "x$use_systemd" = "xyes"; then
AC_DEFINE(HAVE_SYSTEMD, 1, [systemd support])
AC_SUBST(SYSTEMD_CFLAGS)
AC_SUBST(SYSTEMD_LIBS)
fi
fi
AM_CONDITIONAL(HAVE_SYSTEMD, test "x$use_systemd" = "xyes")
AC_SUBST(HAVE_SYSTEMD)

dnl ====================================================================
dnl X development libraries check
dnl ====================================================================
Expand Down Expand Up @@ -137,7 +160,7 @@ fi

AC_CHECK_LIB(Xau, XauFileName, [X_LIBS="$X_LIBS -lXau"],
[AC_MSG_ERROR([
*** Can't find the Xauth library. It is needed to compile mate-session.])],
*** Cant find the Xauth library. It is needed to compile mate-session.])],
$X_LIBS)

AC_SUBST(X_LIBS)
Expand Down Expand Up @@ -361,6 +384,7 @@ echo "

GTK+ version: ${with_gtk}
Default WM: ${with_default_wm}
Systemd support: ${use_systemd}
IPv6 support: ${have_full_ipv6}
Backtrace support: ${have_backtrace}
XRender support: ${have_xrender}
Expand Down
6 changes: 5 additions & 1 deletion mate-session/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ noinst_PROGRAMS = \
test-inhibit

AM_CPPFLAGS = \
$(MATE_SESSION_CFLAGS) \
$(MATE_SESSION_CFLAGS) \
$(SYSTEMD_CFLAGS) \
$(DISABLE_DEPRECATED_CFLAGS)

AM_CFLAGS = $(WARN_CFLAGS)
Expand All @@ -25,6 +26,8 @@ mate_session_SOURCES = \
gsm-marshal.c \
gsm-consolekit.c \
gsm-consolekit.h \
gsm-systemd.c \
gsm-systemd.h \
gsm-logout-dialog.h \
gsm-logout-dialog.c \
gsm-inhibit-dialog.h \
Expand Down Expand Up @@ -72,6 +75,7 @@ mate_session_LDADD = \
$(XTEST_LIBS) \
$(XEXT_LIBS) \
$(MATE_SESSION_LIBS) \
$(SYSTEMD_LIBS) \
$(EXECINFO_LIBS)

libgsmutil_la_SOURCES = \
Expand Down
60 changes: 54 additions & 6 deletions mate-session/gsm-logout-dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
#include <upower.h>

#include "gsm-logout-dialog.h"
#ifdef HAVE_SYSTEMD
#include "gsm-systemd.h"
#include <systemd/sd-daemon.h>
#endif
#include "gsm-consolekit.h"
#include "mdm.h"

Expand All @@ -51,6 +55,9 @@ struct _GsmLogoutDialogPrivate
GsmDialogLogoutType type;

UpClient *up_client;
#ifdef HAVE_SYSTEMD
GsmSystemd *systemd;
#endif
GsmConsolekit *consolekit;

int timeout;
Expand Down Expand Up @@ -144,6 +151,11 @@ gsm_logout_dialog_init (GsmLogoutDialog *logout_dialog)

logout_dialog->priv->up_client = up_client_new ();

#ifdef HAVE_SYSTEMD
if (sd_booted() > 0)
logout_dialog->priv->systemd = gsm_get_systemd ();
else
#endif
logout_dialog->priv->consolekit = gsm_get_consolekit ();

g_signal_connect (logout_dialog,
Expand Down Expand Up @@ -171,6 +183,13 @@ gsm_logout_dialog_destroy (GsmLogoutDialog *logout_dialog,
logout_dialog->priv->up_client = NULL;
}

#ifdef HAVE_SYSTEMD
if (logout_dialog->priv->systemd) {
g_object_unref (logout_dialog->priv->systemd);
logout_dialog->priv->systemd = NULL;
}
#endif

if (logout_dialog->priv->consolekit) {
g_object_unref (logout_dialog->priv->consolekit);
logout_dialog->priv->consolekit = NULL;
Expand All @@ -196,6 +215,11 @@ gsm_logout_supports_switch_user (GsmLogoutDialog *logout_dialog)
{
gboolean ret;

#ifdef HAVE_SYSTEMD
if (sd_booted () > 0)
ret = gsm_systemd_can_switch_user (logout_dialog->priv->systemd);
else
#endif
ret = gsm_consolekit_can_switch_user (logout_dialog->priv->consolekit);

return ret;
Expand All @@ -206,6 +230,11 @@ gsm_logout_supports_reboot (GsmLogoutDialog *logout_dialog)
{
gboolean ret;

#ifdef HAVE_SYSTEMD
if (sd_booted () > 0)
ret = gsm_systemd_can_restart (logout_dialog->priv->systemd);
else
#endif
ret = gsm_consolekit_can_restart (logout_dialog->priv->consolekit);
if (!ret) {
ret = mdm_supports_logout_action (MDM_LOGOUT_ACTION_REBOOT);
Expand All @@ -219,6 +248,11 @@ gsm_logout_supports_shutdown (GsmLogoutDialog *logout_dialog)
{
gboolean ret;

#ifdef HAVE_SYSTEMD
if (sd_booted () > 0)
ret = gsm_systemd_can_stop (logout_dialog->priv->systemd);
else
#endif
ret = gsm_consolekit_can_stop (logout_dialog->priv->consolekit);

if (!ret) {
Expand All @@ -242,6 +276,7 @@ gsm_logout_dialog_timeout (gpointer data)
char *secondary_text;
int seconds_to_show;
static char *session_type = NULL;
static gboolean is_not_login;

logout_dialog = (GsmLogoutDialog *) data;

Expand Down Expand Up @@ -283,14 +318,27 @@ gsm_logout_dialog_timeout (gpointer data)
}

if (session_type == NULL) {
GsmConsolekit *consolekit;

#ifdef HAVE_SYSTEMD
if (sd_booted () > 0) {
GsmSystemd *systemd;
systemd = gsm_get_systemd ();
session_type = gsm_systemd_get_current_session_type (systemd);
g_object_unref (systemd);
is_not_login = (g_strcmp0 (session_type, GSM_SYSTEMD_SESSION_TYPE_LOGIN_WINDOW) != 0);
}
else {
#endif
GsmConsolekit *consolekit;
consolekit = gsm_get_consolekit ();
session_type = gsm_consolekit_get_current_session_type (consolekit);
g_object_unref (consolekit);
is_not_login = (g_strcmp0 (session_type, GSM_CONSOLEKIT_SESSION_TYPE_LOGIN_WINDOW) != 0);
#ifdef HAVE_SYSTEMD
}
#endif
}

if (g_strcmp0 (session_type, GSM_CONSOLEKIT_SESSION_TYPE_LOGIN_WINDOW) != 0) {
if (is_not_login) {
char *name, *tmp;

name = g_locale_to_utf8 (g_get_real_name (), -1, NULL, NULL, NULL);
Expand All @@ -308,9 +356,9 @@ gsm_logout_dialog_timeout (gpointer data)
g_free (tmp);

g_free (name);
} else {
secondary_text = g_strdup (seconds_warning);
}
} else {
secondary_text = g_strdup (seconds_warning);
}

gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (logout_dialog),
secondary_text,
Expand Down
Loading

0 comments on commit 31fdf9e

Please sign in to comment.