From cb3bc06f5ae4a9c3e706babd0a2c009058c0940f Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Mon, 19 Oct 2015 07:52:27 +0000 Subject: nlplug-findfs: use DT_UNKNOWN to detect if lstat is to be used --- nlplug-findfs.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'nlplug-findfs.c') diff --git a/nlplug-findfs.c b/nlplug-findfs.c index a016b23..ceaafab 100644 --- a/nlplug-findfs.c +++ b/nlplug-findfs.c @@ -265,7 +265,6 @@ struct recurse_opts { const char *searchname; void (*callback)(const char *, const void *); void *userdata; - int fastdir; /* avoid lstat on sysfs which we know support d_type */ }; /* pathbuf needs hold PATH_MAX chars */ @@ -278,7 +277,6 @@ void recurse_dir(char *pathbuf, struct recurse_opts *opts) return; while ((entry = readdir(d)) != NULL) { - struct stat st; size_t pathlen = strlen(pathbuf); size_t namelen = strlen(entry->d_name); int is_dir; @@ -293,19 +291,17 @@ void recurse_dir(char *pathbuf, struct recurse_opts *opts) pathbuf[pathlen] = '/'; strcpy(&pathbuf[pathlen+1], entry->d_name); - if (opts->fastdir) { - /* avoid the lstat syscall for sysfs which we know - support the d_type field. */ - is_dir = entry->d_type & DT_DIR; - } else { + if (entry->d_type == DT_UNKNOWN) { /* some filesystems like iso9660 does not support the d_type so we use lstat */ + struct stat st; if (lstat(pathbuf, &st) < 0) { dbg("%s: %s", pathbuf, strerror(errno)); goto next; } is_dir = S_ISDIR(st.st_mode); - } + else + is_dir = entry->d_type & DT_DIR; if (is_dir) { if (entry->d_name[0] == '.') @@ -387,7 +383,6 @@ static int find_bootrepos(const char *devnode, const char *type, .searchname = ".boot_repository", .callback = bootrepo_cb, .userdata = &repos, - .fastdir = 0, }; @@ -603,7 +598,6 @@ void *trigger_thread(void *data) .searchname = "uevent", .callback = trigger_uevent_cb, .userdata = NULL, - .fastdir = 1, }; char path[PATH_MAX] = "/sys/bus"; -- cgit v1.2.3