_public_ int sd_uid_get_state(uid_t uid, char**state) { _cleanup_free_ char *p = NULL; char *s = NULL; int r; assert_return(state, -EINVAL); r = file_of_uid(uid, &p); if (r < 0) return r; 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; } if (isempty(s)) { free(s); return -EIO; } *state = s; return 0; }
static int uid_get_array(uid_t uid, const char *variable, char ***array) { _cleanup_free_ char *p = NULL, *s = NULL; char **a; int r; assert(variable); r = file_of_uid(uid, &p); if (r < 0) return r; r = parse_env_file(p, NEWLINE, variable, &s, NULL); if (r == -ENOENT || (r >= 0 && isempty(s))) { if (array) *array = NULL; return 0; } if (r < 0) return r; a = strv_split(s, " "); if (!a) return -ENOMEM; strv_uniq(a); r = strv_length(a); if (array) *array = a; else strv_free(a); return r; }
_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; }