char **a;
int r;
- if (!array)
- return -EINVAL;
-
if (asprintf(&p, "/run/systemd/users/%lu", (unsigned long) uid) < 0)
return -ENOMEM;
free(s);
if (r == -ENOENT) {
- *array = NULL;
+ if (array)
+ *array = NULL;
return 0;
}
}
if (!s) {
- *array = NULL;
+ if (array)
+ *array = NULL;
return 0;
}
if (!a)
return -ENOMEM;
- *array = a;
- return 0;
+ strv_uniq(a);
+ r = strv_length(a);
+
+ if (array)
+ *array = a;
+ else
+ strv_free(a);
+
+ return r;
}
_public_ int sd_uid_get_sessions(uid_t uid, int require_active, char ***sessions) {
if (!seat)
return -EINVAL;
- if (!sessions && !uids)
- return -EINVAL;
-
p = strappend("/run/systemd/seats/", seat);
if (!p)
return -ENOMEM;
return r;
}
- if (sessions && s) {
+ if (s) {
a = strv_split(s, " ");
if (!a) {
free(s);
free(t);
+ r = strv_length(a);
+
if (sessions)
*sessions = a;
+ else
+ strv_free(a);
if (uids)
*uids = b;
if (n_uids)
*n_uids = n;
- return 0;
+ return r;
}
-_public_ int sd_get_seats(char ***seats) {
+_public_ int sd_seat_can_multi_session(const char *seat) {
+ char *p, *s = NULL;
+ int r;
- if (!seats)
+ if (!seat)
return -EINVAL;
+ p = strappend("/run/systemd/seats/", seat);
+ if (!p)
+ return -ENOMEM;
+
+ r = parse_env_file(p, NEWLINE,
+ "IS_VTCONSOLE", &s,
+ NULL);
+ free(p);
+
+ if (r < 0) {
+ free(s);
+ return r;
+ }
+
+ if (s) {
+ r = parse_boolean(s);
+ free(s);
+ } else
+ r = 0;
+
+ return r;
+}
+
+_public_ int sd_get_seats(char ***seats) {
return get_files_in_directory("/run/systemd/seats/", seats);
}
_public_ int sd_get_sessions(char ***sessions) {
-
- if (!sessions)
- return -EINVAL;
-
return get_files_in_directory("/run/systemd/sessions/", sessions);
}
unsigned n = 0;
uid_t *l = NULL;
- if (!users)
- return -EINVAL;
-
d = opendir("/run/systemd/users/");
for (;;) {
struct dirent buffer, *de;
if (k < 0)
continue;
- if ((unsigned) r >= n) {
- uid_t *t;
+ if (users) {
+ if ((unsigned) r >= n) {
+ uid_t *t;
- n = MAX(16, 2*r);
- t = realloc(l, sizeof(uid_t) * n);
- if (!t) {
- r = -ENOMEM;
- goto finish;
- }
+ n = MAX(16, 2*r);
+ t = realloc(l, sizeof(uid_t) * n);
+ if (!t) {
+ r = -ENOMEM;
+ goto finish;
+ }
- l = t;
- }
+ l = t;
+ }
- assert((unsigned) r < n);
- l[r++] = uid;
+ assert((unsigned) r < n);
+ l[r++] = uid;
+ } else
+ r++;
}
finish:
if (d)
closedir(d);
- if (r >= 0)
- *users = l;
- else
+ if (r >= 0) {
+ if (users)
+ *users = l;
+ } else
free(l);
return r;