diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-09-09 15:20:10 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-09-09 15:26:11 +0200 |
commit | 74ca738f6a01fb5fc19c5c3899f5cb1fdc1d7f68 (patch) | |
tree | 920d0abca454976756296d982d1cb9ef794e1ade /src/core/main.c | |
parent | 9c00a6adfa6c2ded071222b2ec76295480add34e (diff) |
util: introduce safe_fclose() and port everything over to it
Adds a coccinelle script to port things over automatically.
Diffstat (limited to 'src/core/main.c')
-rw-r--r-- | src/core/main.c | 21 |
1 files changed, 5 insertions, 16 deletions
diff --git a/src/core/main.c b/src/core/main.c index 9aaf244e71..6577a06621 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -918,8 +918,7 @@ static int parse_argv(int argc, char *argv[]) { if (!f) return log_error_errno(errno, "Failed to open serialization fd: %m"); - if (arg_serialization) - fclose(arg_serialization); + safe_fclose(arg_serialization); arg_serialization = f; @@ -1059,8 +1058,7 @@ static int prepare_reexecute(Manager *m, FILE **_f, FDSet **_fds, bool switching fail: fdset_free(fds); - if (f) - fclose(f); + safe_fclose(f); return r; } @@ -1678,10 +1676,7 @@ int main(int argc, char *argv[]) { fdset_free(fds); fds = NULL; - if (arg_serialization) { - fclose(arg_serialization); - arg_serialization = NULL; - } + arg_serialization = safe_fclose(arg_serialization); if (queue_default_job) { _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; @@ -1923,10 +1918,7 @@ finish: * getopt() in argv[], and some cleanups in envp[], * but let's hope that doesn't matter.) */ - if (arg_serialization) { - fclose(arg_serialization); - arg_serialization = NULL; - } + arg_serialization = safe_fclose(arg_serialization); if (fds) { fdset_free(fds); @@ -1966,10 +1958,7 @@ finish: log_warning_errno(errno, "Failed to execute /sbin/init, giving up: %m"); } - if (arg_serialization) { - fclose(arg_serialization); - arg_serialization = NULL; - } + arg_serialization = safe_fclose(arg_serialization); if (fds) { fdset_free(fds); |