logind: introduce an explicit session class for cronjobs and similar

cronjobs are neither interactive user session, nor lock screens, nor
login screens, hence they should get their own class.
This commit is contained in:
Lennart Poettering 2013-04-09 22:18:16 +02:00
parent 05d0c3e1fd
commit e2acb67baa
4 changed files with 46 additions and 21 deletions

View 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;

View 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);

View File

@ -37,6 +37,15 @@ typedef enum SessionState {
_SESSION_STATE_INVALID = -1
} SessionState;
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,
@ -45,14 +54,6 @@ typedef enum SessionType {
_SESSION_TYPE_INVALID = -1
} SessionType;
typedef enum SessionClass {
SESSION_USER,
SESSION_GREETER,
SESSION_LOCK_SCREEN,
_SESSION_CLASS_MAX,
_SESSION_CLASS_INVALID = -1
} SessionClass;
typedef enum KillWho {
KILL_LEADER,
KILL_ALL,

View 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") &&