/***
This file is part of systemd.
Copyright 2012 Lennart Poettering
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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include "alloc-util.h"
#include "escape.h"
#include "fd-util.h"
#include "fileio.h"
#include "formats-util.h"
#include "logind-inhibit.h"
#include "mkdir.h"
#include "parse-util.h"
#include "string-table.h"
#include "string-util.h"
#include "user-util.h"
#include "util.h"
Inhibitor *i;
assert(m);
if (!i)
return NULL;
if (!i->state_file) {
free(i);
return NULL;
}
free(i->state_file);
free(i);
return NULL;
}
i->manager = m;
i->fifo_fd = -1;
return i;
}
assert(i);
if (i->state_file) {
unlink(i->state_file);
free(i->state_file);
}
free(i);
}
int r;
assert(i);
if (r < 0)
goto fail;
if (r < 0)
goto fail;
fprintf(f,
"# This is private data. Do not parse.\n"
"WHAT=%s\n"
"MODE=%s\n"
i->uid,
i->pid);
if (i->who) {
if (!cc) {
r = -ENOMEM;
goto fail;
}
}
if (i->why) {
if (!cc) {
r = -ENOMEM;
goto fail;
}
}
if (i->fifo_path)
r = fflush_and_check(f);
if (r < 0)
goto fail;
r = -errno;
goto fail;
}
return 0;
fail:
(void) unlink(i->state_file);
if (temp_path)
}
assert(i);
if (i->started)
return 0;
dual_timestamp_get(&i->since);
inhibit_mode_to_string(i->mode));
inhibitor_save(i);
i->started = true;
manager_send_changed(i->manager, i->mode == INHIBIT_BLOCK ? "BlockInhibited" : "DelayInhibited", NULL);
return 0;
}
assert(i);
if (i->started)
inhibit_mode_to_string(i->mode));
if (i->state_file)
unlink(i->state_file);
i->started = false;
manager_send_changed(i->manager, i->mode == INHIBIT_BLOCK ? "BlockInhibited" : "DelayInhibited", NULL);
return 0;
}
_cleanup_free_ char
InhibitWhat w;
char *cc;
int r;
"WHAT", &what,
"UID", &uid,
"PID", &pid,
"WHO", &who,
"WHY", &why,
"MODE", &mode,
"FIFO", &i->fifo_path,
NULL);
if (r < 0)
return r;
if (w >= 0)
i->what = w;
if (mm >= 0)
if (uid) {
if (r < 0)
return r;
}
if (pid) {
if (r < 0)
return r;
}
if (who) {
if (r < 0)
return r;
}
if (why) {
if (r < 0)
return r;
}
if (i->fifo_path) {
int fd;
fd = inhibitor_create_fifo(i);
safe_close(fd);
}
return 0;
}
assert(s);
assert(i);
inhibitor_stop(i);
inhibitor_free(i);
return 0;
}
int r;
assert(i);
/* Create FIFO */
if (!i->fifo_path) {
if (r < 0)
return r;
if (!i->fifo_path)
return -ENOMEM;
return -errno;
}
/* Open reading side */
if (i->fifo_fd < 0) {
if (i->fifo_fd < 0)
return -errno;
}
if (!i->event_source) {
r = sd_event_add_io(i->manager->event, &i->event_source, i->fifo_fd, 0, inhibitor_dispatch_fifo, i);
if (r < 0)
return r;
if (r < 0)
return r;
}
/* Open writing side */
if (r < 0)
return -errno;
return r;
}
assert(i);
if (i->fifo_path) {
}
}
Inhibitor *i;
Iterator j;
assert(m);
HASHMAP_FOREACH(i, m->inhibitors, j)
return what;
}
Session *s;
int r;
r = manager_get_session_by_pid(m, pid, &s);
if (r < 0)
return r;
/* If there's no session assigned to it, then it's globally
* active on all ttys */
if (r == 0)
return 1;
return session_is_active(s);
}
bool manager_is_inhibited(
Manager *m,
InhibitWhat w,
bool ignore_inactive,
bool ignore_uid,
Inhibitor *i;
Iterator j;
bool inhibited = false;
assert(m);
assert(w > 0 && w < _INHIBIT_WHAT_MAX);
HASHMAP_FOREACH(i, m->inhibitors, j) {
if (!(i->what & w))
continue;
continue;
continue;
continue;
if (!inhibited ||
inhibited = true;
if (offending)
*offending = i;
}
if (since)
return inhibited;
}
char *p;
if (w < 0 || w >= _INHIBIT_WHAT_MAX)
return NULL;
p = buffer;
if (w & INHIBIT_SHUTDOWN)
p = stpcpy(p, "shutdown:");
if (w & INHIBIT_SLEEP)
p = stpcpy(p, "sleep:");
if (w & INHIBIT_IDLE)
p = stpcpy(p, "idle:");
if (w & INHIBIT_HANDLE_POWER_KEY)
p = stpcpy(p, "handle-power-key:");
if (w & INHIBIT_HANDLE_SUSPEND_KEY)
p = stpcpy(p, "handle-suspend-key:");
if (w & INHIBIT_HANDLE_HIBERNATE_KEY)
p = stpcpy(p, "handle-hibernate-key:");
if (w & INHIBIT_HANDLE_LID_SWITCH)
p = stpcpy(p, "handle-lid-switch:");
if (p > buffer)
*(p-1) = 0;
else
*p = 0;
return buffer;
}
size_t l;
what |= INHIBIT_SHUTDOWN;
what |= INHIBIT_SLEEP;
what |= INHIBIT_IDLE;
else
return _INHIBIT_WHAT_INVALID;
}
return what;
}
[INHIBIT_BLOCK] = "block",
[INHIBIT_DELAY] = "delay"
};