#include <linux/kd.h>
#include <linux/vt.h>
#include <signal.h>
-#include <stdio_ext.h>
#include <string.h>
#include <sys/ioctl.h>
+#include <sys/stat.h>
#include <unistd.h>
#include "sd-messages.h"
#include "audit-util.h"
#include "bus-error.h"
#include "bus-util.h"
+#include "env-file.h"
#include "escape.h"
#include "fd-util.h"
#include "fileio.h"
#include "format-util.h"
#include "io-util.h"
+#include "logind-dbus.h"
+#include "logind-seat-dbus.h"
+#include "logind-session-dbus.h"
#include "logind-session.h"
+#include "logind-user-dbus.h"
#include "mkdir.h"
#include "parse-util.h"
#include "path-util.h"
#include "process-util.h"
+#include "serialize.h"
#include "string-table.h"
#include "strv.h"
#include "terminal-util.h"
+#include "tmpfile-util.h"
#include "user-util.h"
#include "util.h"
#define RELEASE_USEC (20*USEC_PER_SEC)
static void session_remove_fifo(Session *s);
+static void session_restore_vt(Session *s);
int session_new(Session **ret, Manager *m, const char *id) {
_cleanup_(session_freep) Session *s = NULL;
if (r < 0)
goto fail;
- (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
(void) fchmod(fileno(f), 0644);
fprintf(f,
assert(s);
- r = parse_env_file(NULL, s->state_file, NEWLINE,
+ r = parse_env_file(NULL, s->state_file,
"REMOTE", &remote,
"SCOPE", &s->scope,
"SCOPE_JOB", &s->scope_job,
"CONTROLLER", &controller,
"ACTIVE", &active,
"DEVICES", &devices,
- "IS_DISPLAY", &is_display,
- NULL);
+ "IS_DISPLAY", &is_display);
if (r < 0)
return log_error_errno(r, "Failed to read %s: %m", s->state_file);
uid_t u;
User *user;
- if (!uid) {
- log_error("UID not specified for session %s", s->id);
- return -ENOENT;
- }
+ if (!uid)
+ return log_error_errno(SYNTHETIC_ERRNO(ENOENT),
+ "UID not specified for session %s",
+ s->id);
r = parse_uid(uid, &u);
if (r < 0) {
}
user = hashmap_get(s->manager->users, UID_TO_PTR(u));
- if (!user) {
- log_error("User of session %s not known.", s->id);
- return -ENOENT;
- }
+ if (!user)
+ return log_error_errno(SYNTHETIC_ERRNO(ENOENT),
+ "User of session %s not known.",
+ s->id);
session_set_user(s, user);
}
}
if (realtime)
- timestamp_deserialize(realtime, &s->timestamp.realtime);
+ (void) deserialize_usec(realtime, &s->timestamp.realtime);
if (monotonic)
- timestamp_deserialize(monotonic, &s->timestamp.monotonic);
+ (void) deserialize_usec(monotonic, &s->timestamp.monotonic);
if (active) {
k = parse_boolean(active);
s->leader,
s->user->slice,
description,
- STRV_MAKE(s->user->runtime_dir_service, s->user->service), /* These two have StopWhenUnneeded= set, hence add a dep towards them */
- STRV_MAKE("systemd-logind.service", "systemd-user-sessions.service", s->user->runtime_dir_service, s->user->service), /* And order us after some more */
+ /* These two have StopWhenUnneeded= set, hence add a dep towards them */
+ STRV_MAKE(s->user->runtime_dir_service,
+ s->user->service),
+ /* And order us after some more */
+ STRV_MAKE("systemd-logind.service",
+ "systemd-user-sessions.service",
+ s->user->runtime_dir_service,
+ s->user->service),
s->user->home,
properties,
error,
&s->scope_job);
if (r < 0)
- return log_error_errno(r, "Failed to start session scope %s: %s", scope, bus_error_message(error, r));
+ return log_error_errno(r, "Failed to start session scope %s: %s",
+ scope, bus_error_message(error, r));
s->scope = TAKE_PTR(scope);
}
- if (s->scope)
- (void) hashmap_put(s->manager->session_units, s->scope, s);
+ (void) hashmap_put(s->manager->session_units, s->scope, s);
return 0;
}
return r;
}
-void session_restore_vt(Session *s) {
-
- static const struct vt_mode mode = {
- .mode = VT_AUTO,
- };
-
- int vt, old_fd;
+static void session_restore_vt(Session *s) {
+ int r, vt, old_fd;
/* We need to get a fresh handle to the virtual terminal,
* since the old file-descriptor is potentially in a hung-up
if (vt < 0)
return;
- (void) ioctl(vt, KDSETMODE, KD_TEXT);
-
- (void) vt_reset_keyboard(vt);
-
- (void) ioctl(vt, VT_SETMODE, &mode);
- (void) fchown(vt, 0, (gid_t) -1);
+ r = vt_restore(vt);
+ if (r < 0)
+ log_warning_errno(r, "Failed to restore VT, ignoring: %m");
s->vtfd = safe_close(s->vtfd);
}
return;
session_device_pause_all(s);
- r = ioctl(s->vtfd, VT_RELDISP, 1);
+ r = vt_release(s->vtfd, false);
if (r < 0)
- log_debug_errno(errno, "Cannot release VT of session %s: %m", s->id);
+ log_debug_errno(r, "Cannot release VT of session %s: %m", s->id);
}
bool session_is_controller(Session *s, const char *sender) {