if (!s)
return -EIO;
- r = parse_boolean(s);
+ return parse_boolean(s);
+}
- return r;
+_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;
+
+ return parse_boolean(s);
}
_public_ int sd_session_get_state(const char *session, char **state) {
return r;
r = parse_env_file(p, NEWLINE, "UID", &s, NULL);
-
if (r < 0)
return r;
if (!s)
return -EIO;
- r = parse_uid(s, uid);
-
- return r;
+ return parse_uid(s, uid);
}
static int session_get_string(const char *session, const char *field, char **value) {
return session_get_string(session, "DISPLAY", display);
}
+_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);
+}
+
static int file_of_seat(const char *seat, char **_p) {
char *p;
int r;
_cleanup_free_ char *p = NULL, *s = NULL;
int r;
+ assert_return(variable, -EINVAL);
+
r = file_of_seat(seat, &p);
if (r < 0)
return r;
NULL);
if (r < 0)
return r;
+ if (!s)
+ return 0;
- if (s)
- r = parse_boolean(s);
- else
- r = 0;
-
- return r;
+ return parse_boolean(s);
}
_public_ int sd_seat_can_multi_session(const char *seat) {
for (;;) {
struct dirent *de;
- union dirent_storage buf;
int k;
uid_t uid;
- k = readdir_r(d, &buf.de, &de);
- if (k != 0)
- return -k;
+ errno = 0;
+ de = readdir(d);
+ if (!de && errno != 0)
+ return -errno;
if (!de)
break;
}
_public_ int sd_get_machine_names(char ***machines) {
- return get_files_in_directory("/run/systemd/machines/", machines);
+ char **l = NULL, **a, **b;
+ int r;
+
+ assert_return(machines, -EINVAL);
+
+ 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;
+}
+
+_public_ int sd_machine_get_class(const char *machine, char **class) {
+ _cleanup_free_ char *c = NULL;
+ const char *p;
+ int r;
+
+ assert_return(filename_is_safe(machine), -EINVAL);
+ 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;
}
static inline int MONITOR_TO_FD(sd_login_monitor *m) {