From aacf3b483b70b9a9ff16217f6376d143cbfe4636 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 16 Oct 2013 17:00:13 +0200 Subject: [PATCH] api: unify some common bits used by public systemd APIs --- Makefile.am | 4 +++- 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 +++- 6 files changed, 78 insertions(+), 51 deletions(-) create mode 100644 src/systemd/_sd-common.h 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 . +***/ + +/* 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 #include -#include +#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 . ***/ -#include +#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 +#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: * -- 2.7.4