[systemd-commits] 3 commits - Makefile.am TODO src/resolve src/shared

Lennart Poettering lennart at kemper.freedesktop.org
Wed Apr 8 08:24:42 PDT 2015


 Makefile.am                    |    1 
 TODO                           |    2 +
 src/resolve/resolved-manager.c |   39 ++++++++++++++-------------
 src/shared/ordered-set.h       |   59 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 83 insertions(+), 18 deletions(-)

New commits:
commit b18d23d7ac6a53d52b99dbf0b2048d5a946a2e28
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Apr 8 17:24:23 2015 +0200

    update TODO

diff --git a/TODO b/TODO
index eea359e..39c6548 100644
--- a/TODO
+++ b/TODO
@@ -43,6 +43,8 @@ Before 220:
 
 Features:
 
+* docs: bring http://www.freedesktop.org/wiki/Software/systemd/MyServiceCantGetRealtime up to date
+
 * systemctl should set EFI firmware flag via logind
 
 * mounting and unmounting mount points manually with different source

commit 822db23cfa98a9fbc48f41e11caafb6f1017e052
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Apr 8 17:23:27 2015 +0200

    resolved: maintain order when writing resolv.conf entries
    
    http://lists.freedesktop.org/archives/systemd-devel/2015-March/029850.html

diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c
index 167bea3..adaa6c6 100644
--- a/src/resolve/resolved-manager.c
+++ b/src/resolve/resolved-manager.c
@@ -30,6 +30,7 @@
 #include "af-list.h"
 #include "utf8.h"
 #include "fileio-label.h"
+#include "ordered-set.h"
 
 #include "resolved-dns-domain.h"
 #include "resolved-conf.h"
@@ -702,8 +703,11 @@ static void write_resolv_conf_server(DnsServer *s, FILE *f, unsigned *count) {
         (*count) ++;
 }
 
-static void write_resolv_conf_search(const char *domain, FILE *f,
-                                     unsigned *count, unsigned *length) {
+static void write_resolv_conf_search(
+                const char *domain, FILE *f,
+                unsigned *count,
+                unsigned *length) {
+
         assert(domain);
         assert(f);
         assert(length);
@@ -724,7 +728,7 @@ static void write_resolv_conf_search(const char *domain, FILE *f,
         (*count) ++;
 }
 
-static int write_resolv_conf_contents(FILE *f, Set *dns, Set *domains) {
+static int write_resolv_conf_contents(FILE *f, OrderedSet *dns, OrderedSet *domains) {
         Iterator i;
 
         fputs("# This file is managed by systemd-resolved(8). Do not edit.\n#\n"
@@ -733,22 +737,22 @@ static int write_resolv_conf_contents(FILE *f, Set *dns, Set *domains) {
               "# resolv.conf(5) in a different way, replace the symlink by a\n"
               "# static file or a different symlink.\n\n", f);
 
-        if (set_isempty(dns))
+        if (ordered_set_isempty(dns))
                 fputs("# No DNS servers known.\n", f);
         else {
                 DnsServer *s;
                 unsigned count = 0;
 
-                SET_FOREACH(s, dns, i)
+                ORDERED_SET_FOREACH(s, dns, i)
                         write_resolv_conf_server(s, f, &count);
         }
 
-        if (!set_isempty(domains)) {
+        if (!ordered_set_isempty(domains)) {
                 unsigned length = 0, count = 0;
                 char *domain;
 
                 fputs("search", f);
-                SET_FOREACH(domain, domains, i)
+                ORDERED_SET_FOREACH(domain, domains, i)
                         write_resolv_conf_search(domain, f, &count, &length);
                 fputs("\n", f);
         }
@@ -756,12 +760,11 @@ static int write_resolv_conf_contents(FILE *f, Set *dns, Set *domains) {
         return fflush_and_check(f);
 }
 
-
 int manager_write_resolv_conf(Manager *m) {
         static const char path[] = "/run/systemd/resolve/resolv.conf";
         _cleanup_free_ char *temp_path = NULL;
         _cleanup_fclose_ FILE *f = NULL;
-        _cleanup_set_free_ Set *dns = NULL, *domains = NULL;
+        _cleanup_ordered_set_free_ OrderedSet *dns = NULL, *domains = NULL;
         DnsServer *s;
         Iterator i;
         Link *l;
@@ -773,17 +776,17 @@ int manager_write_resolv_conf(Manager *m) {
         manager_read_resolv_conf(m);
 
         /* Add the full list to a set, to filter out duplicates */
-        dns = set_new(&dns_server_hash_ops);
+        dns = ordered_set_new(&dns_server_hash_ops);
         if (!dns)
                 return -ENOMEM;
 
-        domains = set_new(&dns_name_hash_ops);
+        domains = ordered_set_new(&dns_name_hash_ops);
         if (!domains)
                 return -ENOMEM;
 
         /* First add the system-wide servers */
         LIST_FOREACH(servers, s, m->dns_servers) {
-                r = set_put(dns, s);
+                r = ordered_set_put(dns, s);
                 if (r == -EEXIST)
                         continue;
                 if (r < 0)
@@ -795,7 +798,7 @@ int manager_write_resolv_conf(Manager *m) {
                 char **domain;
 
                 LIST_FOREACH(servers, s, l->dns_servers) {
-                        r = set_put(dns, s);
+                        r = ordered_set_put(dns, s);
                         if (r == -EEXIST)
                                 continue;
                         if (r < 0)
@@ -806,7 +809,7 @@ int manager_write_resolv_conf(Manager *m) {
                         continue;
 
                 STRV_FOREACH(domain, l->unicast_scope->domains) {
-                        r = set_put(domains, *domain);
+                        r = ordered_set_put(domains, *domain);
                         if (r == -EEXIST)
                                 continue;
                         if (r < 0)
@@ -815,9 +818,9 @@ int manager_write_resolv_conf(Manager *m) {
         }
 
         /* If we found nothing, add the fallback servers */
-        if (set_isempty(dns)) {
+        if (ordered_set_isempty(dns)) {
                 LIST_FOREACH(servers, s, m->fallback_dns_servers) {
-                        r = set_put(dns, s);
+                        r = ordered_set_put(dns, s);
                         if (r == -EEXIST)
                                 continue;
                         if (r < 0)
@@ -843,8 +846,8 @@ int manager_write_resolv_conf(Manager *m) {
         return 0;
 
 fail:
-        unlink(path);
-        unlink(temp_path);
+        (void) unlink(path);
+        (void) unlink(temp_path);
         return r;
 }
 

commit 4a280a7e78e633bd57cd1d5e6333d8fa29906e42
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Apr 8 17:22:15 2015 +0200

    util: add minimal OrderedSet type
    
    OrderedSet implements a Set-like structure, but maintains insertion
    ordered. It is hence to Set what OrderedHashmap is for Hashmap.
    
    Internally, this is only a wrapper around OrderedHashmap for now, but
    this could one day be improved and be added to hashmap.c natively.

diff --git a/Makefile.am b/Makefile.am
index a575af6..0a57389 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -792,6 +792,7 @@ libsystemd_shared_la_SOURCES = \
 	src/shared/siphash24.c \
 	src/shared/siphash24.h \
 	src/shared/set.h \
+	src/shared/ordered-set.h \
 	src/shared/fdset.c \
 	src/shared/fdset.h \
 	src/shared/prioq.c \
diff --git a/src/shared/ordered-set.h b/src/shared/ordered-set.h
new file mode 100644
index 0000000..766a1f2
--- /dev/null
+++ b/src/shared/ordered-set.h
@@ -0,0 +1,59 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+#pragma once
+
+/***
+  This file is part of systemd.
+
+  Copyright 2015 Lennart Poettering
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 2.1 of the License, or
+  (at your option) any later version.
+
+  systemd is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include "hashmap.h"
+
+typedef struct OrderedSet OrderedSet;
+
+static inline OrderedSet* ordered_set_new(const struct hash_ops *ops) {
+        return (OrderedSet*) ordered_hashmap_new(ops);
+}
+
+static inline OrderedSet* ordered_set_free(OrderedSet *s) {
+        ordered_hashmap_free((OrderedHashmap*) s);
+        return NULL;
+}
+
+static inline OrderedSet* ordered_set_free_free(OrderedSet *s) {
+        ordered_hashmap_free_free((OrderedHashmap*) s);
+        return NULL;
+}
+
+static inline int ordered_set_put(OrderedSet *s, void *p) {
+        return ordered_hashmap_put((OrderedHashmap*) s, p, p);
+}
+
+static inline bool ordered_set_isempty(OrderedSet *s) {
+        return ordered_hashmap_isempty((OrderedHashmap*) s);
+}
+
+static inline void *ordered_set_iterate(OrderedSet *s, Iterator *i) {
+        return ordered_hashmap_iterate((OrderedHashmap*) s, i, NULL);
+}
+
+#define ORDERED_SET_FOREACH(e, s, i)                                    \
+        for ((i) = ITERATOR_FIRST, (e) = ordered_set_iterate((s), &(i)); (e); (e) = ordered_set_iterate((s), &(i)))
+
+DEFINE_TRIVIAL_CLEANUP_FUNC(OrderedSet*, ordered_set_free);
+
+#define _cleanup_ordered_set_free_ _cleanup_(ordered_set_freep)



More information about the systemd-commits mailing list