From: Lennart Poettering Date: Tue, 9 Oct 2018 14:45:33 +0000 (+0200) Subject: core: allow manager_serialize() to fail correctly X-Git-Tag: v240~585^2~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4daf832afaeac471085e56445a05218217bf5107;p=thirdparty%2Fsystemd.git core: allow manager_serialize() to fail correctly If manager_serialize() fails in the middle (which it hopefully doesn't) make sure to fix up m->n_reloading correctly again so that we don't leave it > 0 when it really shouldn't be. --- diff --git a/src/core/manager.c b/src/core/manager.c index ba16e8259e7..c41d88f3f6c 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -3043,7 +3043,12 @@ int manager_open_serialization(Manager *m, FILE **_f) { return 0; } -int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool switching_root) { +int manager_serialize( + Manager *m, + FILE *f, + FDSet *fds, + bool switching_root) { + ManagerTimestamp q; const char *t; Iterator i; @@ -3097,8 +3102,10 @@ int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool switching_root) { int copy; copy = fdset_put_dup(fds, m->notify_fd); - if (copy < 0) - return copy; + if (copy < 0) { + r = copy; + goto finish; + } fprintf(f, "notify-fd=%i\n", copy); fprintf(f, "notify-socket=%s\n", m->notify_socket); @@ -3108,8 +3115,10 @@ int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool switching_root) { int copy; copy = fdset_put_dup(fds, m->cgroups_agent_fd); - if (copy < 0) - return copy; + if (copy < 0) { + r = copy; + goto finish; + } fprintf(f, "cgroups-agent-fd=%i\n", copy); } @@ -3118,12 +3127,16 @@ int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool switching_root) { int copy0, copy1; copy0 = fdset_put_dup(fds, m->user_lookup_fds[0]); - if (copy0 < 0) - return copy0; + if (copy0 < 0) { + r = copy0; + goto finish; + } copy1 = fdset_put_dup(fds, m->user_lookup_fds[1]); - if (copy1 < 0) - return copy1; + if (copy1 < 0) { + r = copy1; + goto finish; + } fprintf(f, "user-lookup=%i %i\n", copy0, copy1); } @@ -3132,14 +3145,14 @@ int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool switching_root) { r = dynamic_user_serialize(m, f, fds); if (r < 0) - return r; + goto finish; manager_serialize_uid_refs(m, f); manager_serialize_gid_refs(m, f); r = exec_runtime_serialize(m, f, fds); if (r < 0) - return r; + goto finish; (void) fputc('\n', f); @@ -3152,24 +3165,25 @@ int manager_serialize(Manager *m, FILE *f, FDSet *fds, bool switching_root) { fputc('\n', f); r = unit_serialize(u, f, fds, !switching_root); - if (r < 0) { - m->n_reloading--; - return r; - } + if (r < 0) + goto finish; } - assert(m->n_reloading > 0); - m->n_reloading--; - r = fflush_and_check(f); if (r < 0) - return r; + goto finish; r = bus_fdset_add_all(m, fds); if (r < 0) - return r; + goto finish; - return 0; + r = 0; + +finish: + assert(m->n_reloading > 0); + m->n_reloading--; + + return r; } int manager_deserialize(Manager *m, FILE *f, FDSet *fds) {