chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
dbus: add dbus introspection extraction
[elogind.git]
/
src
/
logind-session.c
diff --git
a/src/logind-session.c
b/src/logind-session.c
index 9af99d054a788f416c296a8db8aea2b00814545d..6b3b277897544084b844aef1331e6b8c02ada2d0 100644
(file)
--- a/
src/logind-session.c
+++ b/
src/logind-session.c
@@
-23,7
+23,7
@@
#include <string.h>
#include <unistd.h>
#include <string.h>
#include <unistd.h>
-#include "logind.h"
+#include "logind
-session
.h"
#include "strv.h"
#include "util.h"
#include "cgroup-util.h"
#include "strv.h"
#include "util.h"
#include "cgroup-util.h"
@@
-34,7
+34,7
@@
Session* session_new(Manager *m, User *u, const char *id) {
assert(m);
assert(id);
assert(m);
assert(id);
- s = new(Session, 1);
+ s = new
0
(Session, 1);
if (!s)
return NULL;
if (!s)
return NULL;
@@
-56,7
+56,7
@@
Session* session_new(Manager *m, User *u, const char *id) {
s->pipe_fd = -1;
s->user = u;
s->pipe_fd = -1;
s->user = u;
-
dual_timestamp_get(&s->timestamp
);
+
LIST_PREPEND(Session, sessions_by_user, u->sessions, s
);
return s;
}
return s;
}
@@
-64,6
+64,9
@@
Session* session_new(Manager *m, User *u, const char *id) {
void session_free(Session *s) {
assert(s);
void session_free(Session *s) {
assert(s);
+ if (s->in_gc_queue)
+ LIST_REMOVE(Session, gc_queue, s->manager->session_gc_queue, s);
+
if (s->user) {
LIST_REMOVE(Session, sessions_by_user, s->user->sessions, s);
if (s->user) {
LIST_REMOVE(Session, sessions_by_user, s->user->sessions, s);
@@
-80,6
+83,7
@@
void session_free(Session *s) {
free(s->tty);
free(s->display);
free(s->remote_host);
free(s->tty);
free(s->display);
free(s->remote_host);
+ free(s->remote_user);
hashmap_remove(s->manager->sessions, s->id);
hashmap_remove(s->manager->sessions, s->id);
@@
-90,19
+94,22
@@
void session_free(Session *s) {
int session_save(Session *s) {
FILE *f;
int r = 0;
int session_save(Session *s) {
FILE *f;
int r = 0;
+ char *temp_path;
assert(s);
r = safe_mkdir("/run/systemd/session", 0755, 0, 0);
if (r < 0)
assert(s);
r = safe_mkdir("/run/systemd/session", 0755, 0, 0);
if (r < 0)
-
return r
;
+
goto finish
;
-
f = fopen(s->state_file, "we"
);
- if (
!f
)
-
return -errno
;
+
r = fopen_temporary(s->state_file, &f, &temp_path
);
+ if (
r < 0
)
+
goto finish
;
assert(s->user);
assert(s->user);
+ fchmod(fileno(f), 0644);
+
fprintf(f,
"# This is private data. Do not parse.\n"
"UID=%lu\n"
fprintf(f,
"# This is private data. Do not parse.\n"
"UID=%lu\n"
@@
-141,6
+148,11
@@
int session_save(Session *s) {
"REMOTE_HOST=%s\n",
s->remote_host);
"REMOTE_HOST=%s\n",
s->remote_host);
+ if (s->remote_user)
+ fprintf(f,
+ "REMOTE_USER=%s\n",
+ s->remote_user);
+
if (s->seat && s->seat->manager->vtconsole == s->seat)
fprintf(f,
"VTNR=%i\n",
if (s->seat && s->seat->manager->vtconsole == s->seat)
fprintf(f,
"VTNR=%i\n",
@@
-157,12
+169,20
@@
int session_save(Session *s) {
(unsigned long long) s->audit_id);
fflush(f);
(unsigned long long) s->audit_id);
fflush(f);
- if (ferror(f)) {
+
+ if (ferror(f) || rename(temp_path, s->state_file) < 0) {
r = -errno;
unlink(s->state_file);
r = -errno;
unlink(s->state_file);
+ unlink(temp_path);
}
fclose(f);
}
fclose(f);
+ free(temp_path);
+
+finish:
+ if (r < 0)
+ log_error("Failed to save session data for %s: %s", s->id, strerror(-r));
+
return r;
}
return r;
}
@@
-174,6
+194,7
@@
int session_load(Session *s) {
int session_activate(Session *s) {
int r;
int session_activate(Session *s) {
int r;
+ Session *old_active;
assert(s);
assert(s);
@@
-192,9
+213,10
@@
int session_activate(Session *s) {
if (r < 0)
return r;
if (r < 0)
return r;
+ old_active = s->seat->active;
s->seat->active = s;
s->seat->active = s;
- return seat_apply_acls(s->seat);
+ return seat_apply_acls(s->seat
, old_active
);
}
bool x11_display_is_local(const char *display) {
}
bool x11_display_is_local(const char *display) {
@@
-328,11
+350,6
@@
int session_start(Session *s) {
assert(s);
assert(s->user);
assert(s);
assert(s->user);
- /* Create user first */
- r = user_start(s->user);
- if (r < 0)
- return r;
-
/* Create cgroup */
r = session_create_cgroup(s);
if (r < 0)
/* Create cgroup */
r = session_create_cgroup(s);
if (r < 0)
@@
-340,6
+357,12
@@
int session_start(Session *s) {
/* Create X11 symlink */
session_link_x11_socket(s);
/* Create X11 symlink */
session_link_x11_socket(s);
+
+ /* Save session data */
+ session_save(s);
+
+ dual_timestamp_get(&s->timestamp);
+
return 0;
}
return 0;
}
@@
-424,6
+447,9
@@
int session_stop(Session *s) {
/* Remove X11 symlink */
session_unlink_x11_socket(s);
/* Remove X11 symlink */
session_unlink_x11_socket(s);
+ unlink(s->state_file);
+ session_add_to_gc_queue(s);
+
return r;
}
return r;
}
@@
-447,7
+473,7
@@
int session_check_gc(Session *s) {
if (r < 0)
return r;
if (r < 0)
return r;
- if (r
<
= 0)
+ if (r
=
= 0)
return 1;
}
return 1;
}
@@
-464,8
+490,18
@@
int session_check_gc(Session *s) {
return 0;
}
return 0;
}
+void session_add_to_gc_queue(Session *s) {
+ assert(s);
+
+ if (s->in_gc_queue)
+ return;
+
+ LIST_PREPEND(Session, gc_queue, s->manager->session_gc_queue, s);
+ s->in_gc_queue = true;
+}
+
static const char* const session_type_table[_SESSION_TYPE_MAX] = {
static const char* const session_type_table[_SESSION_TYPE_MAX] = {
- [SESSION_T
ERMINAL] = "terminal
",
+ [SESSION_T
TY] = "tty
",
[SESSION_X11] = "x11"
};
[SESSION_X11] = "x11"
};