|
|
65878a |
From 735583e63b9c109e3aaa7aecbce8d7a477988ef6 Mon Sep 17 00:00:00 2001
|
|
|
65878a |
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
|
|
|
65878a |
Date: Fri, 11 Oct 2013 19:33:48 -0400
|
|
|
65878a |
Subject: [PATCH] Introduce _cleanup_fdset_free_
|
|
|
65878a |
|
|
|
65878a |
(cherry picked from commit 51d122af23533b0b8318911c4fc8b128ad8eafb7)
|
|
|
65878a |
|
|
|
65878a |
Related: #1098310
|
|
|
65878a |
---
|
|
|
65878a |
src/core/manager.c | 22 +++++++---------------
|
|
|
65878a |
src/nspawn/nspawn.c | 4 +---
|
|
|
65878a |
src/shared/fdset.h | 7 +++++++
|
|
|
65878a |
3 files changed, 15 insertions(+), 18 deletions(-)
|
|
|
65878a |
|
|
|
65878a |
diff --git a/src/core/manager.c b/src/core/manager.c
|
|
|
65878a |
index 2829c95..57a88b0 100644
|
|
|
65878a |
--- a/src/core/manager.c
|
|
|
65878a |
+++ b/src/core/manager.c
|
|
|
65878a |
@@ -236,7 +236,7 @@ static void draw_cylon(char buffer[], size_t buflen, unsigned width, unsigned po
|
|
|
65878a |
*p++ = '*';
|
|
|
65878a |
if (pos < width-1)
|
|
|
65878a |
p = mempset(p, ' ', width-1-pos);
|
|
|
65878a |
- p = stpcpy(p, ANSI_HIGHLIGHT_OFF);
|
|
|
65878a |
+ strcpy(p, ANSI_HIGHLIGHT_OFF);
|
|
|
65878a |
}
|
|
|
65878a |
}
|
|
|
65878a |
|
|
|
65878a |
@@ -257,6 +257,7 @@ static void manager_print_jobs_in_progress(Manager *m) {
|
|
|
65878a |
/* m->n_running_jobs must be consistent with the contents of m->jobs,
|
|
|
65878a |
* so the above loop must have succeeded in finding j. */
|
|
|
65878a |
assert(counter == print_nr + 1);
|
|
|
65878a |
+ assert(j);
|
|
|
65878a |
|
|
|
65878a |
cylon_pos = m->jobs_in_progress_iteration % 14;
|
|
|
65878a |
if (cylon_pos >= 8)
|
|
|
65878a |
@@ -2343,8 +2344,8 @@ int manager_distribute_fds(Manager *m, FDSet *fds) {
|
|
|
65878a |
|
|
|
65878a |
int manager_reload(Manager *m) {
|
|
|
65878a |
int r, q;
|
|
|
65878a |
- FILE *f;
|
|
|
65878a |
- FDSet *fds;
|
|
|
65878a |
+ _cleanup_fclose_ FILE *f = NULL;
|
|
|
65878a |
+ _cleanup_fdset_free_ FDSet *fds = NULL;
|
|
|
65878a |
|
|
|
65878a |
assert(m);
|
|
|
65878a |
|
|
|
65878a |
@@ -2358,20 +2359,18 @@ int manager_reload(Manager *m) {
|
|
|
65878a |
fds = fdset_new();
|
|
|
65878a |
if (!fds) {
|
|
|
65878a |
m->n_reloading --;
|
|
|
65878a |
- r = -ENOMEM;
|
|
|
65878a |
- goto finish;
|
|
|
65878a |
+ return -ENOMEM;
|
|
|
65878a |
}
|
|
|
65878a |
|
|
|
65878a |
r = manager_serialize(m, f, fds, false);
|
|
|
65878a |
if (r < 0) {
|
|
|
65878a |
m->n_reloading --;
|
|
|
65878a |
- goto finish;
|
|
|
65878a |
+ return r;
|
|
|
65878a |
}
|
|
|
65878a |
|
|
|
65878a |
if (fseeko(f, 0, SEEK_SET) < 0) {
|
|
|
65878a |
m->n_reloading --;
|
|
|
65878a |
- r = -errno;
|
|
|
65878a |
- goto finish;
|
|
|
65878a |
+ return -errno;
|
|
|
65878a |
}
|
|
|
65878a |
|
|
|
65878a |
/* From here on there is no way back. */
|
|
|
65878a |
@@ -2415,13 +2414,6 @@ int manager_reload(Manager *m) {
|
|
|
65878a |
|
|
|
65878a |
m->send_reloading_done = true;
|
|
|
65878a |
|
|
|
65878a |
-finish:
|
|
|
65878a |
- if (f)
|
|
|
65878a |
- fclose(f);
|
|
|
65878a |
-
|
|
|
65878a |
- if (fds)
|
|
|
65878a |
- fdset_free(fds);
|
|
|
65878a |
-
|
|
|
65878a |
return r;
|
|
|
65878a |
}
|
|
|
65878a |
|
|
|
65878a |
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
|
|
|
65878a |
index f326f99..1cf67d0 100644
|
|
|
65878a |
--- a/src/nspawn/nspawn.c
|
|
|
65878a |
+++ b/src/nspawn/nspawn.c
|
|
|
65878a |
@@ -1305,7 +1305,7 @@ int main(int argc, char *argv[]) {
|
|
|
65878a |
bool saved_attr_valid = false;
|
|
|
65878a |
struct winsize ws;
|
|
|
65878a |
int kmsg_socket_pair[2] = { -1, -1 };
|
|
|
65878a |
- FDSet *fds = NULL;
|
|
|
65878a |
+ _cleanup_fdset_free_ FDSet *fds = NULL;
|
|
|
65878a |
|
|
|
65878a |
log_parse_environment();
|
|
|
65878a |
log_open();
|
|
|
65878a |
@@ -1813,7 +1813,5 @@ finish:
|
|
|
65878a |
free(arg_directory);
|
|
|
65878a |
free(arg_machine);
|
|
|
65878a |
|
|
|
65878a |
- fdset_free(fds);
|
|
|
65878a |
-
|
|
|
65878a |
return r;
|
|
|
65878a |
}
|
|
|
65878a |
diff --git a/src/shared/fdset.h b/src/shared/fdset.h
|
|
|
65878a |
index a7bd5e2..1a26005 100644
|
|
|
65878a |
--- a/src/shared/fdset.h
|
|
|
65878a |
+++ b/src/shared/fdset.h
|
|
|
65878a |
@@ -22,6 +22,7 @@
|
|
|
65878a |
***/
|
|
|
65878a |
|
|
|
65878a |
#include "set.h"
|
|
|
65878a |
+#include "util.h"
|
|
|
65878a |
|
|
|
65878a |
typedef struct FDSet FDSet;
|
|
|
65878a |
|
|
|
65878a |
@@ -47,3 +48,9 @@ int fdset_iterate(FDSet *s, Iterator *i);
|
|
|
65878a |
|
|
|
65878a |
#define FDSET_FOREACH(fd, fds, i) \
|
|
|
65878a |
for ((i) = ITERATOR_FIRST, (fd) = fdset_iterate((fds), &(i)); (fd) >= 0; (fd) = fdset_iterate((fds), &(i)))
|
|
|
65878a |
+
|
|
|
65878a |
+static inline void fdset_freep(FDSet **fds) {
|
|
|
65878a |
+ if (*fds)
|
|
|
65878a |
+ fdset_free(*fds);
|
|
|
65878a |
+}
|
|
|
65878a |
+#define _cleanup_fdset_free_ _cleanup_(fdset_freep)
|