mirror of
https://github.com/AuxXxilium/eudev.git
synced 2024-12-15 11:07:24 +07:00
logind: if we have to stop a session, kill at least its leader
This commit is contained in:
parent
7e64c73a93
commit
9b221b63e5
@ -601,6 +601,23 @@ static int session_terminate_cgroup(Session *s) {
|
||||
log_error("Failed to kill session cgroup: %s", strerror(-r));
|
||||
|
||||
} else {
|
||||
if (s->leader > 0) {
|
||||
Session *t;
|
||||
|
||||
/* We still send a HUP to the leader process,
|
||||
* even if we are not supposed to kill the
|
||||
* whole cgroup. But let's first check the
|
||||
* leader still exists and belongs to our
|
||||
* session... */
|
||||
|
||||
r = manager_get_session_by_pid(s->manager, s->leader, &t);
|
||||
if (r > 0 && t == s) {
|
||||
kill(s->leader, SIGTERM); /* for normal processes */
|
||||
kill(s->leader, SIGHUP); /* for shells */
|
||||
kill(s->leader, SIGCONT); /* in case they are stopped */
|
||||
}
|
||||
}
|
||||
|
||||
r = cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, s->cgroup_path, true);
|
||||
if (r < 0)
|
||||
log_error("Failed to check session cgroup: %s", strerror(-r));
|
||||
@ -608,8 +625,7 @@ static int session_terminate_cgroup(Session *s) {
|
||||
r = cg_delete(SYSTEMD_CGROUP_CONTROLLER, s->cgroup_path);
|
||||
if (r < 0)
|
||||
log_error("Failed to delete session cgroup: %s", strerror(-r));
|
||||
} else
|
||||
r = -EBUSY;
|
||||
}
|
||||
}
|
||||
|
||||
STRV_FOREACH(k, s->user->manager->controllers)
|
||||
@ -620,7 +636,7 @@ static int session_terminate_cgroup(Session *s) {
|
||||
free(s->cgroup_path);
|
||||
s->cgroup_path = NULL;
|
||||
|
||||
return r;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int session_unlink_x11_socket(Session *s) {
|
||||
|
@ -781,34 +781,68 @@ finish:
|
||||
return r;
|
||||
}
|
||||
|
||||
void manager_cgroup_notify_empty(Manager *m, const char *cgroup) {
|
||||
Session *s;
|
||||
int manager_get_session_by_cgroup(Manager *m, const char *cgroup, Session **session) {
|
||||
char *p;
|
||||
|
||||
assert(m);
|
||||
assert(cgroup);
|
||||
assert(session);
|
||||
|
||||
p = strdup(cgroup);
|
||||
if (!p) {
|
||||
log_error("Out of memory.");
|
||||
return;
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
Session *s;
|
||||
char *e;
|
||||
|
||||
if (isempty(p) || streq(p, "/"))
|
||||
break;
|
||||
if (isempty(p) || streq(p, "/")) {
|
||||
free(p);
|
||||
*session = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
s = hashmap_get(m->cgroups, p);
|
||||
if (s)
|
||||
session_add_to_gc_queue(s);
|
||||
if (s) {
|
||||
free(p);
|
||||
*session = s;
|
||||
return 1;
|
||||
}
|
||||
|
||||
assert_se(e = strrchr(p, '/'));
|
||||
*e = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int manager_get_session_by_pid(Manager *m, pid_t pid, Session **session) {
|
||||
char *p;
|
||||
int r;
|
||||
|
||||
assert(m);
|
||||
assert(pid >= 1);
|
||||
assert(session);
|
||||
|
||||
r = cg_get_by_pid(SYSTEMD_CGROUP_CONTROLLER, pid, &p);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = manager_get_session_by_cgroup(m, p, session);
|
||||
free(p);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
void manager_cgroup_notify_empty(Manager *m, const char *cgroup) {
|
||||
Session *s;
|
||||
int r;
|
||||
|
||||
r = manager_get_session_by_cgroup(m, cgroup, &s);
|
||||
if (r <= 0)
|
||||
return;
|
||||
|
||||
session_add_to_gc_queue(s);
|
||||
}
|
||||
|
||||
static void manager_pipe_notify_eof(Manager *m, int fd) {
|
||||
|
@ -116,6 +116,9 @@ void manager_gc(Manager *m, bool drop_not_started);
|
||||
|
||||
int manager_get_idle_hint(Manager *m, dual_timestamp *t);
|
||||
|
||||
int manager_get_session_by_cgroup(Manager *m, const char *cgroup, Session **session);
|
||||
int manager_get_session_by_pid(Manager *m, pid_t pid, Session **session);
|
||||
|
||||
extern const DBusObjectPathVTable bus_manager_vtable;
|
||||
|
||||
DBusHandlerResult bus_message_filter(DBusConnection *c, DBusMessage *message, void *userdata);
|
||||
|
Loading…
Reference in New Issue
Block a user