2011-07-14 22:50:01 +02:00
|
|
|
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
|
|
|
|
|
|
|
|
/***
|
|
|
|
This file is part of systemd.
|
|
|
|
|
|
|
|
Copyright 2011 Lennart Poettering
|
|
|
|
|
|
|
|
systemd is free software; you can redistribute it and/or modify it
|
2012-04-12 00:20:58 +02:00
|
|
|
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
|
2011-07-14 22:50:01 +02:00
|
|
|
(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
|
2012-04-12 00:20:58 +02:00
|
|
|
Lesser General Public License for more details.
|
2011-07-14 22:50:01 +02:00
|
|
|
|
2012-04-12 00:20:58 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
2011-07-14 22:50:01 +02:00
|
|
|
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
***/
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
2011-07-22 21:01:15 +02:00
|
|
|
#include <sys/inotify.h>
|
2013-04-04 17:38:08 +02:00
|
|
|
#include <sys/poll.h>
|
2011-07-14 22:50:01 +02:00
|
|
|
|
|
|
|
#include "util.h"
|
|
|
|
#include "cgroup-util.h"
|
|
|
|
#include "macro.h"
|
2011-07-22 21:01:15 +02:00
|
|
|
#include "strv.h"
|
2013-02-14 12:26:13 +01:00
|
|
|
#include "fileio.h"
|
2013-09-16 04:26:56 +02:00
|
|
|
#include "login-shared.h"
|
2013-12-10 18:01:10 +01:00
|
|
|
#include "sd-login.h"
|
2011-07-14 22:50:01 +02:00
|
|
|
|
2011-07-22 21:01:15 +02:00
|
|
|
_public_ int sd_pid_get_session(pid_t pid, char **session) {
|
2012-05-30 22:25:01 +02:00
|
|
|
|
2013-12-02 22:42:01 +01:00
|
|
|
assert_return(pid >= 0, -EINVAL);
|
|
|
|
assert_return(session, -EINVAL);
|
2011-07-22 21:01:15 +02:00
|
|
|
|
2013-04-16 04:36:06 +02:00
|
|
|
return cg_pid_get_session(pid, session);
|
2011-07-14 22:50:01 +02:00
|
|
|
}
|
|
|
|
|
2012-01-04 15:35:30 +01:00
|
|
|
_public_ int sd_pid_get_unit(pid_t pid, char **unit) {
|
2012-01-03 20:51:38 +01:00
|
|
|
|
2013-12-02 22:42:01 +01:00
|
|
|
assert_return(pid >= 0, -EINVAL);
|
|
|
|
assert_return(unit, -EINVAL);
|
2012-01-03 20:51:38 +01:00
|
|
|
|
2012-05-30 22:25:01 +02:00
|
|
|
return cg_pid_get_unit(pid, unit);
|
2012-01-03 20:51:38 +01:00
|
|
|
}
|
|
|
|
|
2013-04-15 14:16:45 +02:00
|
|
|
_public_ int sd_pid_get_user_unit(pid_t pid, char **unit) {
|
|
|
|
|
2013-12-02 22:42:01 +01:00
|
|
|
assert_return(pid >= 0, -EINVAL);
|
|
|
|
assert_return(unit, -EINVAL);
|
2013-04-15 14:16:45 +02:00
|
|
|
|
|
|
|
return cg_pid_get_user_unit(pid, unit);
|
|
|
|
}
|
|
|
|
|
2013-04-16 04:36:06 +02:00
|
|
|
_public_ int sd_pid_get_machine_name(pid_t pid, char **name) {
|
|
|
|
|
2013-12-02 22:42:01 +01:00
|
|
|
assert_return(pid >= 0, -EINVAL);
|
|
|
|
assert_return(name, -EINVAL);
|
2013-04-16 04:36:06 +02:00
|
|
|
|
|
|
|
return cg_pid_get_machine_name(pid, name);
|
|
|
|
}
|
|
|
|
|
2013-06-21 01:46:27 +02:00
|
|
|
_public_ int sd_pid_get_slice(pid_t pid, char **slice) {
|
|
|
|
|
2013-12-02 22:42:01 +01:00
|
|
|
assert_return(pid >= 0, -EINVAL);
|
|
|
|
assert_return(slice, -EINVAL);
|
2013-06-21 01:46:27 +02:00
|
|
|
|
|
|
|
return cg_pid_get_slice(pid, slice);
|
|
|
|
}
|
|
|
|
|
2011-07-22 21:01:15 +02:00
|
|
|
_public_ int sd_pid_get_owner_uid(pid_t pid, uid_t *uid) {
|
|
|
|
|
2013-12-02 22:42:01 +01:00
|
|
|
assert_return(pid >= 0, -EINVAL);
|
|
|
|
assert_return(uid, -EINVAL);
|
2011-07-22 21:01:15 +02:00
|
|
|
|
2013-04-23 04:10:13 +02:00
|
|
|
return cg_pid_get_owner_uid(pid, uid);
|
2011-07-22 21:01:15 +02:00
|
|
|
}
|
|
|
|
|
2014-03-17 18:14:26 +01:00
|
|
|
_public_ int sd_peer_get_session(int fd, char **session) {
|
|
|
|
struct ucred ucred;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert_return(fd >= 0, -EINVAL);
|
|
|
|
assert_return(session, -EINVAL);
|
|
|
|
|
|
|
|
r = getpeercred(fd, &ucred);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
return cg_pid_get_session(ucred.pid, session);
|
|
|
|
}
|
|
|
|
|
|
|
|
_public_ int sd_peer_get_owner_uid(int fd, uid_t *uid) {
|
|
|
|
struct ucred ucred;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert_return(fd >= 0, -EINVAL);
|
|
|
|
assert_return(uid, -EINVAL);
|
|
|
|
|
|
|
|
r = getpeercred(fd, &ucred);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
return cg_pid_get_owner_uid(ucred.pid, uid);
|
|
|
|
}
|
|
|
|
|
|
|
|
_public_ int sd_peer_get_unit(int fd, char **unit) {
|
|
|
|
struct ucred ucred;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert_return(fd >= 0, -EINVAL);
|
|
|
|
assert_return(unit, -EINVAL);
|
|
|
|
|
|
|
|
r = getpeercred(fd, &ucred);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
return cg_pid_get_unit(ucred.pid, unit);
|
|
|
|
}
|
|
|
|
|
|
|
|
_public_ int sd_peer_get_user_unit(int fd, char **unit) {
|
|
|
|
struct ucred ucred;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert_return(fd >= 0, -EINVAL);
|
|
|
|
assert_return(unit, -EINVAL);
|
|
|
|
|
|
|
|
r = getpeercred(fd, &ucred);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
return cg_pid_get_user_unit(ucred.pid, unit);
|
|
|
|
}
|
|
|
|
|
|
|
|
_public_ int sd_peer_get_machine_name(int fd, char **machine) {
|
|
|
|
struct ucred ucred;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert_return(fd >= 0, -EINVAL);
|
|
|
|
assert_return(machine, -EINVAL);
|
|
|
|
|
|
|
|
r = getpeercred(fd, &ucred);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
return cg_pid_get_machine_name(ucred.pid, machine);
|
|
|
|
}
|
|
|
|
|
|
|
|
_public_ int sd_peer_get_slice(int fd, char **slice) {
|
|
|
|
struct ucred ucred;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert_return(fd >= 0, -EINVAL);
|
|
|
|
assert_return(slice, -EINVAL);
|
|
|
|
|
|
|
|
r = getpeercred(fd, &ucred);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
return cg_pid_get_slice(ucred.pid, slice);
|
|
|
|
}
|
|
|
|
|
2014-05-19 02:33:20 +02:00
|
|
|
static int file_of_uid(uid_t uid, char **p) {
|
|
|
|
assert(p);
|
|
|
|
|
|
|
|
if (asprintf(p, "/run/systemd/users/" UID_FMT, uid) < 0)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-07-14 22:50:01 +02:00
|
|
|
_public_ int sd_uid_get_state(uid_t uid, char**state) {
|
2014-03-17 18:14:26 +01:00
|
|
|
_cleanup_free_ char *p = NULL;
|
|
|
|
char *s = NULL;
|
2011-07-14 22:50:01 +02:00
|
|
|
int r;
|
|
|
|
|
2013-12-02 22:42:01 +01:00
|
|
|
assert_return(state, -EINVAL);
|
2011-07-14 22:50:01 +02:00
|
|
|
|
2014-05-19 02:33:20 +02:00
|
|
|
r = file_of_uid(uid, &p);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2011-07-14 22:50:01 +02:00
|
|
|
|
|
|
|
r = parse_env_file(p, NEWLINE, "STATE", &s, NULL);
|
|
|
|
if (r == -ENOENT) {
|
|
|
|
free(s);
|
|
|
|
s = strdup("offline");
|
|
|
|
if (!s)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
} else if (r < 0) {
|
|
|
|
free(s);
|
|
|
|
return r;
|
|
|
|
} else if (!s)
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
*state = s;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-19 02:33:20 +02:00
|
|
|
_public_ int sd_uid_get_display(uid_t uid, char **session) {
|
|
|
|
_cleanup_free_ char *p = NULL, *s = NULL;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert_return(session, -EINVAL);
|
|
|
|
|
|
|
|
r = file_of_uid(uid, &p);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r = parse_env_file(p, NEWLINE, "DISPLAY", &s, NULL);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
if (isempty(s))
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
*session = s;
|
|
|
|
s = NULL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-07-22 21:01:15 +02:00
|
|
|
_public_ int sd_uid_is_on_seat(uid_t uid, int require_active, const char *seat) {
|
2013-04-17 14:05:24 +02:00
|
|
|
char *w, *state;
|
|
|
|
_cleanup_free_ char *t = NULL, *s = NULL, *p = NULL;
|
2011-07-14 22:50:01 +02:00
|
|
|
size_t l;
|
|
|
|
int r;
|
2011-07-22 21:01:15 +02:00
|
|
|
const char *variable;
|
2011-07-14 22:50:01 +02:00
|
|
|
|
2013-12-02 22:42:01 +01:00
|
|
|
assert_return(seat, -EINVAL);
|
2011-07-14 22:50:01 +02:00
|
|
|
|
2011-07-22 21:01:15 +02:00
|
|
|
variable = require_active ? "ACTIVE_UID" : "UIDS";
|
|
|
|
|
2011-07-14 22:50:01 +02:00
|
|
|
p = strappend("/run/systemd/seats/", seat);
|
|
|
|
if (!p)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2011-07-22 21:01:15 +02:00
|
|
|
r = parse_env_file(p, NEWLINE, variable, &s, NULL);
|
2011-07-14 22:50:01 +02:00
|
|
|
|
2013-04-17 14:05:24 +02:00
|
|
|
if (r < 0)
|
2011-07-14 22:50:01 +02:00
|
|
|
return r;
|
|
|
|
|
|
|
|
if (!s)
|
|
|
|
return -EIO;
|
|
|
|
|
2014-04-25 13:45:15 +02:00
|
|
|
if (asprintf(&t, UID_FMT, uid) < 0)
|
2011-07-14 22:50:01 +02:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
FOREACH_WORD(w, l, s, state) {
|
2013-04-17 14:05:24 +02:00
|
|
|
if (strneq(t, w, l))
|
2011-07-14 22:50:01 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-07-22 21:01:15 +02:00
|
|
|
static int uid_get_array(uid_t uid, const char *variable, char ***array) {
|
2013-04-17 14:05:24 +02:00
|
|
|
_cleanup_free_ char *p = NULL, *s = NULL;
|
2011-07-22 21:01:15 +02:00
|
|
|
char **a;
|
|
|
|
int r;
|
|
|
|
|
2014-05-19 02:33:20 +02:00
|
|
|
r = file_of_uid(uid, &p);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2011-07-22 21:01:15 +02:00
|
|
|
|
|
|
|
r = parse_env_file(p, NEWLINE,
|
|
|
|
variable, &s,
|
|
|
|
NULL);
|
|
|
|
if (r < 0) {
|
|
|
|
if (r == -ENOENT) {
|
2011-07-29 03:08:49 +02:00
|
|
|
if (array)
|
|
|
|
*array = NULL;
|
2011-07-22 21:01:15 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!s) {
|
2011-07-29 03:08:49 +02:00
|
|
|
if (array)
|
|
|
|
*array = NULL;
|
2011-07-22 21:01:15 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
a = strv_split(s, " ");
|
|
|
|
|
|
|
|
if (!a)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2011-07-29 03:08:49 +02:00
|
|
|
strv_uniq(a);
|
|
|
|
r = strv_length(a);
|
|
|
|
|
|
|
|
if (array)
|
|
|
|
*array = a;
|
|
|
|
else
|
|
|
|
strv_free(a);
|
|
|
|
|
|
|
|
return r;
|
2011-07-22 21:01:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
_public_ int sd_uid_get_sessions(uid_t uid, int require_active, char ***sessions) {
|
2012-09-12 08:30:35 +02:00
|
|
|
return uid_get_array(
|
|
|
|
uid,
|
|
|
|
require_active == 0 ? "ONLINE_SESSIONS" :
|
|
|
|
require_active > 0 ? "ACTIVE_SESSIONS" :
|
|
|
|
"SESSIONS",
|
|
|
|
sessions);
|
2011-07-14 22:50:01 +02:00
|
|
|
}
|
|
|
|
|
2011-07-22 21:01:15 +02:00
|
|
|
_public_ int sd_uid_get_seats(uid_t uid, int require_active, char ***seats) {
|
2012-09-12 08:30:35 +02:00
|
|
|
return uid_get_array(
|
|
|
|
uid,
|
|
|
|
require_active == 0 ? "ONLINE_SEATS" :
|
|
|
|
require_active > 0 ? "ACTIVE_SEATS" :
|
|
|
|
"SEATS",
|
|
|
|
seats);
|
2011-07-14 22:50:01 +02:00
|
|
|
}
|
|
|
|
|
2012-02-11 03:45:23 +01:00
|
|
|
static int file_of_session(const char *session, char **_p) {
|
|
|
|
char *p;
|
2011-07-14 22:50:01 +02:00
|
|
|
int r;
|
|
|
|
|
2012-02-11 03:45:23 +01:00
|
|
|
assert(_p);
|
|
|
|
|
2013-09-16 04:26:56 +02:00
|
|
|
if (session) {
|
|
|
|
if (!session_id_valid(session))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2012-02-11 03:45:23 +01:00
|
|
|
p = strappend("/run/systemd/sessions/", session);
|
2013-09-16 04:26:56 +02:00
|
|
|
} else {
|
|
|
|
_cleanup_free_ char *buf = NULL;
|
2012-02-11 03:45:23 +01:00
|
|
|
|
|
|
|
r = sd_pid_get_session(0, &buf);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
p = strappend("/run/systemd/sessions/", buf);
|
|
|
|
}
|
2011-07-14 22:50:01 +02:00
|
|
|
|
|
|
|
if (!p)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2012-02-11 03:45:23 +01:00
|
|
|
*_p = p;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
_public_ int sd_session_is_active(const char *session) {
|
|
|
|
int r;
|
2013-04-17 14:05:24 +02:00
|
|
|
_cleanup_free_ char *p = NULL, *s = NULL;
|
2012-02-11 03:45:23 +01:00
|
|
|
|
|
|
|
r = file_of_session(session, &p);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
2011-07-14 22:50:01 +02:00
|
|
|
r = parse_env_file(p, NEWLINE, "ACTIVE", &s, NULL);
|
2013-04-17 14:05:24 +02:00
|
|
|
if (r < 0)
|
2011-07-14 22:50:01 +02:00
|
|
|
return r;
|
|
|
|
|
|
|
|
if (!s)
|
|
|
|
return -EIO;
|
|
|
|
|
2014-03-12 20:54:29 +01:00
|
|
|
return parse_boolean(s);
|
2011-07-14 22:50:01 +02:00
|
|
|
}
|
|
|
|
|
2013-12-22 01:48:46 +01:00
|
|
|
_public_ int sd_session_is_remote(const char *session) {
|
|
|
|
int r;
|
|
|
|
_cleanup_free_ char *p = NULL, *s = NULL;
|
|
|
|
|
|
|
|
r = file_of_session(session, &p);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r = parse_env_file(p, NEWLINE, "REMOTE", &s, NULL);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
if (!s)
|
|
|
|
return -EIO;
|
|
|
|
|
2014-03-12 20:54:29 +01:00
|
|
|
return parse_boolean(s);
|
2013-12-22 01:48:46 +01:00
|
|
|
}
|
|
|
|
|
2012-06-21 16:14:53 +02:00
|
|
|
_public_ int sd_session_get_state(const char *session, char **state) {
|
2013-04-17 14:05:24 +02:00
|
|
|
_cleanup_free_ char *p = NULL, *s = NULL;
|
2012-06-21 16:14:53 +02:00
|
|
|
int r;
|
|
|
|
|
2013-12-02 22:42:01 +01:00
|
|
|
assert_return(state, -EINVAL);
|
2012-06-21 16:14:53 +02:00
|
|
|
|
|
|
|
r = file_of_session(session, &p);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r = parse_env_file(p, NEWLINE, "STATE", &s, NULL);
|
2013-04-17 14:05:24 +02:00
|
|
|
if (r < 0)
|
2012-06-21 16:14:53 +02:00
|
|
|
return r;
|
2013-04-17 14:05:24 +02:00
|
|
|
else if (!s)
|
2012-06-21 16:14:53 +02:00
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
*state = s;
|
2013-04-17 14:05:24 +02:00
|
|
|
s = NULL;
|
|
|
|
|
2012-06-21 16:14:53 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-07-14 22:50:01 +02:00
|
|
|
_public_ int sd_session_get_uid(const char *session, uid_t *uid) {
|
|
|
|
int r;
|
2013-04-17 14:05:24 +02:00
|
|
|
_cleanup_free_ char *p = NULL, *s = NULL;
|
2011-07-14 22:50:01 +02:00
|
|
|
|
2013-12-02 22:42:01 +01:00
|
|
|
assert_return(uid, -EINVAL);
|
2011-07-14 22:50:01 +02:00
|
|
|
|
2012-02-11 03:45:23 +01:00
|
|
|
r = file_of_session(session, &p);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2011-07-14 22:50:01 +02:00
|
|
|
|
|
|
|
r = parse_env_file(p, NEWLINE, "UID", &s, NULL);
|
2013-04-17 14:05:24 +02:00
|
|
|
if (r < 0)
|
2011-07-14 22:50:01 +02:00
|
|
|
return r;
|
|
|
|
|
|
|
|
if (!s)
|
|
|
|
return -EIO;
|
|
|
|
|
2014-03-12 20:54:29 +01:00
|
|
|
return parse_uid(s, uid);
|
2011-07-14 22:50:01 +02:00
|
|
|
}
|
|
|
|
|
2012-02-14 21:54:00 +01:00
|
|
|
static int session_get_string(const char *session, const char *field, char **value) {
|
2013-04-17 14:05:24 +02:00
|
|
|
_cleanup_free_ char *p = NULL, *s = NULL;
|
2011-07-14 22:50:01 +02:00
|
|
|
int r;
|
|
|
|
|
2013-12-02 22:42:01 +01:00
|
|
|
assert_return(value, -EINVAL);
|
2011-07-14 22:50:01 +02:00
|
|
|
|
2012-02-11 03:45:23 +01:00
|
|
|
r = file_of_session(session, &p);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2011-07-14 22:50:01 +02:00
|
|
|
|
2012-02-14 21:54:00 +01:00
|
|
|
r = parse_env_file(p, NEWLINE, field, &s, NULL);
|
2013-04-17 14:05:24 +02:00
|
|
|
if (r < 0)
|
2011-07-14 22:50:01 +02:00
|
|
|
return r;
|
|
|
|
|
|
|
|
if (isempty(s))
|
|
|
|
return -ENOENT;
|
|
|
|
|
2012-02-14 21:54:00 +01:00
|
|
|
*value = s;
|
2013-04-17 14:05:24 +02:00
|
|
|
s = NULL;
|
2011-07-14 22:50:01 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-14 21:54:00 +01:00
|
|
|
_public_ int sd_session_get_seat(const char *session, char **seat) {
|
|
|
|
return session_get_string(session, "SEAT", seat);
|
|
|
|
}
|
2012-01-05 23:14:22 +01:00
|
|
|
|
2013-01-15 03:00:33 +01:00
|
|
|
_public_ int sd_session_get_tty(const char *session, char **tty) {
|
|
|
|
return session_get_string(session, "TTY", tty);
|
|
|
|
}
|
|
|
|
|
2013-09-11 18:48:20 +02:00
|
|
|
_public_ int sd_session_get_vt(const char *session, unsigned *vtnr) {
|
2013-10-10 13:09:37 +02:00
|
|
|
_cleanup_free_ char *vtnr_string = NULL;
|
2013-09-11 18:48:20 +02:00
|
|
|
unsigned u;
|
|
|
|
int r;
|
|
|
|
|
2013-10-10 13:11:27 +02:00
|
|
|
r = session_get_string(session, "VTNR", &vtnr_string);
|
2013-09-11 18:48:20 +02:00
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r = safe_atou(vtnr_string, &u);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
*vtnr = u;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-14 21:54:00 +01:00
|
|
|
_public_ int sd_session_get_service(const char *session, char **service) {
|
|
|
|
return session_get_string(session, "SERVICE", service);
|
|
|
|
}
|
2012-01-05 23:14:22 +01:00
|
|
|
|
2012-02-14 21:54:00 +01:00
|
|
|
_public_ int sd_session_get_type(const char *session, char **type) {
|
|
|
|
return session_get_string(session, "TYPE", type);
|
|
|
|
}
|
2012-01-05 23:14:22 +01:00
|
|
|
|
2012-02-14 21:54:00 +01:00
|
|
|
_public_ int sd_session_get_class(const char *session, char **class) {
|
|
|
|
return session_get_string(session, "CLASS", class);
|
2012-01-05 23:14:22 +01:00
|
|
|
}
|
|
|
|
|
2012-02-15 04:56:10 +01:00
|
|
|
_public_ int sd_session_get_display(const char *session, char **display) {
|
|
|
|
return session_get_string(session, "DISPLAY", display);
|
|
|
|
}
|
|
|
|
|
2013-12-22 01:48:46 +01:00
|
|
|
_public_ int sd_session_get_remote_user(const char *session, char **remote_user) {
|
|
|
|
return session_get_string(session, "REMOTE_USER", remote_user);
|
|
|
|
}
|
|
|
|
|
|
|
|
_public_ int sd_session_get_remote_host(const char *session, char **remote_host) {
|
|
|
|
return session_get_string(session, "REMOTE_HOST", remote_host);
|
|
|
|
}
|
|
|
|
|
2012-02-11 03:45:23 +01:00
|
|
|
static int file_of_seat(const char *seat, char **_p) {
|
|
|
|
char *p;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(_p);
|
|
|
|
|
|
|
|
if (seat)
|
|
|
|
p = strappend("/run/systemd/seats/", seat);
|
|
|
|
else {
|
2013-04-17 14:05:24 +02:00
|
|
|
_cleanup_free_ char *buf = NULL;
|
2012-02-11 03:45:23 +01:00
|
|
|
|
|
|
|
r = sd_session_get_seat(NULL, &buf);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
p = strappend("/run/systemd/seats/", buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!p)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
*_p = p;
|
2013-04-17 14:05:24 +02:00
|
|
|
p = NULL;
|
2012-02-11 03:45:23 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-07-14 22:50:01 +02:00
|
|
|
_public_ int sd_seat_get_active(const char *seat, char **session, uid_t *uid) {
|
2013-04-17 14:05:24 +02:00
|
|
|
_cleanup_free_ char *p = NULL, *s = NULL, *t = NULL;
|
2011-07-14 22:50:01 +02:00
|
|
|
int r;
|
|
|
|
|
2013-12-02 22:42:01 +01:00
|
|
|
assert_return(session || uid, -EINVAL);
|
2011-07-14 22:50:01 +02:00
|
|
|
|
2012-02-11 03:45:23 +01:00
|
|
|
r = file_of_seat(seat, &p);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2011-07-14 22:50:01 +02:00
|
|
|
|
|
|
|
r = parse_env_file(p, NEWLINE,
|
|
|
|
"ACTIVE", &s,
|
|
|
|
"ACTIVE_UID", &t,
|
|
|
|
NULL);
|
2013-04-17 14:05:24 +02:00
|
|
|
if (r < 0)
|
2011-07-14 22:50:01 +02:00
|
|
|
return r;
|
|
|
|
|
2013-04-17 14:05:24 +02:00
|
|
|
if (session && !s)
|
2011-07-22 21:01:15 +02:00
|
|
|
return -ENOENT;
|
2011-07-14 22:50:01 +02:00
|
|
|
|
2013-04-17 14:05:24 +02:00
|
|
|
if (uid && !t)
|
2011-07-22 21:01:15 +02:00
|
|
|
return -ENOENT;
|
2011-07-14 22:50:01 +02:00
|
|
|
|
|
|
|
if (uid && t) {
|
2011-07-22 21:01:15 +02:00
|
|
|
r = parse_uid(t, uid);
|
2013-04-17 14:05:24 +02:00
|
|
|
if (r < 0)
|
2011-07-14 22:50:01 +02:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2013-04-17 14:05:24 +02:00
|
|
|
if (session && s) {
|
2011-07-14 22:50:01 +02:00
|
|
|
*session = s;
|
2013-04-17 14:05:24 +02:00
|
|
|
s = NULL;
|
|
|
|
}
|
2011-07-14 22:50:01 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2011-07-22 21:01:15 +02:00
|
|
|
|
|
|
|
_public_ int sd_seat_get_sessions(const char *seat, char ***sessions, uid_t **uids, unsigned *n_uids) {
|
2013-04-17 14:05:24 +02:00
|
|
|
_cleanup_free_ char *p = NULL, *s = NULL, *t = NULL;
|
|
|
|
_cleanup_strv_free_ char **a = NULL;
|
|
|
|
_cleanup_free_ uid_t *b = NULL;
|
2011-07-22 21:01:15 +02:00
|
|
|
unsigned n = 0;
|
|
|
|
int r;
|
|
|
|
|
2012-02-11 03:45:23 +01:00
|
|
|
r = file_of_seat(seat, &p);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2011-07-22 21:01:15 +02:00
|
|
|
|
|
|
|
r = parse_env_file(p, NEWLINE,
|
|
|
|
"SESSIONS", &s,
|
|
|
|
"ACTIVE_SESSIONS", &t,
|
|
|
|
NULL);
|
|
|
|
|
2013-04-17 14:05:24 +02:00
|
|
|
if (r < 0)
|
2011-07-22 21:01:15 +02:00
|
|
|
return r;
|
|
|
|
|
2011-07-29 03:08:49 +02:00
|
|
|
if (s) {
|
2011-07-22 21:01:15 +02:00
|
|
|
a = strv_split(s, " ");
|
2013-04-17 14:05:24 +02:00
|
|
|
if (!a)
|
2011-07-22 21:01:15 +02:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (uids && t) {
|
|
|
|
char *w, *state;
|
|
|
|
size_t l;
|
|
|
|
|
|
|
|
FOREACH_WORD(w, l, t, state)
|
|
|
|
n++;
|
|
|
|
|
2013-04-17 14:05:24 +02:00
|
|
|
if (n > 0) {
|
2011-09-23 02:39:28 +02:00
|
|
|
unsigned i = 0;
|
2011-07-22 21:01:15 +02:00
|
|
|
|
2011-09-23 02:39:28 +02:00
|
|
|
b = new(uid_t, n);
|
2013-04-17 14:05:24 +02:00
|
|
|
if (!b)
|
2011-07-22 21:01:15 +02:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2011-09-23 02:39:28 +02:00
|
|
|
FOREACH_WORD(w, l, t, state) {
|
2013-04-17 14:05:24 +02:00
|
|
|
_cleanup_free_ char *k = NULL;
|
2011-07-22 21:01:15 +02:00
|
|
|
|
2011-09-23 02:39:28 +02:00
|
|
|
k = strndup(w, l);
|
2013-04-17 14:05:24 +02:00
|
|
|
if (!k)
|
2011-09-23 02:39:28 +02:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
r = parse_uid(k, b + i);
|
2013-04-17 14:05:24 +02:00
|
|
|
|
2011-09-23 02:39:28 +02:00
|
|
|
if (r < 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
2011-07-22 21:01:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-29 03:08:49 +02:00
|
|
|
r = strv_length(a);
|
|
|
|
|
2013-04-17 14:05:24 +02:00
|
|
|
if (sessions) {
|
2011-07-22 21:01:15 +02:00
|
|
|
*sessions = a;
|
2013-04-17 14:05:24 +02:00
|
|
|
a = NULL;
|
|
|
|
}
|
2011-07-22 21:01:15 +02:00
|
|
|
|
2013-04-17 14:05:24 +02:00
|
|
|
if (uids) {
|
2011-07-22 21:01:15 +02:00
|
|
|
*uids = b;
|
2013-04-17 14:05:24 +02:00
|
|
|
b = NULL;
|
|
|
|
}
|
2011-07-22 21:01:15 +02:00
|
|
|
|
|
|
|
if (n_uids)
|
|
|
|
*n_uids = n;
|
|
|
|
|
2011-07-29 03:08:49 +02:00
|
|
|
return r;
|
2011-07-22 21:01:15 +02:00
|
|
|
}
|
|
|
|
|
2012-06-21 16:52:54 +02:00
|
|
|
static int seat_get_can(const char *seat, const char *variable) {
|
2013-04-17 14:05:24 +02:00
|
|
|
_cleanup_free_ char *p = NULL, *s = NULL;
|
2011-07-26 23:09:09 +02:00
|
|
|
int r;
|
|
|
|
|
2014-03-12 20:54:29 +01:00
|
|
|
assert_return(variable, -EINVAL);
|
|
|
|
|
2012-02-11 03:45:23 +01:00
|
|
|
r = file_of_seat(seat, &p);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2011-07-26 23:09:09 +02:00
|
|
|
|
|
|
|
r = parse_env_file(p, NEWLINE,
|
2012-06-21 16:52:54 +02:00
|
|
|
variable, &s,
|
2011-07-26 23:09:09 +02:00
|
|
|
NULL);
|
2013-04-17 14:05:24 +02:00
|
|
|
if (r < 0)
|
2011-07-26 23:09:09 +02:00
|
|
|
return r;
|
2014-03-12 20:54:29 +01:00
|
|
|
if (!s)
|
|
|
|
return 0;
|
2011-07-26 23:09:09 +02:00
|
|
|
|
2014-03-12 20:54:29 +01:00
|
|
|
return parse_boolean(s);
|
2011-07-26 23:09:09 +02:00
|
|
|
}
|
|
|
|
|
2012-06-21 16:52:54 +02:00
|
|
|
_public_ int sd_seat_can_multi_session(const char *seat) {
|
|
|
|
return seat_get_can(seat, "CAN_MULTI_SESSION");
|
|
|
|
}
|
|
|
|
|
|
|
|
_public_ int sd_seat_can_tty(const char *seat) {
|
|
|
|
return seat_get_can(seat, "CAN_TTY");
|
|
|
|
}
|
|
|
|
|
|
|
|
_public_ int sd_seat_can_graphical(const char *seat) {
|
|
|
|
return seat_get_can(seat, "CAN_GRAPHICAL");
|
|
|
|
}
|
|
|
|
|
2011-07-22 21:01:15 +02:00
|
|
|
_public_ int sd_get_seats(char ***seats) {
|
|
|
|
return get_files_in_directory("/run/systemd/seats/", seats);
|
|
|
|
}
|
|
|
|
|
|
|
|
_public_ int sd_get_sessions(char ***sessions) {
|
|
|
|
return get_files_in_directory("/run/systemd/sessions/", sessions);
|
|
|
|
}
|
|
|
|
|
|
|
|
_public_ int sd_get_uids(uid_t **users) {
|
2013-04-17 14:05:24 +02:00
|
|
|
_cleanup_closedir_ DIR *d;
|
2011-07-22 21:01:15 +02:00
|
|
|
int r = 0;
|
|
|
|
unsigned n = 0;
|
2013-04-17 14:05:24 +02:00
|
|
|
_cleanup_free_ uid_t *l = NULL;
|
2011-07-22 21:01:15 +02:00
|
|
|
|
|
|
|
d = opendir("/run/systemd/users/");
|
2011-09-23 01:43:28 +02:00
|
|
|
if (!d)
|
|
|
|
return -errno;
|
|
|
|
|
2011-07-22 21:01:15 +02:00
|
|
|
for (;;) {
|
2012-09-19 22:21:09 +02:00
|
|
|
struct dirent *de;
|
2011-07-22 21:01:15 +02:00
|
|
|
int k;
|
|
|
|
uid_t uid;
|
|
|
|
|
2013-12-19 11:14:09 +01:00
|
|
|
errno = 0;
|
|
|
|
de = readdir(d);
|
|
|
|
if (!de && errno != 0)
|
|
|
|
return -errno;
|
2011-07-22 21:01:15 +02:00
|
|
|
|
|
|
|
if (!de)
|
|
|
|
break;
|
|
|
|
|
|
|
|
dirent_ensure_type(d, de);
|
|
|
|
|
|
|
|
if (!dirent_is_file(de))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
k = parse_uid(de->d_name, &uid);
|
|
|
|
if (k < 0)
|
|
|
|
continue;
|
|
|
|
|
2011-07-29 03:08:49 +02:00
|
|
|
if (users) {
|
|
|
|
if ((unsigned) r >= n) {
|
|
|
|
uid_t *t;
|
2011-07-22 21:01:15 +02:00
|
|
|
|
2011-07-29 03:08:49 +02:00
|
|
|
n = MAX(16, 2*r);
|
|
|
|
t = realloc(l, sizeof(uid_t) * n);
|
2013-04-17 14:05:24 +02:00
|
|
|
if (!t)
|
|
|
|
return -ENOMEM;
|
2011-07-22 21:01:15 +02:00
|
|
|
|
2011-07-29 03:08:49 +02:00
|
|
|
l = t;
|
|
|
|
}
|
2011-07-22 21:01:15 +02:00
|
|
|
|
2011-07-29 03:08:49 +02:00
|
|
|
assert((unsigned) r < n);
|
|
|
|
l[r++] = uid;
|
|
|
|
} else
|
|
|
|
r++;
|
2011-07-22 21:01:15 +02:00
|
|
|
}
|
|
|
|
|
2013-04-17 14:05:24 +02:00
|
|
|
if (users) {
|
|
|
|
*users = l;
|
|
|
|
l = NULL;
|
|
|
|
}
|
2011-07-22 21:01:15 +02:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2013-05-07 12:47:30 +02:00
|
|
|
_public_ int sd_get_machine_names(char ***machines) {
|
2014-02-11 17:15:38 +01:00
|
|
|
char **l = NULL, **a, **b;
|
|
|
|
int r;
|
|
|
|
|
2014-03-12 20:54:29 +01:00
|
|
|
assert_return(machines, -EINVAL);
|
|
|
|
|
2014-02-11 17:15:38 +01:00
|
|
|
r = get_files_in_directory("/run/systemd/machines/", &l);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
if (l) {
|
|
|
|
r = 0;
|
|
|
|
|
|
|
|
/* Filter out the unit: symlinks */
|
|
|
|
for (a = l, b = l; *a; a++) {
|
|
|
|
if (startswith(*a, "unit:"))
|
|
|
|
free(*a);
|
|
|
|
else {
|
|
|
|
*b = *a;
|
|
|
|
b++;
|
|
|
|
r++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*b = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*machines = l;
|
|
|
|
return r;
|
2013-04-24 22:54:17 +02:00
|
|
|
}
|
|
|
|
|
2014-03-12 20:54:29 +01:00
|
|
|
_public_ int sd_machine_get_class(const char *machine, char **class) {
|
|
|
|
_cleanup_free_ char *c = NULL;
|
|
|
|
const char *p;
|
|
|
|
int r;
|
|
|
|
|
2014-07-03 01:19:26 +02:00
|
|
|
assert_return(machine_name_is_valid(machine), -EINVAL);
|
2014-03-12 20:54:29 +01:00
|
|
|
assert_return(class, -EINVAL);
|
|
|
|
|
|
|
|
p = strappenda("/run/systemd/machines/", machine);
|
|
|
|
r = parse_env_file(p, NEWLINE, "CLASS", &c, NULL);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
if (!c)
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
*class = c;
|
|
|
|
c = NULL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-07-11 03:15:21 +02:00
|
|
|
_public_ int sd_machine_get_ifindexes(const char *machine, int **ifindexes) {
|
|
|
|
_cleanup_free_ char *netif = NULL;
|
|
|
|
size_t l, allocated = 0, nr = 0;
|
|
|
|
char *w, *state;
|
|
|
|
int *ni = NULL;
|
|
|
|
const char *p;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
assert_return(machine_name_is_valid(machine), -EINVAL);
|
|
|
|
assert_return(ifindexes, -EINVAL);
|
|
|
|
|
|
|
|
p = strappenda("/run/systemd/machines/", machine);
|
|
|
|
r = parse_env_file(p, NEWLINE, "NETIF", &netif, NULL);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
if (!netif) {
|
|
|
|
*ifindexes = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
FOREACH_WORD(w, l, netif, state) {
|
|
|
|
char buf[l+1];
|
|
|
|
int ifi;
|
|
|
|
|
|
|
|
*(char*) (mempcpy(buf, w, l)) = 0;
|
|
|
|
|
|
|
|
if (safe_atoi(buf, &ifi) < 0)
|
|
|
|
continue;
|
|
|
|
if (ifi <= 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!GREEDY_REALLOC(ni, allocated, nr+1)) {
|
|
|
|
free(ni);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
ni[nr++] = ifi;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ifindexes = ni;
|
|
|
|
return nr;
|
|
|
|
}
|
|
|
|
|
2011-07-22 21:01:15 +02:00
|
|
|
static inline int MONITOR_TO_FD(sd_login_monitor *m) {
|
|
|
|
return (int) (unsigned long) m - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline sd_login_monitor* FD_TO_MONITOR(int fd) {
|
|
|
|
return (sd_login_monitor*) (unsigned long) (fd + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
_public_ int sd_login_monitor_new(const char *category, sd_login_monitor **m) {
|
|
|
|
int fd, k;
|
|
|
|
bool good = false;
|
|
|
|
|
2013-12-02 22:42:01 +01:00
|
|
|
assert_return(m, -EINVAL);
|
2011-07-22 21:01:15 +02:00
|
|
|
|
|
|
|
fd = inotify_init1(IN_NONBLOCK|IN_CLOEXEC);
|
|
|
|
if (fd < 0)
|
2013-04-12 00:57:42 +02:00
|
|
|
return -errno;
|
2011-07-22 21:01:15 +02:00
|
|
|
|
|
|
|
if (!category || streq(category, "seat")) {
|
|
|
|
k = inotify_add_watch(fd, "/run/systemd/seats/", IN_MOVED_TO|IN_DELETE);
|
|
|
|
if (k < 0) {
|
2014-03-18 19:22:43 +01:00
|
|
|
safe_close(fd);
|
2011-07-22 21:01:15 +02:00
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
good = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!category || streq(category, "session")) {
|
|
|
|
k = inotify_add_watch(fd, "/run/systemd/sessions/", IN_MOVED_TO|IN_DELETE);
|
|
|
|
if (k < 0) {
|
2014-03-18 19:22:43 +01:00
|
|
|
safe_close(fd);
|
2011-07-22 21:01:15 +02:00
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
good = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!category || streq(category, "uid")) {
|
|
|
|
k = inotify_add_watch(fd, "/run/systemd/users/", IN_MOVED_TO|IN_DELETE);
|
|
|
|
if (k < 0) {
|
2014-03-18 19:22:43 +01:00
|
|
|
safe_close(fd);
|
2011-07-22 21:01:15 +02:00
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
good = true;
|
|
|
|
}
|
|
|
|
|
2013-04-24 22:54:55 +02:00
|
|
|
if (!category || streq(category, "machine")) {
|
2013-06-20 04:03:38 +02:00
|
|
|
k = inotify_add_watch(fd, "/run/systemd/machines/", IN_MOVED_TO|IN_DELETE);
|
2013-04-24 22:54:55 +02:00
|
|
|
if (k < 0) {
|
2014-03-18 19:22:43 +01:00
|
|
|
safe_close(fd);
|
2013-04-24 22:54:55 +02:00
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
good = true;
|
|
|
|
}
|
|
|
|
|
2011-07-22 21:01:15 +02:00
|
|
|
if (!good) {
|
|
|
|
close_nointr(fd);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*m = FD_TO_MONITOR(fd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
_public_ sd_login_monitor* sd_login_monitor_unref(sd_login_monitor *m) {
|
|
|
|
int fd;
|
|
|
|
|
2013-12-02 22:42:01 +01:00
|
|
|
assert_return(m, NULL);
|
2011-07-22 21:01:15 +02:00
|
|
|
|
|
|
|
fd = MONITOR_TO_FD(m);
|
|
|
|
close_nointr(fd);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
_public_ int sd_login_monitor_flush(sd_login_monitor *m) {
|
|
|
|
|
2013-12-02 22:42:01 +01:00
|
|
|
assert_return(m, -EINVAL);
|
2011-07-22 21:01:15 +02:00
|
|
|
|
|
|
|
return flush_fd(MONITOR_TO_FD(m));
|
|
|
|
}
|
|
|
|
|
|
|
|
_public_ int sd_login_monitor_get_fd(sd_login_monitor *m) {
|
|
|
|
|
2013-12-02 22:42:01 +01:00
|
|
|
assert_return(m, -EINVAL);
|
2011-07-22 21:01:15 +02:00
|
|
|
|
|
|
|
return MONITOR_TO_FD(m);
|
|
|
|
}
|
2013-04-04 17:38:08 +02:00
|
|
|
|
|
|
|
_public_ int sd_login_monitor_get_events(sd_login_monitor *m) {
|
|
|
|
|
2013-12-02 22:42:01 +01:00
|
|
|
assert_return(m, -EINVAL);
|
2013-04-04 17:38:08 +02:00
|
|
|
|
2013-04-04 18:31:22 +02:00
|
|
|
/* For now we will only return POLLIN here, since we don't
|
|
|
|
* need anything else ever for inotify. However, let's have
|
|
|
|
* this API to keep our options open should we later on need
|
|
|
|
* it. */
|
2013-04-04 17:38:08 +02:00
|
|
|
return POLLIN;
|
|
|
|
}
|
2013-04-04 18:31:22 +02:00
|
|
|
|
|
|
|
_public_ int sd_login_monitor_get_timeout(sd_login_monitor *m, uint64_t *timeout_usec) {
|
|
|
|
|
2013-12-02 22:42:01 +01:00
|
|
|
assert_return(m, -EINVAL);
|
|
|
|
assert_return(timeout_usec, -EINVAL);
|
2013-04-04 18:31:22 +02:00
|
|
|
|
|
|
|
/* For now we will only return (uint64_t) -1, since we don't
|
|
|
|
* need any timeout. However, let's have this API to keep our
|
|
|
|
* options open should we later on need it. */
|
|
|
|
*timeout_usec = (uint64_t) -1;
|
|
|
|
return 0;
|
|
|
|
}
|