chiark / gitweb /
logind: introduce an explicit session class for cronjobs and similar
authorLennart Poettering <lennart@poettering.net>
Tue, 9 Apr 2013 20:18:16 +0000 (22:18 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 9 Apr 2013 20:18:16 +0000 (22:18 +0200)
cronjobs are neither interactive user session, nor lock screens, nor
login screens, hence they should get their own class.

src/login/logind-dbus.c
src/login/logind-session.c
src/login/logind-session.h
src/login/pam-module.c

index aa212d1fedfb4591ad96530cbf9f4ca2ccc4dd55..230dd2b4b5e9ac2f329a0de281cb30f1d439a214 100644 (file)
@@ -353,21 +353,28 @@ static int bus_manager_create_session(Manager *m, DBusMessage *message, DBusMess
                 return -EINVAL;
 
         dbus_message_iter_get_basic(&iter, &type);
-        t = session_type_from_string(type);
+        if (isempty(type))
+                t = _SESSION_TYPE_INVALID;
+        else {
+                t = session_type_from_string(type);
+                if (t < 0)
+                        return -EINVAL;
+        }
 
-        if (t < 0 ||
-            !dbus_message_iter_next(&iter) ||
+        if (!dbus_message_iter_next(&iter) ||
             dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
                 return -EINVAL;
 
         dbus_message_iter_get_basic(&iter, &class);
         if (isempty(class))
-                c = SESSION_USER;
-        else
+                c = _SESSION_CLASS_INVALID;
+        else {
                 c = session_class_from_string(class);
+                if (c < 0)
+                        return -EINVAL;
+        }
 
-        if (c < 0 ||
-            !dbus_message_iter_next(&iter) ||
+        if (!dbus_message_iter_next(&iter) ||
             dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
                 return -EINVAL;
 
@@ -441,6 +448,22 @@ static int bus_manager_create_session(Manager *m, DBusMessage *message, DBusMess
             dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_BOOLEAN)
                 return -EINVAL;
 
+        if (t == _SESSION_TYPE_INVALID) {
+                if (!isempty(display))
+                        t = SESSION_X11;
+                else if (!isempty(tty))
+                        t = SESSION_TTY;
+                else
+                        t = SESSION_UNSPECIFIED;
+        }
+
+        if (c == _SESSION_CLASS_INVALID) {
+                if (!isempty(display) || !isempty(tty))
+                        c = SESSION_USER;
+                else
+                        c = SESSION_BACKGROUND;
+        }
+
         dbus_message_iter_get_basic(&iter, &remote);
 
         if (!dbus_message_iter_next(&iter) ||
@@ -993,7 +1016,6 @@ static int have_multiple_sessions(
          * count, and non-login sessions do not count either. */
         HASHMAP_FOREACH(session, m->sessions, i)
                 if (session->class == SESSION_USER &&
-                    (session->type == SESSION_TTY || session->type == SESSION_X11) &&
                     session->user->uid != uid)
                         return true;
 
index 97c24d094b66ef2ee97b5c9861c38c2a14848564..508336d4d3b6fbc756917f8f804a0965f2e187a8 100644 (file)
@@ -1056,7 +1056,8 @@ DEFINE_STRING_TABLE_LOOKUP(session_type, SessionType);
 static const char* const session_class_table[_SESSION_CLASS_MAX] = {
         [SESSION_USER] = "user",
         [SESSION_GREETER] = "greeter",
-        [SESSION_LOCK_SCREEN] = "lock-screen"
+        [SESSION_LOCK_SCREEN] = "lock-screen",
+        [SESSION_BACKGROUND] = "background"
 };
 
 DEFINE_STRING_TABLE_LOOKUP(session_class, SessionClass);
index 7598afa61880437880ef02a6dbcb6e3a60f70e1d..c8dd181e7ba0ed9eda5cd22f3acf054e2a072846 100644 (file)
@@ -37,22 +37,23 @@ typedef enum SessionState {
         _SESSION_STATE_INVALID = -1
 } SessionState;
 
-typedef enum SessionType {
-        SESSION_UNSPECIFIED,
-        SESSION_TTY,
-        SESSION_X11,
-        _SESSION_TYPE_MAX,
-        _SESSION_TYPE_INVALID = -1
-} SessionType;
-
 typedef enum SessionClass {
         SESSION_USER,
         SESSION_GREETER,
         SESSION_LOCK_SCREEN,
+        SESSION_BACKGROUND,
         _SESSION_CLASS_MAX,
         _SESSION_CLASS_INVALID = -1
 } SessionClass;
 
+typedef enum SessionType {
+        SESSION_UNSPECIFIED,
+        SESSION_TTY,
+        SESSION_X11,
+        _SESSION_TYPE_MAX,
+        _SESSION_TYPE_INVALID = -1
+} SessionType;
+
 typedef enum KillWho {
         KILL_LEADER,
         KILL_ALL,
index c8f4dae77e1c9f25b46e2d86ad70a373091653bd..609317e9dd8f705e51ca048d6964eac3b1316167 100644 (file)
@@ -440,9 +440,10 @@ _public_ PAM_EXTERN int pam_sm_open_session(
         seat = strempty(seat);
 
         if (strchr(tty, ':')) {
-                /* A tty with a colon is usually an X11 display, place
-                 * there to show up in utmp. We rearrange things and
-                 * don't pretend that an X display was a tty */
+                /* A tty with a colon is usually an X11 display,
+                 * placed there to show up in utmp. We rearrange
+                 * things and don't pretend that an X display was a
+                 * tty. */
 
                 if (isempty(display))
                         display = tty;
@@ -482,7 +483,7 @@ _public_ PAM_EXTERN int pam_sm_open_session(
         if (isempty(class))
                 class = class_pam;
         if (isempty(class))
-                class = "user";
+                class = streq(type, "unspecified") ? "background" : "user";
 
         remote = !isempty(remote_host) &&
                 !streq(remote_host, "localhost") &&