[systemd-commits] 7 commits - .gitignore Makefile.am README TODO src/shared src/test

Lennart Poettering lennart at kemper.freedesktop.org
Wed Nov 14 13:28:24 PST 2012


 .gitignore                  |    1 
 Makefile.am                 |   14 ++++-
 README                      |    1 
 TODO                        |   18 +++++--
 src/shared/polkit.c         |    2 
 src/shared/replace-var.c    |  110 ++++++++++++++++++++++++++++++++++++++++++++
 src/shared/replace-var.h    |   24 +++++++++
 src/shared/specifier.c      |    9 ++-
 src/shared/util.c           |   50 ++++++++++++++++++++
 src/shared/util.h           |    2 
 src/test/test-replace-var.c |   46 ++++++++++++++++++
 11 files changed, 266 insertions(+), 11 deletions(-)

New commits:
commit e673ad0415d89c322e5b1a121e411f1b1d8075c0
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Nov 14 22:20:51 2012 +0100

    update TODO

diff --git a/TODO b/TODO
index 8ad5d5b..2488ee3 100644
--- a/TODO
+++ b/TODO
@@ -21,6 +21,14 @@ F18:
 
 Features:
 
+* add API to close/reopen/get fd for journal client fd in libsystemd-journal.
+
+* maybe add API to send pairs of iovecs via sd_journal_send
+
+* fallback to /dev/log based logging in libsystemd-journal, if we can't log natively?
+
+* declare the local journal protocol stable in the wiki interface chart
+
 * introduce ntp.service (or suchlike) as symlink that is used to arbitrate between various
   NTP implementations
 
@@ -28,6 +36,8 @@ Features:
 * journal: reuse XZ context
 * sd-journal: speed up sd_journal_get_data() with transparent hash table in bg
 
+* introduce ntp.service (or suchlike) as symlink that is used to arbitrate between various NTP implementations
+
 * timer units should get the ability to trigger when:
     - CLOCK_REALTIME makes jumps (TFD_TIMER_CANCEL_ON_SET)
     - DST changes

commit 6e6fb527f987d0c1f5bd930020301c9ac76a5e2c
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Nov 14 22:20:17 2012 +0100

    shared: add API for replacing @FOO@ style variables in strings

diff --git a/.gitignore b/.gitignore
index 94a8542..18e4e23 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+/test-replace-var
 /test-journal-enum
 /test-sleep
 /localectl
diff --git a/Makefile.am b/Makefile.am
index 452de15..53a3bb9 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -798,6 +798,8 @@ libsystemd_shared_la_SOURCES = \
 	src/shared/spawn-ask-password-agent.h \
 	src/shared/specifier.c \
 	src/shared/specifier.h \
+	src/shared/replace-var.c \
+	src/shared/replace-var.h \
 	src/shared/spawn-polkit-agent.c \
 	src/shared/spawn-polkit-agent.h \
 	src/shared/hwclock.c \
@@ -1182,7 +1184,8 @@ noinst_PROGRAMS += \
 	test-log \
 	test-unit-file \
 	test-date \
-	test-sleep
+	test-sleep \
+	test-replace-var
 
 TESTS += \
 	test-job-type \
@@ -1191,7 +1194,8 @@ TESTS += \
 	test-unit-name \
 	test-unit-file \
 	test-date \
-	test-sleep
+	test-sleep \
+	test-replace-var
 
 test_engine_SOURCES = \
 	src/test/test-engine.c
@@ -1265,6 +1269,12 @@ test_sleep_SOURCES = \
 test_sleep_LDADD = \
 	libsystemd-core.la
 
+test_replace_var_SOURCES = \
+	src/test/test-replace-var.c
+
+test_replace_var_LDADD = \
+	libsystemd-shared.la
+
 test_daemon_SOURCES = \
 	src/test/test-daemon.c
 
diff --git a/src/shared/replace-var.c b/src/shared/replace-var.c
new file mode 100644
index 0000000..e11c57a
--- /dev/null
+++ b/src/shared/replace-var.c
@@ -0,0 +1,110 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+  This file is part of systemd.
+
+  Copyright 2012 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 <string.h>
+
+#include "macro.h"
+#include "util.h"
+#include "replace-var.h"
+
+/*
+ * Generic infrastructure for replacing @FOO@ style variables in
+ * strings. Will call a callback for each replacement.
+ */
+
+static int get_variable(const char *b, char **r) {
+        size_t k;
+        char *t;
+
+        assert(b);
+        assert(r);
+
+        if (*b != '@')
+                return 0;
+
+        k = strspn(b + 1, "ABCDEFGHIJKLMNOPQRSTUVWXYZ_");
+        if (k <= 0 || b[k+1] != '@')
+                return 0;
+
+        t = strndup(b + 1, k);
+        if (!t)
+                return -ENOMEM;
+
+        *r = t;
+        return 1;
+}
+
+char *replace_var(const char *text, char *(*lookup)(const char *variable, void*userdata), void *userdata) {
+        char *r, *t;
+        const char *f;
+        size_t l;
+
+        assert(text);
+        assert(lookup);
+
+        l = strlen(text);
+        r = new(char, l+1);
+        if (!r)
+                return NULL;
+
+        f = text;
+        t = r;
+        while (*f) {
+                _cleanup_free_ char *v = NULL, *n = NULL;
+                char *a;
+                int k;
+                size_t skip, d, nl;
+
+                k = get_variable(f, &v);
+                if (k < 0)
+                        goto oom;
+                if (k == 0) {
+                        *(t++) = *(f++);
+                        continue;
+                }
+
+                n = lookup(v, userdata);
+                if (!n)
+                        goto oom;
+
+                skip = strlen(v) + 2;
+
+                d = t - r;
+                nl = l - skip + strlen(n);
+                a = realloc(r, nl + 1);
+                if (!a)
+                        goto oom;
+
+                l = nl;
+                r = a;
+                t = r + d;
+
+                t = stpcpy(t, n);
+                f += skip;
+        }
+
+        *t = 0;
+        return r;
+
+oom:
+        free(r);
+        return NULL;
+}
diff --git a/src/shared/replace-var.h b/src/shared/replace-var.h
new file mode 100644
index 0000000..7eaee93
--- /dev/null
+++ b/src/shared/replace-var.h
@@ -0,0 +1,24 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+#pragma once
+
+/***
+  This file is part of systemd.
+
+  Copyright 2012 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/>.
+***/
+
+char *replace_var(const char *text, char *(*lookup)(const char *variable, void*userdata), void *userdata);
diff --git a/src/test/test-replace-var.c b/src/test/test-replace-var.c
new file mode 100644
index 0000000..b1d42d7
--- /dev/null
+++ b/src/test/test-replace-var.c
@@ -0,0 +1,46 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+  This file is part of systemd.
+
+  Copyright 2012 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 <string.h>
+
+#include "util.h"
+#include "macro.h"
+#include "replace-var.h"
+
+static char *lookup(const char *variable, void *userdata) {
+        return strjoin("<<<", variable, ">>>", NULL);
+}
+
+int main(int argc, char *argv[]) {
+        char *r;
+
+        assert_se(r = replace_var("@@@foobar at xyz@HALLO at foobar@test@@testtest at TEST@...@@@", lookup, NULL));
+        puts(r);
+        assert_se(streq(r, "@@@foobar at xyz<<<HALLO>>>foobar at test@@testtest<<<TEST>>>...@@@"));
+        free(r);
+
+        assert_se(r = strreplace("XYZFFFFXYZFFFFXYZ", "XYZ", "ABC"));
+        puts(r);
+        assert_se(streq(r, "ABCFFFFABCFFFFABC"));
+        free(r);
+
+        return 0;
+}

commit 409bc9c33e99d5bb1e04d01bf3c75854d3a5dc7e
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Nov 14 22:16:23 2012 +0100

    util: add strreplace() to replace a substring by another string

diff --git a/src/shared/util.c b/src/shared/util.c
index 5a326ec..6d826b6 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -6163,3 +6163,53 @@ const char *draw_special_char(DrawSpecialChar ch) {
 
         return draw_table[!is_locale_utf8()][ch];
 }
+
+char *strreplace(const char *text, const char *old_string, const char *new_string) {
+        const char *f;
+        char *t, *r;
+        size_t l, old_len, new_len;
+
+        assert(text);
+        assert(old_string);
+        assert(new_string);
+
+        old_len = strlen(old_string);
+        new_len = strlen(new_string);
+
+        l = strlen(text);
+        r = new(char, l+1);
+        if (!r)
+                return NULL;
+
+        f = text;
+        t = r;
+        while (*f) {
+                char *a;
+                size_t d, nl;
+
+                if (!startswith(f, old_string)) {
+                        *(t++) = *(f++);
+                        continue;
+                }
+
+                d = t - r;
+                nl = l - old_len + new_len;
+                a = realloc(r, nl + 1);
+                if (!a)
+                        goto oom;
+
+                l = nl;
+                r = a;
+                t = r + d;
+
+                t = stpcpy(t, new_string);
+                f += old_len;
+        }
+
+        *t = 0;
+        return r;
+
+oom:
+        free(r);
+        return NULL;
+}
diff --git a/src/shared/util.h b/src/shared/util.h
index c2bed2a..a148ebb 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -611,3 +611,5 @@ typedef enum DrawSpecialChar {
         _DRAW_SPECIAL_CHAR_MAX
 } DrawSpecialChar;
 const char *draw_special_char(DrawSpecialChar ch);
+
+char *strreplace(const char *text, const char *old_string, const char *new_string);

commit 7ae03f3697762548e49abb6be5ae7151b1ab9365
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Nov 14 22:15:35 2012 +0100

    specifier: minor modernizations

diff --git a/src/shared/specifier.c b/src/shared/specifier.c
index ae00ae1..599027c 100644
--- a/src/shared/specifier.c
+++ b/src/shared/specifier.c
@@ -41,7 +41,8 @@ char *specifier_printf(const char *text, const Specifier table[], void *userdata
         assert(table);
 
         l = strlen(text);
-        if (!(r = new(char, l+1)))
+        r = new(char, l+1);
+        if (!r)
                 return NULL;
 
         t = r;
@@ -62,7 +63,8 @@ char *specifier_printf(const char *text, const Specifier table[], void *userdata
                                         char *n, *w;
                                         size_t k, j;
 
-                                        if (!(w = i->lookup(i->specifier, i->data, userdata))) {
+                                        w = i->lookup(i->specifier, i->data, userdata);
+                                        if (!w) {
                                                 free(r);
                                                 return NULL;
                                         }
@@ -70,7 +72,8 @@ char *specifier_printf(const char *text, const Specifier table[], void *userdata
                                         j = t - r;
                                         k = strlen(w);
 
-                                        if (!(n = new(char, j + k + l + 1))) {
+                                        n = new(char, j + k + l + 1);
+                                        if (!n) {
                                                 free(r);
                                                 free(w);
                                                 return NULL;

commit 02902965822816ec6fcc8a07d008802f17ca1e34
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Nov 14 22:14:53 2012 +0100

    polkit: fix type on comparison

diff --git a/src/shared/polkit.c b/src/shared/polkit.c
index 9ed6ff2..126096e 100644
--- a/src/shared/polkit.c
+++ b/src/shared/polkit.c
@@ -56,7 +56,7 @@ int verify_polkit(
                 return -EINVAL;
 
         ul = dbus_bus_get_unix_user(c, sender, error);
-        if (ul == (unsigned) -1)
+        if (ul == (unsigned long) -1)
                 return -EINVAL;
 
         /* Shortcut things for root, to avoid the PK roundtrip and dependency */

commit 7361c3b4e1e28a7eb4354a3da354b22e79782141
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Nov 14 22:14:17 2012 +0100

    TODO

diff --git a/TODO b/TODO
index 706dea8..8ad5d5b 100644
--- a/TODO
+++ b/TODO
@@ -24,6 +24,10 @@ Features:
 * introduce ntp.service (or suchlike) as symlink that is used to arbitrate between various
   NTP implementations
 
+* sd-journal: don't return fields > a threshold by default
+* journal: reuse XZ context
+* sd-journal: speed up sd_journal_get_data() with transparent hash table in bg
+
 * timer units should get the ability to trigger when:
     - CLOCK_REALTIME makes jumps (TFD_TIMER_CANCEL_ON_SET)
     - DST changes
@@ -47,8 +51,6 @@ Features:
   - find out what to do for blockdevs and skipping scsi modaliases
   - move writing code to src/libudev/libudev-hwdb-private.c
 
-* sd_journal_enumerate_data() implies XZ-decoding compressed field, this sucks hard
-
 * if booted in "quiet" mode, and an error happens, turn on status output again, so that the emergency mode isn't totally surprising
 
 * localectl: add listing support for X11 keymaps, by parsing /usr/share/X11/xkb/rules/xorg.lst
@@ -400,8 +402,6 @@ Features:
 
 * dbus: move dbus to early boot
 
-* journald: reuse XZ context
-
 * logind: add equivalent to sd_pid_get_owner_uid() to the D-Bus API
 
 * journal: deal nicely with byte-by-byte copied files, especially regards header

commit b603662c4152f9bbff3d93d69df0a4f4e05762c7
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Nov 14 22:13:54 2012 +0100

    README: don't list libgcrypt twice as dep

diff --git a/README b/README
index 7a85a4a..bcb4371 100644
--- a/README
+++ b/README
@@ -44,7 +44,6 @@ REQUIREMENTS:
         libkmod >= 5
         PAM >= 1.1.2 (optional)
         libcryptsetup (optional)
-        libgcrypt (optional)
         libaudit (optional)
         libacl (optional)
         libattr (optional)



More information about the systemd-commits mailing list