anitazha / rpms / systemd

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