-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
/***
This file is part of systemd.
#include "escape.h"
#include "fd-util.h"
#include "fileio.h"
-#include "formats-util.h"
+#include "format-util.h"
#include "fs-util.h"
#include "hostname-util.h"
#include "io-util.h"
*/
_public_ int sd_pid_get_session(pid_t pid, char **session) {
+ int r;
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) {
+#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
- 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) {
+#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
- 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) {
+#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
- 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) {
+#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
- 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) {
+#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
- 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) {
+#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
- 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
/* 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 ambigious for people to grok. */
+ * that's easier and less ambiguous for people to grok. */
if (isempty(c)) {
free(c);
c = strdup("/");
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;
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;
r = parse_env_file(p, NEWLINE,
"SESSIONS", &s,
- "ACTIVE_SESSIONS", &t,
+ "UIDS", &t,
NULL);
if (r == -ENOENT)
return -ENXIO;
r = parse_uid(k, b + i);
if (r < 0)
- continue;
+ return r;
i++;
}
}
_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) {
- 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;
+ struct dirent *de;
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;
+ }
- for (;;) {
- struct dirent *de;
+ FOREACH_DIRENT_ALL(de, d, return -errno) {
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))
}
_public_ int sd_get_machine_names(char ***machines) {
- char **l = NULL, **a, **b;
+ _cleanup_strv_free_ char **l = NULL;
+ char **a, **b;
int r;
- assert_return(machines, -EINVAL);
-
r = get_files_in_directory("/run/systemd/machines/", &l);
+ if (r == -ENOENT) {
+ if (machines)
+ *machines = NULL;
+ return 0;
+ }
if (r < 0)
return r;
r = 0;
/* Filter out the unit: symlinks */
- for (a = l, b = l; *a; a++) {
+ for (a = b = l; *a; a++) {
if (startswith(*a, "unit:") || !machine_name_is_valid(*a))
free(*a);
else {
*b = NULL;
}
- *machines = l;
+ if (machines) {
+ *machines = l;
+ l = NULL;
+ }
return r;
}