X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Flogin%2Flogind-inhibit.c;h=60b6237ce5e71b3604bbee4b528a74cfa2956992;hp=e4eefd0def4af912054a0fce8cd35fd972c6e1a0;hb=a34faf579d2be139b0b9e8cd0c73ad4d918ef736;hpb=eecd1362f7f4de432483b5d77c56726c3621a83a diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c index e4eefd0de..60b6237ce 100644 --- a/src/login/logind-inhibit.c +++ b/src/login/logind-inhibit.c @@ -28,7 +28,7 @@ #include "util.h" #include "mkdir.h" - +#include "path-util.h" #include "logind-inhibit.h" Inhibitor* inhibitor_new(Manager *m, const char* id) { @@ -46,7 +46,7 @@ Inhibitor* inhibitor_new(Manager *m, const char* id) { return NULL; } - i->id = file_name_from_path(i->state_file); + i->id = path_get_file_name(i->state_file); if (hashmap_put(m->inhibitors, i->id, i) < 0) { free(i->state_file); @@ -84,7 +84,7 @@ int inhibitor_save(Inhibitor *i) { assert(i); - r = safe_mkdir("/run/systemd/inhibit", 0755, 0, 0); + r = mkdir_safe_label("/run/systemd/inhibit", 0755, 0, 0); if (r < 0) goto finish; @@ -163,7 +163,7 @@ int inhibitor_start(Inhibitor *i) { i->started = true; - manager_send_changed(i->manager, "Inhibited\0"); + manager_send_changed(i->manager, i->mode == INHIBIT_BLOCK ? "BlockInhibited\0" : "DelayInhibited\0"); return 0; } @@ -182,7 +182,7 @@ int inhibitor_stop(Inhibitor *i) { i->started = false; - manager_send_changed(i->manager, "Inhibited\0"); + manager_send_changed(i->manager, i->mode == INHIBIT_BLOCK ? "BlockInhibited\0" : "DelayInhibited\0"); return 0; } @@ -219,11 +219,17 @@ int inhibitor_load(Inhibitor *i) { if (mm >= 0) i->mode = mm; - if (uid) - parse_uid(uid, &i->uid); + if (uid) { + r = parse_uid(uid, &i->uid); + if (r < 0) + goto finish; + } - if (pid) - parse_pid(pid, &i->pid); + if (pid) { + r = parse_pid(pid, &i->pid); + if (r < 0) + goto finish; + } if (who) { cc = cunescape(who); @@ -272,7 +278,7 @@ int inhibitor_create_fifo(Inhibitor *i) { /* Create FIFO */ if (!i->fifo_path) { - r = safe_mkdir("/run/systemd/inhibit", 0755, 0, 0); + r = mkdir_safe_label("/run/systemd/inhibit", 0755, 0, 0); if (r < 0) return r; @@ -297,7 +303,7 @@ int inhibitor_create_fifo(Inhibitor *i) { zero(ev); ev.events = 0; - ev.data.u32 = FD_FIFO_BASE + i->fifo_fd; + ev.data.u32 = FD_OTHER_BASE + i->fifo_fd; if (epoll_ctl(i->manager->epoll_fd, EPOLL_CTL_ADD, i->fifo_fd, &ev) < 0) return -errno; @@ -376,12 +382,12 @@ const char *inhibit_what_to_string(InhibitWhat w) { static const char* const table[_INHIBIT_WHAT_MAX] = { [0] = "", [INHIBIT_SHUTDOWN] = "shutdown", - [INHIBIT_SUSPEND] = "suspend", + [INHIBIT_SLEEP] = "sleep", [INHIBIT_IDLE] = "idle", - [INHIBIT_SHUTDOWN|INHIBIT_SUSPEND] = "shutdown:suspend", + [INHIBIT_SHUTDOWN|INHIBIT_SLEEP] = "shutdown:sleep", [INHIBIT_SHUTDOWN|INHIBIT_IDLE] = "shutdown:idle", - [INHIBIT_SHUTDOWN|INHIBIT_SUSPEND|INHIBIT_IDLE] = "shutdown:suspend:idle", - [INHIBIT_SUSPEND|INHIBIT_IDLE] = "suspend:idle" + [INHIBIT_SHUTDOWN|INHIBIT_SLEEP|INHIBIT_IDLE] = "shutdown:sleep:idle", + [INHIBIT_SLEEP|INHIBIT_IDLE] = "sleep:idle" }; if (w < 0 || w >= _INHIBIT_WHAT_MAX) @@ -398,8 +404,8 @@ InhibitWhat inhibit_what_from_string(const char *s) { FOREACH_WORD_SEPARATOR(w, l, s, ":", state) { if (l == 8 && strncmp(w, "shutdown", l) == 0) what |= INHIBIT_SHUTDOWN; - else if (l == 7 && strncmp(w, "suspend", l) == 0) - what |= INHIBIT_SUSPEND; + else if (l == 5 && strncmp(w, "sleep", l) == 0) + what |= INHIBIT_SLEEP; else if (l == 4 && strncmp(w, "idle", l) == 0) what |= INHIBIT_IDLE; else