summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-09-09 15:20:10 +0200
committerLennart Poettering <lennart@poettering.net>2015-09-09 15:26:11 +0200
commit74ca738f6a01fb5fc19c5c3899f5cb1fdc1d7f68 (patch)
tree920d0abca454976756296d982d1cb9ef794e1ade /src/core
parent9c00a6adfa6c2ded071222b2ec76295480add34e (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')
-rw-r--r--src/core/main.c21
-rw-r--r--src/core/mount.c5
-rw-r--r--src/core/swap.c5
3 files changed, 7 insertions, 24 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);
diff --git a/src/core/mount.c b/src/core/mount.c
index 83746ca412..1f02aa5566 100644
--- a/src/core/mount.c
+++ b/src/core/mount.c
@@ -1540,10 +1540,7 @@ static void mount_shutdown(Manager *m) {
m->mount_event_source = sd_event_source_unref(m->mount_event_source);
m->mount_utab_event_source = sd_event_source_unref(m->mount_utab_event_source);
- if (m->proc_self_mountinfo) {
- fclose(m->proc_self_mountinfo);
- m->proc_self_mountinfo = NULL;
- }
+ m->proc_self_mountinfo = safe_fclose(m->proc_self_mountinfo);
m->utab_inotify_fd = safe_close(m->utab_inotify_fd);
}
diff --git a/src/core/swap.c b/src/core/swap.c
index a26bc58cfc..311ce7ee04 100644
--- a/src/core/swap.c
+++ b/src/core/swap.c
@@ -1252,10 +1252,7 @@ static void swap_shutdown(Manager *m) {
m->swap_event_source = sd_event_source_unref(m->swap_event_source);
- if (m->proc_swaps) {
- fclose(m->proc_swaps);
- m->proc_swaps = NULL;
- }
+ m->proc_swaps = safe_fclose(m->proc_swaps);
hashmap_free(m->swaps_by_devnode);
m->swaps_by_devnode = NULL;