summaryrefslogtreecommitdiff
path: root/src/login/logind-dbus.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-03-22 12:38:01 +0100
committerSven Eden <yamakuzure@gmx.net>2018-08-24 16:47:08 +0200
commit58109c17667483583032bf1b8a3b6991976b68b7 (patch)
treea911548f3af56de9801135af925779bd85366ce2 /src/login/logind-dbus.c
parent19b0ce632da2520a9fc0bad5f9f2329096a6a8f8 (diff)
basic/mkdir: convert bool flag to enum
In preparation for subsequent changes...
Diffstat (limited to 'src/login/logind-dbus.c')
-rw-r--r--src/login/logind-dbus.c43
1 files changed, 27 insertions, 16 deletions
diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
index 00a6a1e7b..3da51259e 100644
--- a/src/login/logind-dbus.c
+++ b/src/login/logind-dbus.c
@@ -661,9 +661,10 @@ static int method_list_inhibitors(sd_bus_message *message, void *userdata, sd_bu
static int method_create_session(sd_bus_message *message, void *userdata, sd_bus_error *error) {
const char *service, *type, *class, *cseat, *tty, *display, *remote_user, *remote_host, *desktop;
- _cleanup_free_ char *unit = NULL, *id = NULL;
- Session *session = NULL;
uint32_t audit_id = 0;
+ _cleanup_free_ char *unit = NULL;
+ _cleanup_free_ char *id = NULL;
+ Session *session = NULL;
Manager *m = userdata;
User *user = NULL;
Seat *seat = NULL;
@@ -687,7 +688,7 @@ static int method_create_session(sd_bus_message *message, void *userdata, sd_bus
if (!uid_is_valid(uid))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid UID");
- if (leader < 0 || leader == 1 || leader == getpid_cached())
+ if (leader < 0 || leader == 1)
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid leader PID");
if (isempty(type))
@@ -733,7 +734,7 @@ static int method_create_session(sd_bus_message *message, void *userdata, sd_bus
if (v <= 0)
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Cannot determine VT number from virtual console TTY %s", tty);
- if (vtnr == 0)
+ if (!vtnr)
vtnr = (uint32_t) v;
else if (vtnr != (uint32_t) v)
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Specified TTY and VT number do not match");
@@ -751,7 +752,7 @@ static int method_create_session(sd_bus_message *message, void *userdata, sd_bus
if (seat) {
if (seat_has_vts(seat)) {
- if (vtnr <= 0 || vtnr > 63)
+ if (!vtnr || vtnr > 63)
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "VT number out of range");
} else {
if (vtnr != 0)
@@ -791,13 +792,16 @@ static int method_create_session(sd_bus_message *message, void *userdata, sd_bus
return r;
}
- /* Check if we are already in a logind session. Or if we are in user@.service which is a special PAM session
- * that avoids creating a logind session. */
- r = manager_get_user_by_pid(m, leader, NULL);
+ /*
+ * Check if we are already in a logind session. Or if we are in user@.service
+ * which is a special PAM session that avoids creating a logind session.
+ */
+ r = cg_pid_get_unit(leader, &unit);
if (r < 0)
return r;
- if (r > 0)
- return sd_bus_error_setf(error, BUS_ERROR_SESSION_BUSY, "Already running in a session or user slice");
+ if (hashmap_get(m->session_units, unit) ||
+ hashmap_get(m->user_units, unit))
+ return sd_bus_error_setf(error, BUS_ERROR_SESSION_BUSY, "Already running in a session");
/*
* Old gdm and lightdm start the user-session on the same VT as
@@ -831,8 +835,9 @@ static int method_create_session(sd_bus_message *message, void *userdata, sd_bus
* the audit data and let's better register a new
* ID */
if (hashmap_get(m->sessions, id)) {
- log_warning("Existing logind session ID %s used by new audit session, ignoring.", id);
+ log_warning("Existing logind session ID %s used by new audit session, ignoring", id);
audit_id = AUDIT_SESSION_INVALID;
+
id = mfree(id);
}
}
@@ -925,7 +930,8 @@ static int method_create_session(sd_bus_message *message, void *userdata, sd_bus
session->create_message = sd_bus_message_ref(message);
#if 0 /// UNNEEDED by elogind
- /* Now, let's wait until the slice unit and stuff got created. We send the reply back from
+ /* Now, let's wait until the slice unit and stuff got
+ * created. We send the reply back from
* session_send_create_reply(). */
#else
/* We reply directly. */
@@ -1233,7 +1239,7 @@ static int method_set_user_linger(sd_bus_message *message, void *userdata, sd_bu
mkdir_p_label("/var/lib/elogind", 0755);
- r = mkdir_safe_label("/var/lib/elogind/linger", 0755, 0, 0, false);
+ r = mkdir_safe_label("/var/lib/elogind/linger", 0755, 0, 0, 0);
if (r < 0)
return r;
@@ -2078,7 +2084,7 @@ static int update_schedule_file(Manager *m) {
assert(m);
- r = mkdir_safe_label("/run/systemd/shutdown", 0755, 0, 0, false);
+ r = mkdir_safe_label("/run/systemd/shutdown", 0755, 0, 0, 0);
if (r < 0)
return log_error_errno(r, "Failed to create shutdown subdirectory: %m");
@@ -3247,8 +3253,13 @@ int manager_start_scope(
return r;
}
- /* Make sure that the session shells are terminated with SIGHUP since bash and friends tend to ignore
- * SIGTERM */
+ /* cgroup empty notification is not available in containers
+ * currently. To make this less problematic, let's shorten the
+ * stop timeout for sessions, so that we don't wait
+ * forever. */
+
+ /* Make sure that the session shells are terminated with
+ * SIGHUP since bash and friends tend to ignore SIGTERM */
r = sd_bus_message_append(m, "(sv)", "SendSIGHUP", "b", true);
if (r < 0)
return r;