diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-11-27 19:13:45 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-11-27 19:19:36 +0100 |
commit | 4afd3348c7506dd1d36305b7bcb9feb8952b9d6b (patch) | |
tree | 778068851852e18794eb3351d0cb250cd3911f10 /src/journal | |
parent | f5edf80e297e4ba499db57779af2f121922f372a (diff) |
tree-wide: expose "p"-suffix unref calls in public APIs to make gcc cleanup easy
GLIB has recently started to officially support the gcc cleanup
attribute in its public API, hence let's do the same for our APIs.
With this patch we'll define an xyz_unrefp() call for each public
xyz_unref() call, to make it easy to use inside a
__attribute__((cleanup())) expression. Then, all code is ported over to
make use of this.
The new calls are also documented in the man pages, with examples how to
use them (well, I only added docs where the _unref() call itself already
had docs, and the examples, only cover sd_bus_unrefp() and
sd_event_unrefp()).
This also renames sd_lldp_free() to sd_lldp_unref(), since that's how we
tend to call our destructors these days.
Note that this defines no public macro that wraps gcc's attribute and
makes it easier to use. While I think it's our duty in the library to
make our stuff easy to use, I figure it's not our duty to make gcc's own
features easy to use on its own. Most likely, client code which wants to
make use of this should define its own:
#define _cleanup_(function) __attribute__((cleanup(function)))
Or similar, to make the gcc feature easier to use.
Making this logic public has the benefit that we can remove three header
files whose only purpose was to define these functions internally.
See #2008.
Diffstat (limited to 'src/journal')
-rw-r--r-- | src/journal/coredumpctl.c | 2 | ||||
-rw-r--r-- | src/journal/journal-internal.h | 3 | ||||
-rw-r--r-- | src/journal/journalctl.c | 10 | ||||
-rw-r--r-- | src/journal/test-journal-enum.c | 2 | ||||
-rw-r--r-- | src/journal/test-journal-match.c | 2 | ||||
-rw-r--r-- | src/journal/test-journal-stream.c | 2 |
6 files changed, 9 insertions, 12 deletions
diff --git a/src/journal/coredumpctl.c b/src/journal/coredumpctl.c index 1df28d774a..40ffa6afbe 100644 --- a/src/journal/coredumpctl.c +++ b/src/journal/coredumpctl.c @@ -792,7 +792,7 @@ finish: } int main(int argc, char *argv[]) { - _cleanup_journal_close_ sd_journal*j = NULL; + _cleanup_(sd_journal_closep) sd_journal*j = NULL; const char* match; Iterator it; int r = 0; diff --git a/src/journal/journal-internal.h b/src/journal/journal-internal.h index c3e75ad240..9ff4fea7fb 100644 --- a/src/journal/journal-internal.h +++ b/src/journal/journal-internal.h @@ -127,8 +127,5 @@ struct sd_journal { char *journal_make_match_string(sd_journal *j); void journal_print_header(sd_journal *j); -DEFINE_TRIVIAL_CLEANUP_FUNC(sd_journal*, sd_journal_close); -#define _cleanup_journal_close_ _cleanup_(sd_journal_closep) - #define JOURNAL_FOREACH_DATA_RETVAL(j, data, l, retval) \ for (sd_journal_restart_data(j); ((retval) = sd_journal_enumerate_data((j), &(data), &(l))) > 0; ) diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index d9a8063d31..d009b2e93b 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -1766,8 +1766,8 @@ static int access_check(sd_journal *j) { } static int flush_to_var(void) { - _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; - _cleanup_bus_flush_close_unref_ sd_bus *bus = NULL; + _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; + _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; _cleanup_close_ int watch_fd = -1; int r; @@ -1828,7 +1828,7 @@ static int flush_to_var(void) { } static int send_signal_and_wait(int sig, const char *watch_path) { - _cleanup_bus_flush_close_unref_ sd_bus *bus = NULL; + _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; _cleanup_close_ int watch_fd = -1; usec_t start; int r; @@ -1857,7 +1857,7 @@ static int send_signal_and_wait(int sig, const char *watch_path) { /* Let's ask for a sync, but only once. */ if (!bus) { - _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; + _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; r = bus_connect_system_systemd(&bus); if (r < 0) @@ -1920,7 +1920,7 @@ static int sync_journal(void) { int main(int argc, char *argv[]) { int r; - _cleanup_journal_close_ sd_journal *j = NULL; + _cleanup_(sd_journal_closep) sd_journal *j = NULL; bool need_seek = false; sd_id128_t previous_boot_id; bool previous_boot_id_valid = false, first_line = true; diff --git a/src/journal/test-journal-enum.c b/src/journal/test-journal-enum.c index 8f56ea1907..d396fabdab 100644 --- a/src/journal/test-journal-enum.c +++ b/src/journal/test-journal-enum.c @@ -29,7 +29,7 @@ int main(int argc, char *argv[]) { unsigned n = 0; - _cleanup_journal_close_ sd_journal*j = NULL; + _cleanup_(sd_journal_closep) sd_journal*j = NULL; log_set_max_level(LOG_DEBUG); diff --git a/src/journal/test-journal-match.c b/src/journal/test-journal-match.c index abefedb992..4ebaa8b31a 100644 --- a/src/journal/test-journal-match.c +++ b/src/journal/test-journal-match.c @@ -30,7 +30,7 @@ #include "util.h" int main(int argc, char *argv[]) { - _cleanup_journal_close_ sd_journal*j; + _cleanup_(sd_journal_closep) sd_journal*j = NULL; _cleanup_free_ char *t; log_set_max_level(LOG_DEBUG); diff --git a/src/journal/test-journal-stream.c b/src/journal/test-journal-stream.c index 0cbef4b8c5..2c257e43b6 100644 --- a/src/journal/test-journal-stream.c +++ b/src/journal/test-journal-stream.c @@ -79,7 +79,7 @@ int main(int argc, char *argv[]) { JournalFile *one, *two, *three; char t[] = "/tmp/journal-stream-XXXXXX"; unsigned i; - _cleanup_journal_close_ sd_journal *j = NULL; + _cleanup_(sd_journal_closep) sd_journal *j = NULL; char *z; const void *data; size_t l; |