X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Flogin%2Flogind.c;h=67117405e67027f8b7b48677ec2c34de3cfcc585;hp=333d5f85bdd09c808c310bc7d513a2c3cd864f58;hb=5430f7f2bc7330f3088b894166bf3524a067e3d8;hpb=976c088a0242a1a91b8f00899a4c2ae0e621a185
diff --git a/src/login/logind.c b/src/login/logind.c
index 333d5f85b..67117405e 100644
--- a/src/login/logind.c
+++ b/src/login/logind.c
@@ -6,16 +6,16 @@
Copyright 2011 Lennart Poettering
systemd is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
+ Lesser General Public License for more details.
- You should have received a copy of the GNU General Public License
+ You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see .
***/
@@ -29,6 +29,8 @@
#include
#include
+#include
+
#include "logind.h"
#include "dbus-common.h"
#include "dbus-loop.h"
@@ -779,34 +781,74 @@ finish:
return r;
}
-void manager_cgroup_notify_empty(Manager *m, const char *cgroup) {
+int manager_get_session_by_cgroup(Manager *m, const char *cgroup, Session **session) {
Session *s;
char *p;
assert(m);
assert(cgroup);
+ assert(session);
+
+ s = hashmap_get(m->cgroups, cgroup);
+ if (s) {
+ *session = s;
+ return 1;
+ }
p = strdup(cgroup);
if (!p) {
log_error("Out of memory.");
- return;
+ return -ENOMEM;
}
for (;;) {
char *e;
- if (isempty(p) || streq(p, "/"))
- break;
-
- s = hashmap_get(m->cgroups, p);
- if (s)
- session_add_to_gc_queue(s);
+ e = strrchr(p, '/');
+ if (!e || e == p) {
+ free(p);
+ *session = NULL;
+ return 0;
+ }
- assert_se(e = strrchr(p, '/'));
*e = 0;
+
+ s = hashmap_get(m->cgroups, p);
+ if (s) {
+ free(p);
+ *session = s;
+ return 1;
+ }
}
+}
+
+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) {
@@ -1174,7 +1216,7 @@ static int manager_parse_config_file(Manager *m) {
assert(m);
- fn = "/etc/systemd/systemd-logind.conf";
+ fn = "/etc/systemd/logind.conf";
f = fopen(fn, "re");
if (!f) {
if (errno == ENOENT)
@@ -1198,6 +1240,7 @@ int main(int argc, char *argv[]) {
int r;
log_set_target(LOG_TARGET_AUTO);
+ log_set_facility(LOG_AUTH);
log_parse_environment();
log_open();
@@ -1224,9 +1267,20 @@ int main(int argc, char *argv[]) {
goto finish;
}
+ log_debug("systemd-logind running as pid %lu", (unsigned long) getpid());
+
+ sd_notify(false,
+ "READY=1\n"
+ "STATUS=Processing requests...");
+
r = manager_run(m);
+ log_debug("systemd-logind stopped as pid %lu", (unsigned long) getpid());
+
finish:
+ sd_notify(false,
+ "STATUS=Shutting down...");
+
if (m)
manager_free(m);