diff options
author | Lennart Poettering <lennart@poettering.net> | 2011-07-22 21:01:15 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2011-07-22 21:01:15 +0200 |
commit | 034a2a52ac0ec83e0229941d635d310b23eb04df (patch) | |
tree | 37cca83098579cc56d30b1bab1a4c48134586796 /src/util.c | |
parent | bccc1d8859175f0927652d694796892c9e9c21d6 (diff) |
sd-login: beef up login api, to add monitoring and enumerating
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c index 328a1ead92..2d4f229193 100644 --- a/src/util.c +++ b/src/util.c @@ -317,6 +317,26 @@ int parse_pid(const char *s, pid_t* ret_pid) { return 0; } +int parse_uid(const char *s, uid_t* ret_uid) { + unsigned long ul = 0; + uid_t uid; + int r; + + assert(s); + assert(ret_uid); + + if ((r = safe_atolu(s, &ul)) < 0) + return r; + + uid = (uid_t) ul; + + if ((unsigned long) uid != ul) + return -ERANGE; + + *ret_uid = uid; + return 0; +} + int safe_atou(const char *s, unsigned *ret_u) { char *x = NULL; unsigned long l; @@ -5357,6 +5377,70 @@ int in_search_path(const char *path, char **search) { return r; } +int get_files_in_directory(const char *path, char ***list) { + DIR *d; + int r = 0; + unsigned n = 0; + char **l = NULL; + + assert(path); + assert(list); + + d = opendir(path); + for (;;) { + struct dirent buffer, *de; + int k; + + k = readdir_r(d, &buffer, &de); + if (k != 0) { + r = -k; + goto finish; + } + + if (!de) + break; + + dirent_ensure_type(d, de); + + if (!dirent_is_file(de)) + continue; + + if ((unsigned) r >= n) { + char **t; + + n = MAX(16, 2*r); + t = realloc(l, sizeof(char*) * n); + if (!t) { + r = -ENOMEM; + goto finish; + } + + l = t; + } + + assert((unsigned) r < n); + + l[r] = strdup(de->d_name); + if (!l[r]) { + r = -ENOMEM; + goto finish; + } + + l[++r] = NULL; + } + +finish: + if (d) + closedir(d); + + if (r >= 0) + *list = l; + else + strv_free(l); + + return r; +} + static const char *const ioprio_class_table[] = { [IOPRIO_CLASS_NONE] = "none", [IOPRIO_CLASS_RT] = "realtime", |