[systemd-commits] 3 commits - Makefile.am src/libsystemd-bus src/systemd src/timedate

Lennart Poettering lennart at kemper.freedesktop.org
Wed Oct 16 08:01:34 PDT 2013


 Makefile.am                   |    4 ++-
 src/libsystemd-bus/bus-util.c |    2 -
 src/systemd/_sd-common.h      |   48 ++++++++++++++++++++++++++++++++++++++++++
 src/systemd/sd-bus.h          |   31 ++++++++-------------------
 src/systemd/sd-journal.h      |   40 +++++++++++------------------------
 src/systemd/sd-messages.h     |    2 -
 src/systemd/sd-shutdown.h     |    4 ++-
 src/timedate/timedated.c      |   32 +++++++++++++++++++++++++++-
 8 files changed, 110 insertions(+), 53 deletions(-)

New commits:
commit aacf3b483b70b9a9ff16217f6376d143cbfe4636
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Oct 16 17:00:13 2013 +0200

    api: unify some common bits used by public systemd APIs

diff --git a/Makefile.am b/Makefile.am
index ba27a34..3682893 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -2959,6 +2959,7 @@ test_catalog_LDADD = \
 libsystemd_journal_la_SOURCES = \
 	src/journal/sd-journal.c \
 	src/systemd/sd-journal.h \
+	src/systemd/_sd-common.h \
 	src/journal/journal-file.c \
 	src/journal/journal-file.h \
 	src/journal/journal-vacuum.c \
@@ -3122,7 +3123,8 @@ tests += \
 
 pkginclude_HEADERS += \
 	src/systemd/sd-journal.h \
-	src/systemd/sd-messages.h
+	src/systemd/sd-messages.h \
+	src/systemd/_sd-common.h
 
 lib_LTLIBRARIES += \
 	libsystemd-journal.la
diff --git a/src/systemd/_sd-common.h b/src/systemd/_sd-common.h
new file mode 100644
index 0000000..b861e33
--- /dev/null
+++ b/src/systemd/_sd-common.h
@@ -0,0 +1,48 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+#ifndef foosdcommonhfoo
+#define foosdcommonhfoo
+
+/***
+  This file is part of systemd.
+
+  Copyright 2013 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/>.
+***/
+
+/* This is a private header, never even think of including this directly! */
+
+#ifndef _sd_printf_
+#  if __GNUC__ >= 4
+#    define _sd_printf_(a,b) __attribute__ ((format (printf, a, b)))
+#  else
+#    define _sd_printf_(a,b)
+#  endif
+#endif
+
+#ifndef _sd_sentinel_
+#  define _sd_sentinel_ __attribute__((sentinel))
+#endif
+
+#ifndef _sd_packed_
+#  define _sd_packed_ __attribute__((packed))
+#endif
+
+#ifndef _sd_stringify
+#  define _sd_xstringify(x) #x
+#  define _sd_stringify(x) _sd_xstringify(x)
+#endif
+
+#endif
diff --git a/src/systemd/sd-bus.h b/src/systemd/sd-bus.h
index 4c2c06a..c36ea5a 100644
--- a/src/systemd/sd-bus.h
+++ b/src/systemd/sd-bus.h
@@ -28,23 +28,12 @@
 #include "sd-id128.h"
 #include "sd-event.h"
 #include "sd-memfd.h"
+#include "_sd-common.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-#ifndef _sd_printf_attr_
-#  if __GNUC__ >= 4
-#    define _sd_printf_attr_(a,b) __attribute__ ((format (printf, a, b)))
-#  else
-#    define _sd_printf_attr_(a,b)
-#  endif
-#endif
-
-#ifndef _sd_sentinel_attr_
-#  define _sd_sentinel_attr_ __attribute__((sentinel))
-#endif
-
 /* Types */
 
 typedef struct sd_bus sd_bus;
@@ -142,9 +131,9 @@ int sd_bus_message_new_signal(sd_bus *bus, const char *path, const char *interfa
 int sd_bus_message_new_method_call(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_message **m);
 int sd_bus_message_new_method_return(sd_bus *bus, sd_bus_message *call, sd_bus_message **m);
 int sd_bus_message_new_method_error(sd_bus *bus, sd_bus_message *call, const sd_bus_error *e, sd_bus_message **m);
-int sd_bus_message_new_method_errorf(sd_bus *bus, sd_bus_message *call, sd_bus_message **m, const char *name, const char *format, ...) _sd_printf_attr_(5, 0);
+int sd_bus_message_new_method_errorf(sd_bus *bus, sd_bus_message *call, sd_bus_message **m, const char *name, const char *format, ...) _sd_printf_(5, 0);
 int sd_bus_message_new_method_errno(sd_bus *bus, sd_bus_message *call, int error, const sd_bus_error *e, sd_bus_message **m);
-int sd_bus_message_new_method_errnof(sd_bus *bus, sd_bus_message *call, sd_bus_message **m, int error, const char *format, ...) _sd_printf_attr_(5, 0);
+int sd_bus_message_new_method_errnof(sd_bus *bus, sd_bus_message *call, sd_bus_message **m, int error, const char *format, ...) _sd_printf_(5, 0);
 
 sd_bus_message* sd_bus_message_ref(sd_bus_message *m);
 sd_bus_message* sd_bus_message_unref(sd_bus_message *m);
@@ -217,19 +206,19 @@ int sd_bus_get_property(sd_bus *bus, const char *destination, const char *path,
 int sd_bus_set_property(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *error, const char *type, ...);
 int sd_bus_reply_method_return(sd_bus *bus, sd_bus_message *call, const char *types, ...);
 int sd_bus_reply_method_error(sd_bus *bus, sd_bus_message *call, const sd_bus_error *e);
-int sd_bus_reply_method_errorf(sd_bus *bus, sd_bus_message *call, const char *name, const char *format, ...) _sd_printf_attr_(4, 0);
+int sd_bus_reply_method_errorf(sd_bus *bus, sd_bus_message *call, const char *name, const char *format, ...) _sd_printf_(4, 0);
 int sd_bus_reply_method_errno(sd_bus *bus, sd_bus_message *call, int error, const sd_bus_error *e);
-int sd_bus_reply_method_errnof(sd_bus *bus, sd_bus_message *call, int error, const char *format, ...) _sd_printf_attr_(4, 0);
+int sd_bus_reply_method_errnof(sd_bus *bus, sd_bus_message *call, int error, const char *format, ...) _sd_printf_(4, 0);
 
 int sd_bus_emit_signal(sd_bus *bus, const char *path, const char *interface, const char *member, const char *types, ...);
 
 int sd_bus_emit_properties_changed_strv(sd_bus *bus, const char *path, const char *interface, char **names);
-int sd_bus_emit_properties_changed(sd_bus *bus, const char *path, const char *interface, const char *name, ...) _sd_sentinel_attr_;
+int sd_bus_emit_properties_changed(sd_bus *bus, const char *path, const char *interface, const char *name, ...) _sd_sentinel_;
 
 int sd_bus_emit_interfaces_added_strv(sd_bus *bus, const char *path, char **interfaces);
-int sd_bus_emit_interfaces_added(sd_bus *bus, const char *path, const char *interface, ...) _sd_sentinel_attr_;
+int sd_bus_emit_interfaces_added(sd_bus *bus, const char *path, const char *interface, ...) _sd_sentinel_;
 int sd_bus_emit_interfaces_removed_strv(sd_bus *bus, const char *path, char **interfaces);
-int sd_bus_emit_interfaces_removed(sd_bus *bus, const char *path, const char *interface, ...) _sd_sentinel_attr_;
+int sd_bus_emit_interfaces_removed(sd_bus *bus, const char *path, const char *interface, ...) _sd_sentinel_;
 
 /* Bus management */
 
@@ -249,10 +238,10 @@ int sd_bus_get_owner_machine_id(sd_bus *bus, const char *name, sd_id128_t *machi
 
 void sd_bus_error_free(sd_bus_error *e);
 int sd_bus_error_set(sd_bus_error *e, const char *name, const char *message);
-int sd_bus_error_setf(sd_bus_error *e, const char *name, const char *format, ...)  _sd_printf_attr_(3, 0);
+int sd_bus_error_setf(sd_bus_error *e, const char *name, const char *format, ...)  _sd_printf_(3, 0);
 int sd_bus_error_set_const(sd_bus_error *e, const char *name, const char *message);
 int sd_bus_error_set_errno(sd_bus_error *e, int error);
-int sd_bus_error_set_errnof(sd_bus_error *e, int error, const char *format, ...) _sd_printf_attr_(3, 0);
+int sd_bus_error_set_errnof(sd_bus_error *e, int error, const char *format, ...) _sd_printf_(3, 0);
 int sd_bus_error_get_errno(const sd_bus_error *e);
 int sd_bus_error_copy(sd_bus_error *dest, const sd_bus_error *e);
 int sd_bus_error_is_set(const sd_bus_error *e);
diff --git a/src/systemd/sd-journal.h b/src/systemd/sd-journal.h
index 887fd30..a10a54e 100644
--- a/src/systemd/sd-journal.h
+++ b/src/systemd/sd-journal.h
@@ -28,51 +28,37 @@
 #include <sys/uio.h>
 #include <syslog.h>
 
-#include <systemd/sd-id128.h>
+#include "sd-id128.h"
+#include "_sd-common.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-#ifndef _sd_printf_attr_
-#  if __GNUC__ >= 4
-#    define _sd_printf_attr_(a,b) __attribute__ ((format (printf, a, b)))
-#  else
-#    define _sd_printf_attr_(a,b)
-#  endif
-#endif
-
-#ifndef _sd_sentinel_attr_
-#  define _sd_sentinel_attr_ __attribute__((sentinel))
-#endif
-
 /* Journal APIs. See sd-journal(3) for more information. */
 
 /* Write to daemon */
-int sd_journal_print(int priority, const char *format, ...) _sd_printf_attr_(2, 3);
-int sd_journal_printv(int priority, const char *format, va_list ap) _sd_printf_attr_(2, 0);
-int sd_journal_send(const char *format, ...) _sd_printf_attr_(1, 0) _sd_sentinel_attr_;
+int sd_journal_print(int priority, const char *format, ...) _sd_printf_(2, 3);
+int sd_journal_printv(int priority, const char *format, va_list ap) _sd_printf_(2, 0);
+int sd_journal_send(const char *format, ...) _sd_printf_(1, 0) _sd_sentinel_;
 int sd_journal_sendv(const struct iovec *iov, int n);
 int sd_journal_perror(const char *message);
 
 /* Used by the macros below. Don't call this directly. */
-int sd_journal_print_with_location(int priority, const char *file, const char *line, const char *func, const char *format, ...) _sd_printf_attr_(5, 6);
-int sd_journal_printv_with_location(int priority, const char *file, const char *line, const char *func, const char *format, va_list ap) _sd_printf_attr_(5, 0);
-int sd_journal_send_with_location(const char *file, const char *line, const char *func, const char *format, ...) _sd_printf_attr_(4, 0) _sd_sentinel_attr_;
+int sd_journal_print_with_location(int priority, const char *file, const char *line, const char *func, const char *format, ...) _sd_printf_(5, 6);
+int sd_journal_printv_with_location(int priority, const char *file, const char *line, const char *func, const char *format, va_list ap) _sd_printf_(5, 0);
+int sd_journal_send_with_location(const char *file, const char *line, const char *func, const char *format, ...) _sd_printf_(4, 0) _sd_sentinel_;
 int sd_journal_sendv_with_location(const char *file, const char *line, const char *func, const struct iovec *iov, int n);
 int sd_journal_perror_with_location(const char *file, const char *line, const char *func, const char *message);
 
 /* implicitly add code location to messages sent, if this is enabled */
 #ifndef SD_JOURNAL_SUPPRESS_LOCATION
 
-#define _sd_XSTRINGIFY(x) #x
-#define _sd_STRINGIFY(x) _sd_XSTRINGIFY(x)
-
-#define sd_journal_print(priority, ...) sd_journal_print_with_location(priority, "CODE_FILE=" __FILE__, "CODE_LINE=" _sd_STRINGIFY(__LINE__), __func__, __VA_ARGS__)
-#define sd_journal_printv(priority, format, ap) sd_journal_printv_with_location(priority, "CODE_FILE=" __FILE__, "CODE_LINE=" _sd_STRINGIFY(__LINE__), __func__, format, ap)
-#define sd_journal_send(...) sd_journal_send_with_location("CODE_FILE=" __FILE__, "CODE_LINE=" _sd_STRINGIFY(__LINE__), __func__, __VA_ARGS__)
-#define sd_journal_sendv(iovec, n) sd_journal_sendv_with_location("CODE_FILE=" __FILE__, "CODE_LINE=" _sd_STRINGIFY(__LINE__), __func__, iovec, n)
-#define sd_journal_perror(message) sd_journal_perror_with_location("CODE_FILE=" __FILE__, "CODE_LINE=" _sd_STRINGIFY(__LINE__), __func__, message)
+#define sd_journal_print(priority, ...) sd_journal_print_with_location(priority, "CODE_FILE=" __FILE__, "CODE_LINE=" _sd_stringify(__LINE__), __func__, __VA_ARGS__)
+#define sd_journal_printv(priority, format, ap) sd_journal_printv_with_location(priority, "CODE_FILE=" __FILE__, "CODE_LINE=" _sd_stringify(__LINE__), __func__, format, ap)
+#define sd_journal_send(...) sd_journal_send_with_location("CODE_FILE=" __FILE__, "CODE_LINE=" _sd_stringify(__LINE__), __func__, __VA_ARGS__)
+#define sd_journal_sendv(iovec, n) sd_journal_sendv_with_location("CODE_FILE=" __FILE__, "CODE_LINE=" _sd_stringify(__LINE__), __func__, iovec, n)
+#define sd_journal_perror(message) sd_journal_perror_with_location("CODE_FILE=" __FILE__, "CODE_LINE=" _sd_stringify(__LINE__), __func__, message)
 
 #endif
 
diff --git a/src/systemd/sd-messages.h b/src/systemd/sd-messages.h
index c811a06..775aa23 100644
--- a/src/systemd/sd-messages.h
+++ b/src/systemd/sd-messages.h
@@ -22,7 +22,7 @@
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <systemd/sd-id128.h>
+#include "sd-id128.h"
 
 #ifdef __cplusplus
 extern "C" {
diff --git a/src/systemd/sd-shutdown.h b/src/systemd/sd-shutdown.h
index b8f6a48..6698c8c 100644
--- a/src/systemd/sd-shutdown.h
+++ b/src/systemd/sd-shutdown.h
@@ -26,6 +26,8 @@
 
 #include <inttypes.h>
 
+#include "_sd-common.h"
+
 typedef enum sd_shutdown_mode {
         SD_SHUTDOWN_NONE = 0,
         SD_SHUTDOWN_REBOOT = 'r',
@@ -55,7 +57,7 @@ struct sd_shutdown_command {
         /* The wall message to send around. Leave empty for the
          * default wall message */
         char wall_message[];
-} __attribute__((packed));
+} _sd_packed_;
 
 /* The scheme is very simple:
  *

commit 6fc60278a9de47f40a31acf4d0acb08d2500382d
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Oct 16 16:57:49 2013 +0200

    timedate: expose RTC time
    
    Since access to the RTC is privileged expose the current RTC time as bus
    property so that unprivileged clients can read it.

diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c
index 7b22b20..16e24c1 100644
--- a/src/timedate/timedated.c
+++ b/src/timedate/timedated.c
@@ -452,6 +452,35 @@ static int context_enable_ntp(Context*c, sd_bus *bus, sd_bus_error *error) {
         return -ENOTSUP;
 }
 
+static int property_get_rtc_time(
+                sd_bus *bus,
+                const char *path,
+                const char *interface,
+                const char *property,
+                sd_bus_message *reply,
+                sd_bus_error *error,
+                void *userdata) {
+
+        struct tm tm;
+        usec_t t;
+        int r;
+
+        zero(tm);
+        r = hwclock_get_time(&tm);
+        if (r < 0) {
+                sd_bus_error_set_errnof(error, -r, "Failed to read RTC: %s", strerror(-r));
+                return r;
+        }
+
+        t = (usec_t) mktime(&tm) * USEC_PER_SEC;
+
+        r = sd_bus_message_append(reply, "t", t);
+        if (r < 0)
+                return r;
+
+        return 1;
+}
+
 static int method_set_timezone(sd_bus *bus, sd_bus_message *m, void *userdata) {
         _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
         Context *c = userdata;
@@ -474,7 +503,7 @@ static int method_set_timezone(sd_bus *bus, sd_bus_message *m, void *userdata) {
         if (r < 0)
                 return sd_bus_reply_method_errno(bus, m, r, &error);
         if (r == 0)
-                return 1;
+                return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
 
         t = strdup(z);
         if (!t)
@@ -706,6 +735,7 @@ static const sd_bus_vtable timedate_vtable[] = {
         SD_BUS_PROPERTY("LocalRTC", "b", NULL, offsetof(Context, local_rtc), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
         SD_BUS_PROPERTY("CanNTP", "b", bus_property_get_tristate, offsetof(Context, can_ntp), 0),
         SD_BUS_PROPERTY("NTP", "b", bus_property_get_tristate, offsetof(Context, use_ntp), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
+        SD_BUS_PROPERTY("RTCTimeUSec", "t", property_get_rtc_time, 0, 0),
         SD_BUS_METHOD("SetTime", "xbb", NULL, method_set_time, 0),
         SD_BUS_METHOD("SetTimezone", "sb", NULL, method_set_timezone, 0),
         SD_BUS_METHOD("SetLocalRTC", "bbb", NULL, method_set_local_rtc, 0),

commit d16dd6d42a28a5d7c335ede979c3d426cd4656f5
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Oct 16 16:55:01 2013 +0200

    bus: fix default exit on idle timeout

diff --git a/src/libsystemd-bus/bus-util.c b/src/libsystemd-bus/bus-util.c
index 5a70fae..b77ae91 100644
--- a/src/libsystemd-bus/bus-util.c
+++ b/src/libsystemd-bus/bus-util.c
@@ -81,7 +81,7 @@ int bus_event_loop_with_idle(sd_event *e, sd_bus *bus, const char *name, usec_t
                 if (r == SD_EVENT_FINISHED)
                         break;
 
-                r = sd_event_run(e, exiting ? (uint64_t) -1 : 5 * USEC_PER_SEC /* DEFAULT_EXIT_USEC */);
+                r = sd_event_run(e, exiting ? (uint64_t) -1 : DEFAULT_EXIT_USEC);
                 if (r < 0)
                         return r;
 



More information about the systemd-commits mailing list