summaryrefslogtreecommitdiff
path: root/src/udev
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-07-16 18:59:49 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-07-16 19:00:03 -0400
commited88bcfb7c15029f9fc95ee2380759a9eb782d46 (patch)
tree11913b6937d91fa4ee49f312eb044abc38ae7c50 /src/udev
parent36f822c4bd077f9121757e24b6516e5c7ada63b5 (diff)
Be more careful when checking for empty files
If we want to avoid reading a totally empty file, it seems better to check after we have opened the file, not before.
Diffstat (limited to 'src/udev')
-rw-r--r--src/udev/net/link-config.c10
-rw-r--r--src/udev/udev-rules.c18
2 files changed, 16 insertions, 12 deletions
diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c
index 73243fa107..512885f9c8 100644
--- a/src/udev/net/link-config.c
+++ b/src/udev/net/link-config.c
@@ -153,11 +153,6 @@ static int load_link(link_config_ctx *ctx, const char *filename) {
assert(ctx);
assert(filename);
- if (null_or_empty_path(filename)) {
- log_debug("skipping empty file: %s", filename);
- return 0;
- }
-
file = fopen(filename, "re");
if (!file) {
if (errno == ENOENT)
@@ -166,6 +161,11 @@ static int load_link(link_config_ctx *ctx, const char *filename) {
return -errno;
}
+ if (null_or_empty_fd(fileno(file))) {
+ log_debug("Skipping empty file: %s", filename);
+ return 0;
+ }
+
link = new0(link_config, 1);
if (!link)
return log_oom();
diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c
index 85f78bcdef..9864016d14 100644
--- a/src/udev/udev-rules.c
+++ b/src/udev/udev-rules.c
@@ -1533,15 +1533,19 @@ static int parse_file(struct udev_rules *rules, const char *filename)
int line_nr = 0;
unsigned int i;
- if (null_or_empty_path(filename)) {
- log_debug("skip empty file: %s", filename);
- return 0;
+ f = fopen(filename, "re");
+ if (!f) {
+ if (errno == ENOENT)
+ return 0;
+ else
+ return -errno;
}
- log_debug("read rules file: %s", filename);
- f = fopen(filename, "re");
- if (f == NULL)
- return -1;
+ if (null_or_empty_fd(fileno(f))) {
+ log_debug("Skipping empty file: %s", filename);
+ return 0;
+ } else
+ log_debug("Reading rules file: %s", filename);
first_token = rules->token_cur;
filename_off = rules_add_string(rules, filename);