chiark / gitweb /
sysv-generator: there's really no need to invoke fstatat() multiple times on the...
authorLennart Poettering <lennart@poettering.net>
Wed, 28 Jan 2015 00:36:40 +0000 (01:36 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 28 Jan 2015 00:36:40 +0000 (01:36 +0100)
It's sufficient to check once if something is a regular file, hence,
let's do that.

src/sysv-generator/sysv-generator.c

index 984beab70ad397ed5760dd4e2cc00d64b3095c9d..09ade0dc3a308c4557f484e03a8cb7f2087f30d7 100644 (file)
@@ -749,12 +749,10 @@ static int enumerate_sysv(LookupPaths lp, Hashmap *all_services) {
                         struct stat st;
                         int r;
 
                         struct stat st;
                         int r;
 
-                        dirent_ensure_type(d, de);
-
-                        if (!dirent_is_file(de))
-                            continue;
+                        if (hidden_file(de->d_name))
+                                continue;
 
 
-                        if (fstatat(dirfd(d), de->d_name, &st, 0) < 0) {
+                        if (fstatat(dirfd(d), de->d_name, &st, AT_SYMLINK_NOFOLLOW) < 0) {
                                 log_warning_errno(errno, "stat() failed on %s/%s: %m", *path, de->d_name);
                                 continue;
                         }
                                 log_warning_errno(errno, "stat() failed on %s/%s: %m", *path, de->d_name);
                                 continue;
                         }
@@ -769,13 +767,13 @@ static int enumerate_sysv(LookupPaths lp, Hashmap *all_services) {
                         if (!name)
                                 return log_oom();
 
                         if (!name)
                                 return log_oom();
 
+                        if (hashmap_contains(all_services, name))
+                                continue;
+
                         fpath = strjoin(*path, "/", de->d_name, NULL);
                         if (!fpath)
                                 return log_oom();
 
                         fpath = strjoin(*path, "/", de->d_name, NULL);
                         if (!fpath)
                                 return log_oom();
 
-                        if (hashmap_contains(all_services, name))
-                                continue;
-
                         service = new0(SysvStub, 1);
                         if (!service)
                                 return log_oom();
                         service = new0(SysvStub, 1);
                         if (!service)
                                 return log_oom();