diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2014-07-16 18:59:49 -0400 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2014-07-16 19:00:03 -0400 |
commit | ed88bcfb7c15029f9fc95ee2380759a9eb782d46 (patch) | |
tree | 11913b6937d91fa4ee49f312eb044abc38ae7c50 /src/network | |
parent | 36f822c4bd077f9121757e24b6516e5c7ada63b5 (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/network')
-rw-r--r-- | src/network/networkd-netdev.c | 10 | ||||
-rw-r--r-- | src/network/networkd-network.c | 4 |
2 files changed, 7 insertions, 7 deletions
diff --git a/src/network/networkd-netdev.c b/src/network/networkd-netdev.c index 9974913f49..8b96d60dca 100644 --- a/src/network/networkd-netdev.c +++ b/src/network/networkd-netdev.c @@ -495,11 +495,6 @@ static int netdev_load_one(Manager *manager, const char *filename) { assert(manager); 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) @@ -508,6 +503,11 @@ static int netdev_load_one(Manager *manager, const char *filename) { return -errno; } + if (null_or_empty_fd(fileno(file))) { + log_debug("Skipping empty file: %s", filename); + return 0; + } + netdev = new0(NetDev, 1); if (!netdev) return log_oom(); diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c index 700577fccf..3e46a1a80e 100644 --- a/src/network/networkd-network.c +++ b/src/network/networkd-network.c @@ -48,8 +48,8 @@ static int network_load_one(Manager *manager, const char *filename) { return -errno; } - if (null_or_empty_path(filename)) { - log_debug("skipping empty file: %s", filename); + if (null_or_empty_fd(fileno(file))) { + log_debug("Skipping empty file: %s", filename); return 0; } |