chiark / gitweb /
Introduce _cleanup_fdset_free_
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 11 Oct 2013 23:33:48 +0000 (19:33 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 13 Oct 2013 21:56:54 +0000 (17:56 -0400)
src/core/manager.c
src/nspawn/nspawn.c
src/shared/fdset.h

index 58dacdc8b5d7e894d909eb5cc60e66a3018ae75f..b45a2e11a5a1cde016bd0b529e9468fc33346a10 100644 (file)
@@ -236,7 +236,7 @@ static void draw_cylon(char buffer[], size_t buflen, unsigned width, unsigned po
                 *p++ = '*';
                 if (pos < width-1)
                         p = mempset(p, ' ', width-1-pos);
                 *p++ = '*';
                 if (pos < width-1)
                         p = mempset(p, ' ', width-1-pos);
-                p = stpcpy(p, ANSI_HIGHLIGHT_OFF);
+                strcpy(p, ANSI_HIGHLIGHT_OFF);
         }
 }
 
         }
 }
 
@@ -257,6 +257,7 @@ static void manager_print_jobs_in_progress(Manager *m) {
         /* m->n_running_jobs must be consistent with the contents of m->jobs,
          * so the above loop must have succeeded in finding j. */
         assert(counter == print_nr + 1);
         /* m->n_running_jobs must be consistent with the contents of m->jobs,
          * so the above loop must have succeeded in finding j. */
         assert(counter == print_nr + 1);
+        assert(j);
 
         cylon_pos = m->jobs_in_progress_iteration % 14;
         if (cylon_pos >= 8)
 
         cylon_pos = m->jobs_in_progress_iteration % 14;
         if (cylon_pos >= 8)
@@ -2317,8 +2318,8 @@ int manager_distribute_fds(Manager *m, FDSet *fds) {
 
 int manager_reload(Manager *m) {
         int r, q;
 
 int manager_reload(Manager *m) {
         int r, q;
-        FILE *f;
-        FDSet *fds;
+        _cleanup_fclose_ FILE *f = NULL;
+        _cleanup_fdset_free_ FDSet *fds = NULL;
 
         assert(m);
 
 
         assert(m);
 
@@ -2332,20 +2333,18 @@ int manager_reload(Manager *m) {
         fds = fdset_new();
         if (!fds) {
                 m->n_reloading --;
         fds = fdset_new();
         if (!fds) {
                 m->n_reloading --;
-                r = -ENOMEM;
-                goto finish;
+                return -ENOMEM;
         }
 
         r = manager_serialize(m, f, fds, false);
         if (r < 0) {
                 m->n_reloading --;
         }
 
         r = manager_serialize(m, f, fds, false);
         if (r < 0) {
                 m->n_reloading --;
-                goto finish;
+                return r;
         }
 
         if (fseeko(f, 0, SEEK_SET) < 0) {
                 m->n_reloading --;
         }
 
         if (fseeko(f, 0, SEEK_SET) < 0) {
                 m->n_reloading --;
-                r = -errno;
-                goto finish;
+                return -errno;
         }
 
         /* From here on there is no way back. */
         }
 
         /* From here on there is no way back. */
@@ -2389,13 +2388,6 @@ int manager_reload(Manager *m) {
 
         m->send_reloading_done = true;
 
 
         m->send_reloading_done = true;
 
-finish:
-        if (f)
-                fclose(f);
-
-        if (fds)
-                fdset_free(fds);
-
         return r;
 }
 
         return r;
 }
 
index fc4a8a36c869b716a4ffff7b38cb46fcc5bb7d39..15e48739b9a3a015a890ba0707a0e53e907315ec 100644 (file)
@@ -1223,7 +1223,7 @@ int main(int argc, char *argv[]) {
         bool saved_attr_valid = false;
         struct winsize ws;
         int kmsg_socket_pair[2] = { -1, -1 };
         bool saved_attr_valid = false;
         struct winsize ws;
         int kmsg_socket_pair[2] = { -1, -1 };
-        FDSet *fds = NULL;
+        _cleanup_fdset_free_ FDSet *fds = NULL;
 
         log_parse_environment();
         log_open();
 
         log_parse_environment();
         log_open();
@@ -1725,7 +1725,5 @@ finish:
         free(arg_directory);
         free(arg_machine);
 
         free(arg_directory);
         free(arg_machine);
 
-        fdset_free(fds);
-
         return r;
 }
         return r;
 }
index a7bd5e2b40a798c9fae698440cdece50409f82e5..1a26005183df59451fa9c11cd0aa1f4030d5e757 100644 (file)
@@ -22,6 +22,7 @@
 ***/
 
 #include "set.h"
 ***/
 
 #include "set.h"
+#include "util.h"
 
 typedef struct FDSet FDSet;
 
 
 typedef struct FDSet FDSet;
 
@@ -47,3 +48,9 @@ int fdset_iterate(FDSet *s, Iterator *i);
 
 #define FDSET_FOREACH(fd, fds, i) \
         for ((i) = ITERATOR_FIRST, (fd) = fdset_iterate((fds), &(i)); (fd) >= 0; (fd) = fdset_iterate((fds), &(i)))
 
 #define FDSET_FOREACH(fd, fds, i) \
         for ((i) = ITERATOR_FIRST, (fd) = fdset_iterate((fds), &(i)); (fd) >= 0; (fd) = fdset_iterate((fds), &(i)))
+
+static inline void fdset_freep(FDSet **fds) {
+        if (*fds)
+                fdset_free(*fds);
+}
+#define _cleanup_fdset_free_ _cleanup_(fdset_freep)