diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-01-14 22:37:56 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-01-14 23:18:33 +0100 |
commit | 805e5dda0a01c99d231824e1a9c4a208418bf342 (patch) | |
tree | a3d2ee682290de9b9458863b9bfea3efe3bdde5b /src | |
parent | b3fae863ef548add2d01c3956ce7720f4eeeca7e (diff) |
sysv-generator: always use fstatat() if we can
Diffstat (limited to 'src')
-rw-r--r-- | src/sysv-generator/sysv-generator.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/src/sysv-generator/sysv-generator.c b/src/sysv-generator/sysv-generator.c index 89c0e7c67d..4774981016 100644 --- a/src/sysv-generator/sysv-generator.c +++ b/src/sysv-generator/sysv-generator.c @@ -722,28 +722,33 @@ static int enumerate_sysv(LookupPaths lp, Hashmap *all_services) { } while ((de = readdir(d))) { - SysvStub *service; - struct stat st; _cleanup_free_ char *fpath = NULL, *name = NULL; + _cleanup_free_ SysvStub *service = NULL; + struct stat st; int r; if (hidden_file(de->d_name)) continue; - fpath = strjoin(*path, "/", de->d_name, NULL); - if (!fpath) - return log_oom(); - - if (stat(fpath, &st) < 0) + if (fstatat(dirfd(d), de->d_name, &st, 0) < 0) { + log_warning_errno(errno, "stat() failed on %s/%s: %m", *path, de->d_name); continue; + } if (!(st.st_mode & S_IXUSR)) continue; + if (!S_ISREG(st.st_mode)) + continue; + name = sysv_translate_name(de->d_name); if (!name) return log_oom(); + fpath = strjoin(*path, "/", de->d_name, NULL); + if (!fpath) + return log_oom(); + if (hashmap_contains(all_services, name)) continue; @@ -756,12 +761,11 @@ static int enumerate_sysv(LookupPaths lp, Hashmap *all_services) { service->path = fpath; r = hashmap_put(all_services, service->name, service); - if (r < 0) { - free(service); + if (r < 0) return log_oom(); - } name = fpath = NULL; + service = NULL; } } |