Skip to content

Commit

Permalink
Allow CK support to be disabled at runtime for systemd
Browse files Browse the repository at this point in the history
Gentoo linux users may wish to run dual systems, where they may
boot systemd (needing no CK) or another init/rc system (needing CK)
at will.  In such cases, slim needs to have consolekit support
enabled at compile time but disabled at runtime from within the
systemd unit.  This commit adds such behaviour.

https://bugs.gentoo.org/show_bug.cgi?id=481016
  • Loading branch information
axs-gentoo committed Sep 18, 2015
1 parent 383c891 commit 5e1bf86
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 24 deletions.
65 changes: 42 additions & 23 deletions app.cpp
Expand Up @@ -135,13 +135,16 @@ App::App(int argc, char** argv)
ServerPID(-1), testing(false),
serverStarted(false), mcookie(string(App::mcookiesize, 'a')),
daemonmode(false), force_nodaemon(false),
#ifdef USE_CONSOLEKIT
consolekit_support_enabled = true;
#endif
firstlogin(true), Dpy(NULL)
{
int tmp;

// Parse command line
// Note: we force a option for nodaemon switch to handle "-nodaemon"
while((tmp = getopt(argc, argv, "vhp:n:d?")) != EOF) {
while((tmp = getopt(argc, argv, "vhsp:n:d?")) != EOF) {
switch (tmp) {
case 'p': // Test theme
testtheme = optarg;
Expand All @@ -162,6 +165,11 @@ App::App(int argc, char** argv)
std::cout << APPNAME << " version " << VERSION << endl;
exit(OK_EXIT);
break;
#ifdef USE_CONSOLEKIT
case 's': // Disable consolekit support
consolekit_support_enabled = false;
break;
#endif
case '?': // Illegal
logStream << endl;
case 'h': // Help
Expand All @@ -170,6 +178,9 @@ App::App(int argc, char** argv)
<< " -d: daemon mode" << endl
<< " -nodaemon: no-daemon mode" << endl
<< " -v: show version" << endl
#ifdef USE_CONSOLEKIT
<< " -s: start for systemd, disable consolekit support" << endl
#endif
<< " -p /path/to/theme/dir: preview theme" << endl;
exit(OK_EXIT);
break;
Expand Down Expand Up @@ -565,13 +576,15 @@ void App::Login() {
#endif

#ifdef USE_CONSOLEKIT
// Setup the ConsoleKit session
try {
ck.open_session(DisplayName, pw->pw_uid);
}
catch(Ck::Exception &e) {
logStream << APPNAME << ": " << e << endl;
exit(ERR_EXIT);
if (consolekit_support_enabled) {
// Setup the ConsoleKit session
try {
ck.open_session(DisplayName, pw->pw_uid);
}
catch(Ck::Exception &e) {
logStream << APPNAME << ": " << e << endl;
exit(ERR_EXIT);
}
}
#endif

Expand All @@ -584,18 +597,20 @@ void App::Login() {
char** child_env = pam.getenvlist();

# ifdef USE_CONSOLEKIT
char** old_env = child_env;
if (consolekit_support_enabled) {
char** old_env = child_env;

// Grow the copy of the environment for the session cookie
int n;
for(n = 0; child_env[n] != NULL ; n++);
// Grow the copy of the environment for the session cookie
int n;
for(n = 0; child_env[n] != NULL ; n++);

n++;
n++;

child_env = static_cast<char**>(malloc(sizeof(char*)*(n+1)));
memcpy(child_env, old_env, sizeof(char*)*n);
child_env[n - 1] = StrConcat("XDG_SESSION_COOKIE=", ck.get_xdg_session_cookie());
child_env[n] = NULL;
child_env = static_cast<char**>(malloc(sizeof(char*)*(n+1)));
memcpy(child_env, old_env, sizeof(char*)*n);
child_env[n - 1] = StrConcat("XDG_SESSION_COOKIE=", ck.get_xdg_session_cookie());
child_env[n] = NULL;
}
# endif /* USE_CONSOLEKIT */
#else

Expand All @@ -617,7 +632,9 @@ void App::Login() {
child_env[n++]=StrConcat("MAIL=", maildir.c_str());
child_env[n++]=StrConcat("XAUTHORITY=", xauthority.c_str());
# ifdef USE_CONSOLEKIT
child_env[n++]=StrConcat("XDG_SESSION_COOKIE=", ck.get_xdg_session_cookie());
if (consolekit_support_enabled) {
child_env[n++]=StrConcat("XDG_SESSION_COOKIE=", ck.get_xdg_session_cookie());
}
# endif /* USE_CONSOLEKIT */
child_env[n++]=0;

Expand Down Expand Up @@ -662,12 +679,14 @@ void App::Login() {
}

#ifdef USE_CONSOLEKIT
try {
ck.close_session();
if (consolekit_support_enabled) {
try {
ck.close_session();
}
catch(Ck::Exception &e) {
logStream << APPNAME << ": " << e << endl;
};
}
catch(Ck::Exception &e) {
logStream << APPNAME << ": " << e << endl;
};
#endif

#ifdef USE_PAM
Expand Down
1 change: 1 addition & 0 deletions app.h
Expand Up @@ -89,6 +89,7 @@ class App {
#endif
#ifdef USE_CONSOLEKIT
Ck::Session ck;
bool consolekit_support_enabled;
#endif

// Options
Expand Down
2 changes: 1 addition & 1 deletion build_files/slim.service
Expand Up @@ -3,7 +3,7 @@ Description=SLiM Simple Login Manager
After=systemd-user-sessions.service

[Service]
ExecStart=/usr/bin/slim -nodaemon
ExecStart=/usr/bin/slim -nodaemon -s
Restart=on-failure

[Install]
Expand Down

0 comments on commit 5e1bf86

Please sign in to comment.