if (s->scope)
fprintf(f, "SCOPE=%s\n", s->scope);
-
if (s->scope_job)
fprintf(f, "SCOPE_JOB=%s\n", s->scope_job);
if (s->display)
fprintf(f, "DISPLAY=%s\n", s->display);
- if (s->remote_host)
- fprintf(f, "REMOTE_HOST=%s\n", s->remote_host);
+ if (s->remote_host) {
+ _cleanup_free_ char *escaped;
+
+ escaped = cescape(s->remote_host);
+ if (!escaped) {
+ r = -ENOMEM;
+ goto finish;
+ }
+
+ fprintf(f, "REMOTE_HOST=%s\n", escaped);
+ }
+
+ if (s->remote_user) {
+ _cleanup_free_ char *escaped;
+
+ escaped = cescape(s->remote_user);
+ if (!escaped) {
+ r = -ENOMEM;
+ goto finish;
+ }
+
+ fprintf(f, "REMOTE_USER=%s\n", escaped);
+ }
+
+ if (s->service) {
+ _cleanup_free_ char *escaped;
+
+ escaped = cescape(s->service);
+ if (!escaped) {
+ r = -ENOMEM;
+ goto finish;
+ }
+
+ fprintf(f, "SERVICE=%s\n", escaped);
+ }
- if (s->remote_user)
- fprintf(f, "REMOTE_USER=%s\n", s->remote_user);
+ if (s->desktop) {
+ _cleanup_free_ char *escaped;
- if (s->service)
- fprintf(f, "SERVICE=%s\n", s->service);
- if (s->desktop)
- fprintf(f, "DESKTOP=%s\n", s->desktop);
+ escaped = cescape(s->desktop);
+ if (!escaped) {
+ r = -ENOMEM;
+ goto finish;
+ }
+
+ fprintf(f, "DESKTOP=%s\n", escaped);
+ }
if (s->seat && seat_has_vts(s->seat))
fprintf(f, "VTNR=%u\n", s->vtnr);
MESSAGE_ID(SD_MESSAGE_SESSION_START),
"SESSION_ID=%s", s->id,
"USER_ID=%s", s->user->name,
- "LEADER=%lu", (unsigned long) s->leader,
+ "LEADER="PID_FMT, s->leader,
"MESSAGE=New session %s of user %s.", s->id, s->user->name,
NULL);
s->started = true;
+ user_elect_display(s->user);
+
/* Save data */
session_save(s);
user_save(s->user);
/* Send signals */
session_send_signal(s, true);
- user_send_changed(s->user, "Sessions", NULL);
+ user_send_changed(s->user, "Sessions", "Display", NULL);
if (s->seat) {
if (s->seat->active == s)
seat_send_changed(s->seat, "Sessions", "ActiveSession", NULL);
s->stopping = true;
+ user_elect_display(s->user);
+
session_save(s);
user_save(s->user);
MESSAGE_ID(SD_MESSAGE_SESSION_STOP),
"SESSION_ID=%s", s->id,
"USER_ID=%s", s->user->name,
- "LEADER=%lu", (unsigned long) s->leader,
+ "LEADER="PID_FMT, s->leader,
"MESSAGE=Removed session %s.", s->id,
NULL);
}
user_save(s->user);
- user_send_changed(s->user, "Sessions", NULL);
+ user_send_changed(s->user, "Sessions", "Display", NULL);
return r;
}
return 0;
}
-void session_mute_vt(Session *s) {
+void session_prepare_vt(Session *s) {
int vt, r;
struct vt_mode mode = { 0 };
sigset_t mask;
if (vt < 0)
return;
+ r = fchown(vt, s->user->uid, -1);
+ if (r < 0)
+ goto error;
+
r = ioctl(vt, KDSKBMODE, K_OFF);
if (r < 0)
goto error;
mode.mode = VT_AUTO;
ioctl(vt, VT_SETMODE, &mode);
+ fchown(vt, 0, -1);
+
s->vtfd = safe_close(s->vtfd);
}
* exits.
* If logind crashes/restarts, we restore the controller during restart
* or reset the VT in case it crashed/exited, too. */
- session_mute_vt(s);
+ session_prepare_vt(s);
return 0;
}
[SESSION_TTY] = "tty",
[SESSION_X11] = "x11",
[SESSION_WAYLAND] = "wayland",
+ [SESSION_MIR] = "mir",
};
DEFINE_STRING_TABLE_LOOKUP(session_type, SessionType);