[systemd-commits] 2 commits - src/core src/libsystemd src/shared

Lennart Poettering lennart at kemper.freedesktop.org
Mon Feb 3 10:59:56 PST 2014


 src/core/load-dropin.c         |   36 +++++++++----------------
 src/libsystemd/sd-bus/sd-bus.c |   57 +++++++++++++++++++++++++----------------
 src/shared/conf-parser.c       |    2 +
 src/shared/util.c              |   18 ++++++++++++
 src/shared/util.h              |    2 +
 5 files changed, 71 insertions(+), 44 deletions(-)

New commits:
commit f389bf15d0b732027669690ed9606a96c0568bbd
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Feb 3 13:26:24 2014 +0100

    bus: when closing the bus don't end up in a recursive destruction deadlock

diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c
index 4203930..4fdc246 100644
--- a/src/libsystemd/sd-bus/sd-bus.c
+++ b/src/libsystemd/sd-bus/sd-bus.c
@@ -107,21 +107,21 @@ static void bus_node_destroy(sd_bus *b, struct node *n) {
 }
 
 static void bus_reset_queues(sd_bus *b) {
-        unsigned i;
-
         assert(b);
 
-        for (i = 0; i < b->rqueue_size; i++)
-                sd_bus_message_unref(b->rqueue[i]);
+        while (b->rqueue_size > 0)
+                sd_bus_message_unref(b->rqueue[--b->rqueue_size]);
+
         free(b->rqueue);
+        b->rqueue = NULL;
+        b->rqueue_allocated = 0;
 
-        for (i = 0; i < b->wqueue_size; i++)
-                sd_bus_message_unref(b->wqueue[i]);
-        free(b->wqueue);
+        while (b->wqueue_size > 0)
+                sd_bus_message_unref(b->wqueue[--b->wqueue_size]);
 
-        b->rqueue = b->wqueue = NULL;
-        b->rqueue_allocated = b->wqueue_allocated = 0;
-        b->rqueue_size = b->wqueue_size = 0;
+        free(b->wqueue);
+        b->wqueue = NULL;
+        b->wqueue_allocated = 0;
 }
 
 static void bus_free(sd_bus *b) {
@@ -1340,21 +1340,36 @@ _public_ sd_bus *sd_bus_unref(sd_bus *bus) {
         if (!bus)
                 return NULL;
 
-        i = REFCNT_DEC(bus->n_ref);
-        if (i != bus->rqueue_size + bus->wqueue_size)
-                return NULL;
+        if (REFCNT_GET(bus->n_ref) == bus->rqueue_size + bus->wqueue_size + 1) {
+                bool q = true;
+
+                for (i = 0; i < bus->rqueue_size; i++)
+                        if (bus->rqueue[i]->n_ref > 1) {
+                                q = false;
+                                break;
+                        }
 
-        for (i = 0; i < bus->rqueue_size; i++)
-                if (bus->rqueue[i]->n_ref > 1)
-                        return NULL;
+                if (q) {
+                        for (i = 0; i < bus->wqueue_size; i++)
+                                if (bus->wqueue[i]->n_ref > 1) {
+                                        q = false;
+                                        break;
+                                }
+                }
 
-        for (i = 0; i < bus->wqueue_size; i++)
-                if (bus->wqueue[i]->n_ref > 1)
-                        return NULL;
+                /* We are the only holders on the messages, and the
+                 * messages are the only holders on us, so let's drop
+                 * the messages and thus implicitly also kill our own
+                 * last references */
 
-        /* we are the only holders on the messages */
-        bus_free(bus);
+                bus_reset_queues(bus);
+        }
 
+        i = REFCNT_DEC(bus->n_ref);
+        if (i > 0)
+                return NULL;
+
+        bus_free(bus);
         return NULL;
 }
 

commit fdb9161cd3e1a64eb9a653a6bf69596670d6e942
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Feb 3 12:52:16 2014 +0100

    conf-parser: warn when we open configuration files with weird access bits

diff --git a/src/core/load-dropin.c b/src/core/load-dropin.c
index 3504009..546e560 100644
--- a/src/core/load-dropin.c
+++ b/src/core/load-dropin.c
@@ -100,8 +100,8 @@ static int process_dir(
                 UnitDependency dependency,
                 char ***strv) {
 
+        _cleanup_free_ char *path = NULL;
         int r;
-        char *path;
 
         assert(u);
         assert(unit_path);
@@ -112,39 +112,29 @@ static int process_dir(
         if (!path)
                 return log_oom();
 
-        if (u->manager->unit_path_cache &&
-            !set_get(u->manager->unit_path_cache, path))
-                r = 0;
-        else
+        if (!u->manager->unit_path_cache || set_get(u->manager->unit_path_cache, path)) {
                 r = iterate_dir(u, path, dependency, strv);
-        free(path);
-
-        if (r < 0)
-                return r;
+                if (r < 0)
+                        return r;
+        }
 
         if (u->instance) {
-                char *template;
+                _cleanup_free_ char *template = NULL, *p = NULL;
                 /* Also try the template dir */
 
                 template = unit_name_template(name);
                 if (!template)
                         return log_oom();
 
-                path = strjoin(unit_path, "/", template, suffix, NULL);
-                free(template);
-
-                if (!path)
+                p = strjoin(unit_path, "/", template, suffix, NULL);
+                if (!p)
                         return log_oom();
 
-                if (u->manager->unit_path_cache &&
-                    !set_get(u->manager->unit_path_cache, path))
-                        r = 0;
-                else
-                        r = iterate_dir(u, path, dependency, strv);
-                free(path);
-
-                if (r < 0)
-                        return r;
+                if (!u->manager->unit_path_cache || set_get(u->manager->unit_path_cache, p)) {
+                        r = iterate_dir(u, p, dependency, strv);
+                        if (r < 0)
+                                return r;
+                }
         }
 
         return 0;
diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c
index df4e961..d5a639e 100644
--- a/src/shared/conf-parser.c
+++ b/src/shared/conf-parser.c
@@ -332,6 +332,8 @@ int config_parse(const char *unit,
                 }
         }
 
+        fd_warn_permissions(filename, fileno(f));
+
         while (!feof(f)) {
                 char l[LINE_MAX], *p, *c = NULL, *e;
                 bool escaped = false;
diff --git a/src/shared/util.c b/src/shared/util.c
index aae5872..f76ed6f 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -6132,3 +6132,21 @@ int open_tmpfile(const char *path, int flags) {
         unlink(p);
         return fd;
 }
+
+int fd_warn_permissions(const char *path, int fd) {
+        struct stat st;
+
+        if (fstat(fd, &st) < 0)
+                return -errno;
+
+        if (st.st_mode & 0111)
+                log_warning("Configuration file %s is marked executable. Please remove executable permission bits. Proceeding anyway.", path);
+
+        if (st.st_mode & 0002)
+                log_warning("Configuration file %s is marked world-writable. Please remove world writability permission bits. Proceeding anyway.", path);
+
+        if (getpid() == 1 && (st.st_mode & 0044) != 0044)
+                log_warning("Configuration file %s is marked world-inaccessible. This has no effect as configuration data is accessible via APIs without restrictions. Proceeding anyway.", path);
+
+        return 0;
+}
diff --git a/src/shared/util.h b/src/shared/util.h
index e4de472..219e489 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -867,3 +867,5 @@ int writev_safe(int fd, const struct iovec *w, int j);
 
 int mkostemp_safe(char *pattern, int flags);
 int open_tmpfile(const char *path, int flags);
+
+int fd_warn_permissions(const char *path, int fd);



More information about the systemd-commits mailing list