summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGabor Juhos <juhosg@openwrt.org>2013-09-10 12:59:25 +0200
committerFelix Fietkau <nbd@openwrt.org>2013-09-10 13:25:35 +0200
commit824a4b3da2c0be19ccf54a48dcd4c10677b82c1a (patch)
treebfa009fa82beef07639535552fb82189c1aa7b14
parent782013924f28b9ebadfcd9d1719939bcc344c548 (diff)
downloadunitd-824a4b3da2c0be19ccf54a48dcd4c10677b82c1a.tar
unitd-824a4b3da2c0be19ccf54a48dcd4c10677b82c1a.zip
udevtrigger: reduce indent level in scan_* functions
Return early from the scan_* functions if the opendir call fails. This allows to reduce the indentation level of the subsequent code by one tab. Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
-rw-r--r--udevtrigger.c103
1 files changed, 54 insertions, 49 deletions
diff --git a/udevtrigger.c b/udevtrigger.c
index 98b0743..dbb414a 100644
--- a/udevtrigger.c
+++ b/udevtrigger.c
@@ -185,20 +185,19 @@ static void scan_subdir(const char *base)
struct dirent *dent;
dir = opendir(base);
- if (dir != NULL) {
- for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
- char dirname[PATH_SIZE];
+ if (dir == NULL)
+ return;
- if (dent->d_name[0] == '.')
- continue;
+ for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
+ char dirname[PATH_SIZE];
- strlcpy(dirname, base, sizeof(dirname));
- strlcat(dirname, "/", sizeof(dirname));
- strlcat(dirname, dent->d_name, sizeof(dirname));
- device_list_insert(dirname);
- }
- closedir(dir);
+ strlcpy(dirname, base, sizeof(dirname));
+ strlcat(dirname, "/", sizeof(dirname));
+ strlcat(dirname, dent->d_name, sizeof(dirname));
+ device_list_insert(dirname);
}
+
+ closedir(dir);
}
static void scan_subsystem(const char *subsys)
@@ -211,23 +210,25 @@ static void scan_subsystem(const char *subsys)
strlcat(base, subsys, sizeof(base));
dir = opendir(base);
- if (dir != NULL) {
- for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
- char dirname[PATH_SIZE];
+ if (dir == NULL)
+ return;
- if (dent->d_name[0] == '.')
- continue;
+ for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
+ char dirname[PATH_SIZE];
- strlcpy(dirname, base, sizeof(dirname));
- strlcat(dirname, "/", sizeof(dirname));
- strlcat(dirname, dent->d_name, sizeof(dirname));
- strlcat(dirname, "/devices", sizeof(dirname));
+ if (dent->d_name[0] == '.')
+ continue;
- /* look for devices */
- scan_subdir(dirname);
- }
- closedir(dir);
+ strlcpy(dirname, base, sizeof(dirname));
+ strlcat(dirname, "/", sizeof(dirname));
+ strlcat(dirname, dent->d_name, sizeof(dirname));
+ strlcat(dirname, "/devices", sizeof(dirname));
+
+ /* look for devices */
+ scan_subdir(dirname);
}
+
+ closedir(dir);
}
static void scan_block(void)
@@ -239,24 +240,26 @@ static void scan_block(void)
strlcpy(base, "/sys/block", sizeof(base));
dir = opendir(base);
- if (dir != NULL) {
- for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
- char dirname[PATH_SIZE];
+ if (dir == NULL)
+ return;
- if (dent->d_name[0] == '.')
- continue;
+ for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
+ char dirname[PATH_SIZE];
- strlcpy(dirname, base, sizeof(dirname));
- strlcat(dirname, "/", sizeof(dirname));
- strlcat(dirname, dent->d_name, sizeof(dirname));
- if (device_list_insert(dirname) != 0)
- continue;
+ if (dent->d_name[0] == '.')
+ continue;
- /* look for partitions */
- scan_subdir(dirname);
- }
- closedir(dir);
+ strlcpy(dirname, base, sizeof(dirname));
+ strlcat(dirname, "/", sizeof(dirname));
+ strlcat(dirname, dent->d_name, sizeof(dirname));
+ if (device_list_insert(dirname) != 0)
+ continue;
+
+ /* look for partitions */
+ scan_subdir(dirname);
}
+
+ closedir(dir);
}
static void scan_class(void)
@@ -268,21 +271,23 @@ static void scan_class(void)
strlcpy(base, "/sys/class", sizeof(base));
dir = opendir(base);
- if (dir != NULL) {
- for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
- char dirname[PATH_SIZE];
+ if (dir == NULL)
+ return;
- if (dent->d_name[0] == '.')
- continue;
+ for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
+ char dirname[PATH_SIZE];
- strlcpy(dirname, base, sizeof(dirname));
- strlcat(dirname, "/", sizeof(dirname));
- strlcat(dirname, dent->d_name, sizeof(dirname));
+ if (dent->d_name[0] == '.')
+ continue;
- scan_subdir(dirname);
- }
- closedir(dir);
+ strlcpy(dirname, base, sizeof(dirname));
+ strlcat(dirname, "/", sizeof(dirname));
+ strlcat(dirname, dent->d_name, sizeof(dirname));
+
+ scan_subdir(dirname);
}
+
+ closedir(dir);
}
int main(int argc, char *argv[], char *envp[])