chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
sd-login: treat missing /run/elogind/{seats,sessions,users} the same as empty
[elogind.git]
/
src
/
libelogind
/
sd-login
/
sd-login.c
diff --git
a/src/libelogind/sd-login/sd-login.c
b/src/libelogind/sd-login/sd-login.c
index 9043ef1054ba53549b7ef6232e3c4676660b03a8..7630e6265334f3f7d60e4248bd0b728648650faa 100644
(file)
--- a/
src/libelogind/sd-login/sd-login.c
+++ b/
src/libelogind/sd-login/sd-login.c
@@
-1,5
+1,3
@@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
/***
This file is part of systemd.
/***
This file is part of systemd.
@@
-33,7
+31,7
@@
#include "escape.h"
#include "fd-util.h"
#include "fileio.h"
#include "escape.h"
#include "fd-util.h"
#include "fileio.h"
-#include "format
s
-util.h"
+#include "format-util.h"
#include "fs-util.h"
#include "hostname-util.h"
#include "io-util.h"
#include "fs-util.h"
#include "hostname-util.h"
#include "io-util.h"
@@
-58,80
+56,106
@@
*/
_public_ int sd_pid_get_session(pid_t pid, char **session) {
*/
_public_ int sd_pid_get_session(pid_t pid, char **session) {
+ int r;
assert_return(pid >= 0, -EINVAL);
assert_return(session, -EINVAL);
assert_return(pid >= 0, -EINVAL);
assert_return(session, -EINVAL);
- return cg_pid_get_session(pid, session);
+ r = cg_pid_get_session(pid, session);
+ return IN_SET(r, -ENXIO, -ENOMEDIUM) ? -ENODATA : r;
}
_public_ int sd_pid_get_unit(pid_t pid, char **unit) {
}
_public_ int sd_pid_get_unit(pid_t pid, char **unit) {
+#if 0 /// UNNEEDED by elogind
+ int r;
+#endif // 0
assert_return(pid >= 0, -EINVAL);
assert_return(unit, -EINVAL);
#if 0 /// elogind does not support systemd units
assert_return(pid >= 0, -EINVAL);
assert_return(unit, -EINVAL);
#if 0 /// elogind does not support systemd units
- return cg_pid_get_unit(pid, unit);
+ r = cg_pid_get_unit(pid, unit);
+ return IN_SET(r, -ENXIO, -ENOMEDIUM) ? -ENODATA : r;
#else
return -ESRCH;
#endif // 0
}
_public_ int sd_pid_get_user_unit(pid_t pid, char **unit) {
#else
return -ESRCH;
#endif // 0
}
_public_ int sd_pid_get_user_unit(pid_t pid, char **unit) {
+#if 0 /// UNNEEDED by elogind
+ int r;
+#endif // 0
assert_return(pid >= 0, -EINVAL);
assert_return(unit, -EINVAL);
#if 0 /// elogind does not support systemd units
assert_return(pid >= 0, -EINVAL);
assert_return(unit, -EINVAL);
#if 0 /// elogind does not support systemd units
- return cg_pid_get_user_unit(pid, unit);
+ r = cg_pid_get_user_unit(pid, unit);
+ return IN_SET(r, -ENXIO, -ENOMEDIUM) ? -ENODATA : r;
#else
return -ESRCH;
#endif // 0
}
_public_ int sd_pid_get_machine_name(pid_t pid, char **name) {
#else
return -ESRCH;
#endif // 0
}
_public_ int sd_pid_get_machine_name(pid_t pid, char **name) {
+#if 0 /// UNNEEDED by elogind
+ int r;
+#endif // 0
assert_return(pid >= 0, -EINVAL);
assert_return(name, -EINVAL);
#if 0 /// elogind does not support systemd units
assert_return(pid >= 0, -EINVAL);
assert_return(name, -EINVAL);
#if 0 /// elogind does not support systemd units
- return cg_pid_get_machine_name(pid, name);
+ r = cg_pid_get_machine_name(pid, name);
+ return IN_SET(r, -ENXIO, -ENOMEDIUM) ? -ENODATA : r;
#else
return -ESRCH;
#endif // 0
}
_public_ int sd_pid_get_slice(pid_t pid, char **slice) {
#else
return -ESRCH;
#endif // 0
}
_public_ int sd_pid_get_slice(pid_t pid, char **slice) {
+#if 0 /// UNNEEDED by elogind
+ int r;
+#endif // 0
assert_return(pid >= 0, -EINVAL);
assert_return(slice, -EINVAL);
#if 0 /// elogind does not support systemd slices
assert_return(pid >= 0, -EINVAL);
assert_return(slice, -EINVAL);
#if 0 /// elogind does not support systemd slices
- return cg_pid_get_slice(pid, slice);
+ r = cg_pid_get_slice(pid, slice);
+ return IN_SET(r, -ENXIO, -ENOMEDIUM) ? -ENODATA : r;
#else
return -ESRCH;
#endif // 0
}
_public_ int sd_pid_get_user_slice(pid_t pid, char **slice) {
#else
return -ESRCH;
#endif // 0
}
_public_ int sd_pid_get_user_slice(pid_t pid, char **slice) {
+#if 0 /// UNNEEDED by elogind
+ int r;
+#endif // 0
assert_return(pid >= 0, -EINVAL);
assert_return(slice, -EINVAL);
#if 0 /// elogind does not support systemd slices
assert_return(pid >= 0, -EINVAL);
assert_return(slice, -EINVAL);
#if 0 /// elogind does not support systemd slices
- return cg_pid_get_user_slice(pid, slice);
+ r = cg_pid_get_user_slice(pid, slice);
+ return IN_SET(r, -ENXIO, -ENOMEDIUM) ? -ENODATA : r;
#else
return -ESRCH;
#endif // 0
}
_public_ int sd_pid_get_owner_uid(pid_t pid, uid_t *uid) {
#else
return -ESRCH;
#endif // 0
}
_public_ int sd_pid_get_owner_uid(pid_t pid, uid_t *uid) {
+#if 0 /// UNNEEDED by elogind
+ int r;
+#endif // 0
assert_return(pid >= 0, -EINVAL);
assert_return(uid, -EINVAL);
#if 0 /// elogind does not support systemd slices
assert_return(pid >= 0, -EINVAL);
assert_return(uid, -EINVAL);
#if 0 /// elogind does not support systemd slices
- return cg_pid_get_owner_uid(pid, uid);
+ r = cg_pid_get_owner_uid(pid, uid);
+ return IN_SET(r, -ENXIO, -ENOMEDIUM) ? -ENODATA : r;
#else
return -ESRCH;
#endif // 0
#else
return -ESRCH;
#endif // 0
@@
-150,7
+174,7
@@
_public_ int sd_pid_get_cgroup(pid_t pid, char **cgroup) {
/* The internal APIs return the empty string for the root
* cgroup, let's return the "/" in the public APIs instead, as
/* The internal APIs return the empty string for the root
* cgroup, let's return the "/" in the public APIs instead, as
- * that's easier and less ambig
i
ous for people to grok. */
+ * that's easier and less ambig
u
ous for people to grok. */
if (isempty(c)) {
free(c);
c = strdup("/");
if (isempty(c)) {
free(c);
c = strdup("/");
@@
-380,7
+404,7
@@
static int file_of_seat(const char *seat, char **_p) {
if (!filename_is_valid(seat))
return -EINVAL;
if (!filename_is_valid(seat))
return -EINVAL;
- p = strappend("/run/systemd/seats/", seat);
+
p = strappend("/run/systemd/seats/", seat);
} else {
_cleanup_free_ char *buf = NULL;
} else {
_cleanup_free_ char *buf = NULL;
@@
-444,10
+468,10
@@
static int uid_get_array(uid_t uid, const char *variable, char ***array) {
r = parse_env_file(p, NEWLINE, variable, &s, NULL);
if (r == -ENOENT || (r >= 0 && isempty(s))) {
r = parse_env_file(p, NEWLINE, variable, &s, NULL);
if (r == -ENOENT || (r >= 0 && isempty(s))) {
-
if (array)
-
*array = NULL;
-
return 0;
-
}
+ if (array)
+ *array = NULL;
+ return 0;
+ }
if (r < 0)
return r;
if (r < 0)
return r;
@@
-741,7
+765,7
@@
_public_ int sd_seat_get_sessions(const char *seat, char ***sessions, uid_t **ui
r = parse_env_file(p, NEWLINE,
"SESSIONS", &s,
r = parse_env_file(p, NEWLINE,
"SESSIONS", &s,
- "
ACTIVE_SESSION
S", &t,
+ "
UID
S", &t,
NULL);
if (r == -ENOENT)
return -ENXIO;
NULL);
if (r == -ENOENT)
return -ENXIO;
@@
-777,7
+801,7
@@
_public_ int sd_seat_get_sessions(const char *seat, char ***sessions, uid_t **ui
r = parse_uid(k, b + i);
if (r < 0)
r = parse_uid(k, b + i);
if (r < 0)
-
continue
;
+
return r
;
i++;
}
i++;
}
@@
-838,36
+862,50
@@
_public_ int sd_seat_can_graphical(const char *seat) {
}
_public_ int sd_get_seats(char ***seats) {
}
_public_ int sd_get_seats(char ***seats) {
- return get_files_in_directory("/run/systemd/seats/", seats);
+ int r;
+
+ r = get_files_in_directory("/run/systemd/seats/", seats);
+ if (r == -ENOENT) {
+ if (seats)
+ *seats = NULL;
+ return 0;
+ }
+ return r;
}
_public_ int sd_get_sessions(char ***sessions) {
}
_public_ int sd_get_sessions(char ***sessions) {
- return get_files_in_directory("/run/systemd/sessions/", sessions);
+ int r;
+
+ r = get_files_in_directory("/run/systemd/sessions/", sessions);
+ if (r == -ENOENT) {
+ if (sessions)
+ *sessions = NULL;
+ return 0;
+ }
+ return r;
}
_public_ int sd_get_uids(uid_t **users) {
_cleanup_closedir_ DIR *d;
}
_public_ int sd_get_uids(uid_t **users) {
_cleanup_closedir_ DIR *d;
+ struct dirent *de;
int r = 0;
unsigned n = 0;
_cleanup_free_ uid_t *l = NULL;
d = opendir("/run/systemd/users/");
int r = 0;
unsigned n = 0;
_cleanup_free_ uid_t *l = NULL;
d = opendir("/run/systemd/users/");
- if (!d)
+ if (!d) {
+ if (errno == ENOENT) {
+ if (users)
+ *users = NULL;
+ return 0;
+ }
return -errno;
return -errno;
+ }
- for (;;) {
- struct dirent *de;
+ FOREACH_DIRENT_ALL(de, d, return -errno) {
int k;
uid_t uid;
int k;
uid_t uid;
- errno = 0;
- de = readdir(d);
- if (!de && errno != 0)
- return -errno;
-
- if (!de)
- break;
-
dirent_ensure_type(d, de);
if (!dirent_is_file(de))
dirent_ensure_type(d, de);
if (!dirent_is_file(de))
@@
-910,6
+948,10
@@
_public_ int sd_get_machine_names(char ***machines) {
assert_return(machines, -EINVAL);
r = get_files_in_directory("/run/systemd/machines/", &l);
assert_return(machines, -EINVAL);
r = get_files_in_directory("/run/systemd/machines/", &l);
+ if (r == -ENOENT) {
+ *machines = NULL;
+ return 0;
+ }
if (r < 0)
return r;
if (r < 0)
return r;