[systemd-commits] 3 commits - src/libsystemd-bus src/timedate

Lennart Poettering lennart at kemper.freedesktop.org
Thu Dec 12 11:00:56 PST 2013


 src/libsystemd-bus/bus-internal.h       |    1 
 src/libsystemd-bus/bus-kernel.c         |    1 
 src/libsystemd-bus/bus-message.c        |    3 +-
 src/libsystemd-bus/bus-message.h        |    2 -
 src/libsystemd-bus/bus-socket.c         |    1 
 src/libsystemd-bus/sd-bus.c             |   42 +++++++++++++++++---------------
 src/libsystemd-bus/test-bus-gvariant.c  |    4 +--
 src/libsystemd-bus/test-bus-marshal.c   |    4 +--
 src/libsystemd-bus/test-bus-match.c     |    2 -
 src/libsystemd-bus/test-bus-zero-copy.c |    2 -
 src/timedate/timedatectl.c              |   40 ++++++++++++++++++++----------
 11 files changed, 62 insertions(+), 40 deletions(-)

New commits:
commit 3df7a7e610eece1362d0ab148f3d92b2c98277a1
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu Dec 12 20:00:19 2013 +0100

    bus: always pass valid timeout to kdbus

diff --git a/src/libsystemd-bus/bus-message.c b/src/libsystemd-bus/bus-message.c
index 0f19ee2..a86cd9a 100644
--- a/src/libsystemd-bus/bus-message.c
+++ b/src/libsystemd-bus/bus-message.c
@@ -2695,7 +2695,7 @@ static int bus_message_close_header(sd_bus_message *m) {
         return 0;
 }
 
-int bus_message_seal(sd_bus_message *m, uint64_t serial) {
+int bus_message_seal(sd_bus_message *m, uint64_t serial, usec_t timeout) {
         struct bus_body_part *part;
         size_t l, a;
         unsigned i;
@@ -2742,6 +2742,7 @@ int bus_message_seal(sd_bus_message *m, uint64_t serial) {
                 return r;
 
         m->header->serial = serial;
+        m->timeout = m->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED ? 0 : timeout;
 
         /* Add padding at the end of the fields part, since we know
          * the body needs to start at an 8 byte alignment. We made
diff --git a/src/libsystemd-bus/bus-message.h b/src/libsystemd-bus/bus-message.h
index 75a560b..b9cd4c8 100644
--- a/src/libsystemd-bus/bus-message.h
+++ b/src/libsystemd-bus/bus-message.h
@@ -185,7 +185,7 @@ static inline bool BUS_MESSAGE_IS_GVARIANT(sd_bus_message *m) {
         return m->header->version == 2;
 }
 
-int bus_message_seal(sd_bus_message *m, uint64_t serial);
+int bus_message_seal(sd_bus_message *m, uint64_t serial, usec_t timeout);
 int bus_message_get_blob(sd_bus_message *m, void **buffer, size_t *sz);
 int bus_message_read_strv_extend(sd_bus_message *m, char ***l);
 
diff --git a/src/libsystemd-bus/sd-bus.c b/src/libsystemd-bus/sd-bus.c
index 1a60356..060dcc1 100644
--- a/src/libsystemd-bus/sd-bus.c
+++ b/src/libsystemd-bus/sd-bus.c
@@ -1276,7 +1276,7 @@ _public_ int sd_bus_get_server_id(sd_bus *bus, sd_id128_t *server_id) {
         return 0;
 }
 
-static int bus_seal_message(sd_bus *b, sd_bus_message *m) {
+static int bus_seal_message(sd_bus *b, sd_bus_message *m, usec_t timeout) {
         assert(b);
         assert(m);
 
@@ -1296,7 +1296,10 @@ static int bus_seal_message(sd_bus *b, sd_bus_message *m) {
                 return 0;
         }
 
-        return bus_message_seal(m, ++b->serial);
+        if (timeout == 0)
+                timeout = BUS_DEFAULT_TIMEOUT;
+
+        return bus_message_seal(m, ++b->serial, timeout);
 }
 
 int bus_seal_synthetic_message(sd_bus *b, sd_bus_message *m) {
@@ -1311,7 +1314,7 @@ int bus_seal_synthetic_message(sd_bus *b, sd_bus_message *m) {
          * than (uint64_t) -1 since dbus1 only had 32bit identifiers,
          * even though kdbus can do 64bit. */
 
-        return bus_message_seal(m, 0xFFFFFFFFULL);
+        return bus_message_seal(m, 0xFFFFFFFFULL, 0);
 }
 
 static int bus_write_message(sd_bus *bus, sd_bus_message *message, size_t *idx) {
@@ -1441,7 +1444,7 @@ _public_ int sd_bus_send(sd_bus *bus, sd_bus_message *m, uint64_t *serial) {
         if (!serial && !m->sealed)
                 m->header->flags |= BUS_MESSAGE_NO_REPLY_EXPECTED;
 
-        r = bus_seal_message(bus, m);
+        r = bus_seal_message(bus, m, 0);
         if (r < 0)
                 return r;
 
@@ -1516,9 +1519,6 @@ static usec_t calc_elapse(uint64_t usec) {
         if (usec == (uint64_t) -1)
                 return 0;
 
-        if (usec == 0)
-                usec = BUS_DEFAULT_TIMEOUT;
-
         return now(CLOCK_MONOTONIC) + usec;
 }
 
@@ -1563,13 +1563,11 @@ _public_ int sd_bus_call_async(
         if (r < 0)
                 return r;
 
-        if (usec != (uint64_t) -1) {
-                r = prioq_ensure_allocated(&bus->reply_callbacks_prioq, timeout_compare);
-                if (r < 0)
-                        return r;
-        }
+        r = prioq_ensure_allocated(&bus->reply_callbacks_prioq, timeout_compare);
+        if (r < 0)
+                return r;
 
-        r = bus_seal_message(bus, m);
+        r = bus_seal_message(bus, m, usec);
         if (r < 0)
                 return r;
 
@@ -1580,7 +1578,7 @@ _public_ int sd_bus_call_async(
         c->callback = callback;
         c->userdata = userdata;
         c->serial = BUS_MESSAGE_SERIAL(m);
-        c->timeout = calc_elapse(usec);
+        c->timeout = calc_elapse(m->timeout);
 
         r = hashmap_put(bus->reply_callbacks, &c->serial, c);
         if (r < 0) {
@@ -1675,11 +1673,15 @@ _public_ int sd_bus_call(
 
         i = bus->rqueue_size;
 
+        r = bus_seal_message(bus, m, usec);
+        if (r < 0)
+                return r;
+
         r = sd_bus_send(bus, m, &serial);
         if (r < 0)
                 return r;
 
-        timeout = calc_elapse(usec);
+        timeout = calc_elapse(m->timeout);
 
         for (;;) {
                 usec_t left;
diff --git a/src/libsystemd-bus/test-bus-gvariant.c b/src/libsystemd-bus/test-bus-gvariant.c
index 7ceeb81..de9f001 100644
--- a/src/libsystemd-bus/test-bus-gvariant.c
+++ b/src/libsystemd-bus/test-bus-gvariant.c
@@ -145,7 +145,7 @@ static void test_marshal(void) {
                                         4711, "first-string-parameter", "(st)", "X", (uint64_t) 1111,
                                         4712, "second-string-parameter", "(a(si))", 2, "Y", 5, "Z", 6) >= 0);
 
-        assert_se(bus_message_seal(m, 4711) >= 0);
+        assert_se(bus_message_seal(m, 4711, 0) >= 0);
 
 #ifdef HAVE_GLIB
         {
@@ -185,7 +185,7 @@ static void test_marshal(void) {
 
         assert_se(sd_bus_message_append(m, "as", 0) >= 0);
 
-        assert_se(bus_message_seal(m, 4712) >= 0);
+        assert_se(bus_message_seal(m, 4712, 0) >= 0);
         assert_se(bus_message_dump(m, NULL, true) >= 0);
 }
 
diff --git a/src/libsystemd-bus/test-bus-marshal.c b/src/libsystemd-bus/test-bus-marshal.c
index 79d6939..069b084 100644
--- a/src/libsystemd-bus/test-bus-marshal.c
+++ b/src/libsystemd-bus/test-bus-marshal.c
@@ -119,7 +119,7 @@ int main(int argc, char *argv[]) {
         r = sd_bus_message_append_array(m, 'u', NULL, 0);
         assert_se(r >= 0);
 
-        r = bus_message_seal(m, 4711);
+        r = bus_message_seal(m, 4711, 0);
         assert_se(r >= 0);
 
         bus_message_dump(m, stdout, true);
@@ -253,7 +253,7 @@ int main(int argc, char *argv[]) {
         r = sd_bus_message_copy(copy, m, true);
         assert_se(r >= 0);
 
-        r = bus_message_seal(copy, 4712);
+        r = bus_message_seal(copy, 4712, 0);
         assert_se(r >= 0);
 
         fclose(ms);
diff --git a/src/libsystemd-bus/test-bus-match.c b/src/libsystemd-bus/test-bus-match.c
index af42f0b..25d2b92 100644
--- a/src/libsystemd-bus/test-bus-match.c
+++ b/src/libsystemd-bus/test-bus-match.c
@@ -113,7 +113,7 @@ int main(int argc, char *argv[]) {
 
         assert_se(sd_bus_message_new_signal(NULL, "/foo/bar", "bar.x", "waldo", &m) >= 0);
         assert_se(sd_bus_message_append(m, "ssss", "one", "two", "/prefix/three", "prefix.four") >= 0);
-        assert_se(bus_message_seal(m, 1) >= 0);
+        assert_se(bus_message_seal(m, 1, 0) >= 0);
 
         zero(mask);
         assert_se(bus_match_run(NULL, &root, m) == 0);
diff --git a/src/libsystemd-bus/test-bus-zero-copy.c b/src/libsystemd-bus/test-bus-zero-copy.c
index 0b72fe5..07ccbc3 100644
--- a/src/libsystemd-bus/test-bus-zero-copy.c
+++ b/src/libsystemd-bus/test-bus-zero-copy.c
@@ -133,7 +133,7 @@ int main(int argc, char *argv[]) {
         r = sd_bus_message_append(m, "u", 4711);
         assert_se(r >= 0);
 
-        r = bus_message_seal(m, 55);
+        r = bus_message_seal(m, 55, 0);
         assert_se(r >= 0);
 
         bus_message_dump(m, stdout, true);

commit 0f437184b687af58c5c4b2e3201a83d98485b0e4
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu Dec 12 19:58:46 2013 +0100

    bus: enforce endianess and marshalling for messages we send

diff --git a/src/libsystemd-bus/bus-internal.h b/src/libsystemd-bus/bus-internal.h
index 1be7488..df9a0b5 100644
--- a/src/libsystemd-bus/bus-internal.h
+++ b/src/libsystemd-bus/bus-internal.h
@@ -147,6 +147,7 @@ struct sd_bus {
         enum bus_state state;
         int input_fd, output_fd;
         int message_version;
+        int message_endian;
 
         bool is_kernel:1;
         bool can_fds:1;
diff --git a/src/libsystemd-bus/bus-kernel.c b/src/libsystemd-bus/bus-kernel.c
index c5817a7..68d0f48 100644
--- a/src/libsystemd-bus/bus-kernel.c
+++ b/src/libsystemd-bus/bus-kernel.c
@@ -363,6 +363,7 @@ int bus_kernel_take_fd(sd_bus *b) {
         b->bus_client = true;
         b->can_fds = !!(hello.conn_flags & KDBUS_HELLO_ACCEPT_FD);
         b->message_version = 2;
+        b->message_endian = BUS_NATIVE_ENDIAN;
 
         /* the kernel told us the UUID of the underlying bus */
         memcpy(b->server_id.bytes, hello.id128, sizeof(b->server_id.bytes));
diff --git a/src/libsystemd-bus/bus-socket.c b/src/libsystemd-bus/bus-socket.c
index a449ce0..1365092 100644
--- a/src/libsystemd-bus/bus-socket.c
+++ b/src/libsystemd-bus/bus-socket.c
@@ -625,6 +625,7 @@ int bus_socket_setup(sd_bus *b) {
 
         b->is_kernel = false;
         b->message_version = 1;
+        b->message_endian = 0;
 
         return 0;
 }
diff --git a/src/libsystemd-bus/sd-bus.c b/src/libsystemd-bus/sd-bus.c
index 37408cf..1a60356 100644
--- a/src/libsystemd-bus/sd-bus.c
+++ b/src/libsystemd-bus/sd-bus.c
@@ -1280,7 +1280,12 @@ static int bus_seal_message(sd_bus *b, sd_bus_message *m) {
         assert(b);
         assert(m);
 
-        if (m->header->version > b->message_version)
+        if (b->message_version != 0 &&
+            m->header->version != b->message_version)
+                return -EPERM;
+
+        if (b->message_endian != 0 &&
+            m->header->endian != b->message_endian)
                 return -EPERM;
 
         if (m->sealed) {
@@ -1298,9 +1303,6 @@ int bus_seal_synthetic_message(sd_bus *b, sd_bus_message *m) {
         assert(b);
         assert(m);
 
-        if (m->header->version > b->message_version)
-                return -EPERM;
-
         /* The bus specification says the serial number cannot be 0,
          * hence let's fill something in for synthetic messages. Since
          * synthetic messages might have a fake sender and we don't

commit 9ff09bcb86fb125768667aca9bc0b10b1745370a
Author: Shawn Landden <shawn at churchofgit.com>
Date:   Thu Dec 12 10:00:03 2013 -0800

    timedatectl: work with old timedated
    
    Which does have TimeUSec. Should we specifically check for this method
    instead of assuming time=0 means it doesn't exist?
    
    Before:
    shawn at debian-T61:~/git/systemd$ ./timedatectl
          Local time: Wed 1969-12-31 16:00:00 PST
      Universal time: Thu 1970-01-01 00:00:00 UTC
            RTC time: n/a
            Timezone: America/Los_Angeles (PST, -0800)
         NTP enabled: n/a
    NTP synchronized: no
     RTC in local TZ: no
          DST active: no
     Last DST change: DST ended at
                      Sun 1969-10-26 01:59:59 PDT
                      Sun 1969-10-26 01:00:00 PST
     Next DST change: DST begins (the clock jumps one hour forward) at
                      Sun 1970-04-26 01:59:59 PST
                      Sun 1970-04-26 03:00:00 PDT
    
    After:
    shawn at debian-T61:~/git/systemd$ ./timedatectl
          Local time: Wed 2013-12-11 14:03:21 PST
      Universal time: Wed 2013-12-11 22:03:21 UTC
            RTC time: n/a
            Timezone: America/Los_Angeles (PST, -0800)
         NTP enabled: n/a
    NTP synchronized: no
     RTC in local TZ: no
          DST active: no
     Last DST change: DST ended at
                      Sun 2013-11-03 01:59:59 PDT
                      Sun 2013-11-03 01:00:00 PST
     Next DST change: DST begins (the clock jumps one hour forward) at
                      Sun 2014-03-09 01:59:59 PST
                      Sun 2014-03-09 03:00:00 PDT

diff --git a/src/timedate/timedatectl.c b/src/timedate/timedatectl.c
index 9b81513..2c24b78 100644
--- a/src/timedate/timedatectl.c
+++ b/src/timedate/timedatectl.c
@@ -98,6 +98,7 @@ static void print_status_info(const StatusInfo *i) {
         char s[32];
         struct tm tm;
         time_t sec;
+        bool have_time = false;
         char *zc, *zn;
         time_t t, tc, tn;
         int dn;
@@ -112,17 +113,29 @@ static void print_status_info(const StatusInfo *i) {
                 unsetenv("TZ");
         }
 
-        sec = (time_t) (i->time / USEC_PER_SEC);
+        if (i->time != 0) {
+                sec = (time_t) (i->time / USEC_PER_SEC);
+                have_time = true;
+        } else if (arg_transport == BUS_TRANSPORT_LOCAL) {
+                sec = time(NULL);
+                have_time = true;
+        } else
+                fprintf(stderr, "Warning: could not get time from timedated and not operating locally.\n\n");
 
-        zero(tm);
-        assert_se(strftime(a, sizeof(a), "%a %Y-%m-%d %H:%M:%S %Z", localtime_r(&sec, &tm)) > 0);
-        char_array_0(a);
-        printf("      Local time: %s\n", a);
+        if (have_time) {
+                zero(tm);
+                assert_se(strftime(a, sizeof(a), "%a %Y-%m-%d %H:%M:%S %Z", localtime_r(&sec, &tm)) > 0);
+                char_array_0(a);
+                printf("      Local time: %s\n", a);
 
-        zero(tm);
-        assert_se(strftime(a, sizeof(a), "%a %Y-%m-%d %H:%M:%S UTC", gmtime_r(&sec, &tm)) > 0);
-        char_array_0(a);
-        printf("  Universal time: %s\n", a);
+                zero(tm);
+                assert_se(strftime(a, sizeof(a), "%a %Y-%m-%d %H:%M:%S UTC", gmtime_r(&sec, &tm)) > 0);
+                char_array_0(a);
+                printf("  Universal time: %s\n", a);
+        } else {
+                printf("      Local time: %s\n", "n/a");
+                printf("  Universal time: %s\n", "n/a");
+        }
 
         if (i->rtc_time > 0) {
                 time_t rtc_sec;
@@ -133,7 +146,7 @@ static void print_status_info(const StatusInfo *i) {
                 char_array_0(a);
                 printf("        RTC time: %s\n", a);
         } else
-                printf("        RTC time: n/a\n");
+                printf("        RTC time: %s\n", "n/a");
 
         zero(tm);
         assert_se(strftime(a, sizeof(a), "%Z, %z", localtime_r(&sec, &tm)) > 0);
@@ -151,8 +164,8 @@ static void print_status_info(const StatusInfo *i) {
                          &tc, &zc, &is_dstc,
                          &tn, &dn, &zn, &is_dstn);
         if (r < 0)
-                printf("      DST active: n/a\n");
-        else {
+                printf("      DST active: %s\n", "n/a");
+        else if (have_time) {
                 printf("      DST active: %s\n", yes_no(is_dstc));
 
                 t = tc - 1;
@@ -183,7 +196,8 @@ static void print_status_info(const StatusInfo *i) {
 
                 free(zc);
                 free(zn);
-        }
+        } else
+                printf("      DST active: %s\n", yes_no(is_dstc));
 
         if (i->rtc_local)
                 fputs("\n" ANSI_HIGHLIGHT_ON



More information about the systemd-commits mailing list