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.
This commit is contained in:
Lennart Poettering
2015-11-27 19:13:45 +01:00
parent f5edf80e29
commit 4afd3348c7
189 changed files with 934 additions and 897 deletions

View File

@@ -285,6 +285,7 @@ MANPAGES_ALIAS += \
man/sd_bus_creds_has_permitted_cap.3 \
man/sd_bus_creds_ref.3 \
man/sd_bus_creds_unref.3 \
man/sd_bus_creds_unrefp.3 \
man/sd_bus_default_system.3 \
man/sd_bus_default_user.3 \
man/sd_bus_error_copy.3 \
@@ -320,6 +321,7 @@ MANPAGES_ALIAS += \
man/sd_bus_ref.3 \
man/sd_bus_release_name.3 \
man/sd_bus_unref.3 \
man/sd_bus_unrefp.3 \
man/sd_event.3 \
man/sd_event_add_exit.3 \
man/sd_event_add_post.3 \
@@ -354,8 +356,10 @@ MANPAGES_ALIAS += \
man/sd_event_source_set_io_fd.3 \
man/sd_event_source_set_time.3 \
man/sd_event_source_set_time_accuracy.3 \
man/sd_event_source_unrefp.3 \
man/sd_event_time_handler_t.3 \
man/sd_event_unref.3 \
man/sd_event_unrefp.3 \
man/sd_id128_equal.3 \
man/sd_id128_from_string.3 \
man/sd_id128_get_boot.3 \
@@ -608,6 +612,7 @@ man/sd_bus_creds_has_inheritable_cap.3: man/sd_bus_creds_get_pid.3
man/sd_bus_creds_has_permitted_cap.3: man/sd_bus_creds_get_pid.3
man/sd_bus_creds_ref.3: man/sd_bus_creds_new_from_pid.3
man/sd_bus_creds_unref.3: man/sd_bus_creds_new_from_pid.3
man/sd_bus_creds_unrefp.3: man/sd_bus_creds_new_from_pid.3
man/sd_bus_default_system.3: man/sd_bus_default.3
man/sd_bus_default_user.3: man/sd_bus_default.3
man/sd_bus_error_copy.3: man/sd_bus_error.3
@@ -643,6 +648,7 @@ man/sd_bus_path_encode_many.3: man/sd_bus_path_encode.3
man/sd_bus_ref.3: man/sd_bus_new.3
man/sd_bus_release_name.3: man/sd_bus_request_name.3
man/sd_bus_unref.3: man/sd_bus_new.3
man/sd_bus_unrefp.3: man/sd_bus_new.3
man/sd_event.3: man/sd_event_new.3
man/sd_event_add_exit.3: man/sd_event_add_defer.3
man/sd_event_add_post.3: man/sd_event_add_defer.3
@@ -677,8 +683,10 @@ man/sd_event_source_set_io_events.3: man/sd_event_add_io.3
man/sd_event_source_set_io_fd.3: man/sd_event_add_io.3
man/sd_event_source_set_time.3: man/sd_event_add_time.3
man/sd_event_source_set_time_accuracy.3: man/sd_event_add_time.3
man/sd_event_source_unrefp.3: man/sd_event_source_unref.3
man/sd_event_time_handler_t.3: man/sd_event_add_time.3
man/sd_event_unref.3: man/sd_event_new.3
man/sd_event_unrefp.3: man/sd_event_new.3
man/sd_id128_equal.3: man/sd-id128.3
man/sd_id128_from_string.3: man/sd_id128_to_string.3
man/sd_id128_get_boot.3: man/sd_id128_get_machine.3
@@ -1157,6 +1165,9 @@ man/sd_bus_creds_ref.html: man/sd_bus_creds_new_from_pid.html
man/sd_bus_creds_unref.html: man/sd_bus_creds_new_from_pid.html
$(html-alias)
man/sd_bus_creds_unrefp.html: man/sd_bus_creds_new_from_pid.html
$(html-alias)
man/sd_bus_default_system.html: man/sd_bus_default.html
$(html-alias)
@@ -1262,6 +1273,9 @@ man/sd_bus_release_name.html: man/sd_bus_request_name.html
man/sd_bus_unref.html: man/sd_bus_new.html
$(html-alias)
man/sd_bus_unrefp.html: man/sd_bus_new.html
$(html-alias)
man/sd_event.html: man/sd_event_new.html
$(html-alias)
@@ -1364,12 +1378,18 @@ man/sd_event_source_set_time.html: man/sd_event_add_time.html
man/sd_event_source_set_time_accuracy.html: man/sd_event_add_time.html
$(html-alias)
man/sd_event_source_unrefp.html: man/sd_event_source_unref.html
$(html-alias)
man/sd_event_time_handler_t.html: man/sd_event_add_time.html
$(html-alias)
man/sd_event_unref.html: man/sd_event_new.html
$(html-alias)
man/sd_event_unrefp.html: man/sd_event_new.html
$(html-alias)
man/sd_id128_equal.html: man/sd-id128.html
$(html-alias)
@@ -2138,6 +2158,7 @@ MANPAGES_ALIAS += \
man/sd_login_monitor_get_fd.3 \
man/sd_login_monitor_get_timeout.3 \
man/sd_login_monitor_unref.3 \
man/sd_login_monitor_unrefp.3 \
man/sd_peer_get_cgroup.3 \
man/sd_peer_get_machine_name.3 \
man/sd_peer_get_owner_uid.3 \
@@ -2184,6 +2205,7 @@ man/sd_login_monitor_get_events.3: man/sd_login_monitor_new.3
man/sd_login_monitor_get_fd.3: man/sd_login_monitor_new.3
man/sd_login_monitor_get_timeout.3: man/sd_login_monitor_new.3
man/sd_login_monitor_unref.3: man/sd_login_monitor_new.3
man/sd_login_monitor_unrefp.3: man/sd_login_monitor_new.3
man/sd_peer_get_cgroup.3: man/sd_pid_get_session.3
man/sd_peer_get_machine_name.3: man/sd_pid_get_session.3
man/sd_peer_get_owner_uid.3: man/sd_pid_get_session.3
@@ -2248,6 +2270,9 @@ man/sd_login_monitor_get_timeout.html: man/sd_login_monitor_new.html
man/sd_login_monitor_unref.html: man/sd_login_monitor_new.html
$(html-alias)
man/sd_login_monitor_unrefp.html: man/sd_login_monitor_new.html
$(html-alias)
man/sd_peer_get_cgroup.html: man/sd_pid_get_session.html
$(html-alias)

View File

@@ -3041,7 +3041,6 @@ libsystemd_internal_la_SOURCES = \
src/libsystemd/sd-bus/bus-dump.h \
src/libsystemd/sd-utf8/sd-utf8.c \
src/libsystemd/sd-event/sd-event.c \
src/libsystemd/sd-event/event-util.h \
src/libsystemd/sd-netlink/sd-netlink.c \
src/libsystemd/sd-netlink/netlink-internal.h \
src/libsystemd/sd-netlink/netlink-message.c \
@@ -3070,8 +3069,7 @@ libsystemd_internal_la_SOURCES = \
src/libsystemd/sd-device/sd-device.c \
src/libsystemd/sd-device/device-private.c \
src/libsystemd/sd-device/device-private.h \
src/libsystemd/sd-resolve/sd-resolve.c \
src/libsystemd/sd-resolve/resolve-util.h
src/libsystemd/sd-resolve/sd-resolve.c
libsystemd_internal_la_LIBADD = \
libbasic.la \
@@ -3353,7 +3351,6 @@ libsystemd_network_la_SOURCES = \
src/libsystemd-network/lldp-port.c \
src/libsystemd-network/lldp-internal.h \
src/libsystemd-network/lldp-internal.c \
src/libsystemd-network/lldp-util.h \
src/libsystemd-network/sd-lldp.c
libsystemd_network_la_LIBADD = \

View File

@@ -48,6 +48,7 @@
<refname>sd_bus_creds_get_augmented_mask</refname>
<refname>sd_bus_creds_ref</refname>
<refname>sd_bus_creds_unref</refname>
<refname>sd_bus_creds_unrefp</refname>
<refpurpose>Retrieve credentials object for the specified PID</refpurpose>
</refnamediv>
@@ -82,6 +83,11 @@
<funcdef>sd_bus_creds *<function>sd_bus_creds_unref</function></funcdef>
<paramdef>sd_bus_creds *<parameter>c</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>void <function>sd_bus_creds_unrefp</function></funcdef>
<paramdef>sd_bus_creds **<parameter>c</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
@@ -235,6 +241,21 @@
<para><function>sd_bus_creds_unref()</function> destroys a reference
to <parameter>c</parameter>.</para>
<para><function>sd_bus_creds_unrefp()</function> is similar to
<function>sd_bus_creds_unref()</function> but takes a pointer to a
pointer to an <type>sd_bus_creds</type> object. This call is useful in
conjunction with GCC's and LLVM's <ulink
url="https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html">Clean-up
Variable Attribute</ulink>. Note that this function is defined as
inline function.</para>
<para><function>sd_bus_creds_ref()</function>,
<function>sd_bus_creds_unref()</function> and
<function>sd_bus_creds_unrefp()</function> execute no operation if
the passed in bus credentials object is
<constant>NULL</constant>.</para>
</refsect1>
<refsect1>

View File

@@ -46,6 +46,7 @@
<refname>sd_bus_new</refname>
<refname>sd_bus_ref</refname>
<refname>sd_bus_unref</refname>
<refname>sd_bus_unrefp</refname>
<refpurpose>Create a new bus object and create or destroy references to it</refpurpose>
</refnamediv>
@@ -68,6 +69,11 @@
<funcdef>sd_bus *<function>sd_bus_unref</function></funcdef>
<paramdef>sd_bus *<parameter>bus</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>void <function>sd_bus_unrefp</function></funcdef>
<paramdef>sd_bus **<parameter>bus</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
@@ -93,14 +99,40 @@
only allocate a bus object but also start the connection to a
well-known bus in a single function invocation.</para>
<para><function>sd_bus_ref()</function> creates a new reference to
<parameter>bus</parameter>.</para>
<para><function>sd_bus_ref()</function> increases the reference
counter of <parameter>bus</parameter> by one.</para>
<para><function>sd_bus_unref()</function> destroys a reference to
<parameter>bus</parameter>. Once the reference count has dropped
to zero, <parameter>bus</parameter> cannot be used anymore, so
further calls to <function>sd_bus_ref()</function> or
<para><function>sd_bus_unref()</function> decreases the reference
counter of <parameter>bus</parameter> by one. Once the reference
count has dropped to zero, <parameter>bus</parameter> is destroyed
and cannot be used anymore, so further calls to
<function>sd_bus_ref()</function> or
<function>sd_bus_unref()</function> are illegal.</para>
<para><function>sd_bus_unrefp()</function> is similar to
<function>sd_bus_unref()</function> but takes a pointer to a
pointer to an <type>sd_bus</type> object. This call is useful in
conjunction with GCC's and LLVM's <ulink
url="https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html">Clean-up
Variable Attribute</ulink>. Note that this function is defined as
inline function. Use a declaration like the following, in order to
allocate a bus object that is freed automatically as the code
block is left:</para>
<programlisting>{
__attribute__((cleanup(sd_bus_unrefp)) sd_bus *bus = NULL;
int r;
r = sd_bus_default(&amp;bus);
if (r &lt; 0)
fprintf(stderr, "Failed to allocate bus: %s\n", strerror(-r));
}</programlisting>
<para><function>sd_bus_ref()</function>,
<function>sd_bus_unref()</function> and
<function>sd_bus_unrefp()</function> execute no operation if the
passed in bus object is <constant>NULL</constant>.</para>
</refsect1>
<refsect1>
@@ -110,10 +142,10 @@
positive integer. On failure, it returns a negative errno-style
error code.</para>
<para><function>sd_bus_ref</function> always returns the argument.
<para><function>sd_bus_ref()</function> always returns the argument.
</para>
<para><function>sd_bus_unref</function> always returns
<para><function>sd_bus_unref()</function> always returns
<constant>NULL</constant>.</para>
</refsect1>

View File

@@ -47,6 +47,7 @@
<refname>sd_event_default</refname>
<refname>sd_event_ref</refname>
<refname>sd_event_unref</refname>
<refname>sd_event_unrefp</refname>
<refname>sd_event_get_tid</refname>
<refname>sd_event</refname>
@@ -79,6 +80,11 @@
<paramdef>sd_event *<parameter>event</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>void <function>sd_event_unrefp</function></funcdef>
<paramdef>sd_event **<parameter>event</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>int <function>sd_event_get_tid</function></funcdef>
<paramdef>sd_event *<parameter>event</parameter></paramdef>
@@ -139,8 +145,29 @@
all remaining event sources of the event loop also need to be
freed as each keeps a reference to it.</para>
<para>Both <function>sd_event_ref()</function> and
<function>sd_event_unref()</function> execute no operation if the
<para><function>sd_event_unrefp()</function> is similar to
<function>sd_event_unref()</function> but takes a pointer to a
pointer to an <type>sd_event</type> object. This call is useful in
conjunction with GCC's and LLVM's <ulink
url="https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html">Clean-up
Variable Attribute</ulink>. Note that this function is defined as
inline function. Use a declaration like the following,
in order to allocate an event loop object that is freed
automatically as the code block is left:</para>
<programlisting>{
__attribute__((cleanup(sd_event_unrefp)) sd_event *event = NULL;
int r;
r = sd_event_default(&amp;event);
if (r &lt; 0)
fprintf(stderr, "Failed to allocate event loop: %s\n", strerror(-r));
}</programlisting>
<para><function>sd_event_ref()</function>,
<function>sd_event_unref()</function> and
<function>sd_event_unrefp()</function> execute no operation if the
passed in event loop object is <constant>NULL</constant>.</para>
<para><function>sd_event_get_tid()</function> retrieves the thread

View File

@@ -44,6 +44,7 @@
<refnamediv>
<refname>sd_event_source_unref</refname>
<refname>sd_event_source_unrefp</refname>
<refname>sd_event_source_ref</refname>
<refpurpose>Increase or decrease event source reference counters</refpurpose>
@@ -58,6 +59,11 @@
<paramdef>sd_event_source *<parameter>source</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>void <function>sd_event_source_unrefp</function></funcdef>
<paramdef>sd_event_source **<parameter>source</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>sd_event_source* <function>sd_event_source_ref</function></funcdef>
<paramdef>sd_event_source *<parameter>source</parameter></paramdef>
@@ -80,12 +86,23 @@
the reference counter reaches zero it is removed from its event loop
object and destroyed.</para>
<para><function>sd_event_source_unrefp()</function> is similar to
<function>sd_event_source_unref()</function> but takes a pointer to a
pointer to an <type>sd_event_source</type> object. This call is useful in
conjunction with GCC's and LLVM's <ulink
url="https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html">Clean-up
Variable Attribute</ulink>. Note that this function is defined as
inline function.</para>
<para><function>sd_event_source_ref()</function> may be used
to increase by one the reference counter of the event source object
specified as <parameter>source</parameter>.</para>
<para>Both functions execute no operation if the passed event
source object is <constant>NULL</constant>.</para>
<para><function>sd_event_source_unref()</function>,
<function>sd_bus_creds_unrefp()</function> and
<function>sd_bus_creds_ref()</function> execute no operation if
the passed event source object is
<constant>NULL</constant>.</para>
<para>Note that event source objects stay alive and may be
dispatched as long as they have a reference counter greater than

View File

@@ -45,6 +45,7 @@
<refnamediv>
<refname>sd_login_monitor_new</refname>
<refname>sd_login_monitor_unref</refname>
<refname>sd_login_monitor_unrefp</refname>
<refname>sd_login_monitor_flush</refname>
<refname>sd_login_monitor_get_fd</refname>
<refname>sd_login_monitor_get_events</refname>
@@ -68,6 +69,11 @@
<paramdef>sd_login_monitor *<parameter>m</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>void <function>sd_login_monitor_unrefp</function></funcdef>
<paramdef>sd_login_monitor **<parameter>m</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>int <function>sd_login_monitor_flush</function></funcdef>
<paramdef>sd_login_monitor *<parameter>m</parameter></paramdef>
@@ -121,6 +127,26 @@
descriptor returned by
<function>sd_login_monitor_get_fd()</function>.</para>
<para><function>sd_login_monitor_unrefp()</function> is similar to
<function>sd_login_monitor_unref()</function> but takes a pointer
to a pointer to an <type>sd_login_monitor</type> object. This call
is useful in conjunction with GCC's and LLVM's <ulink
url="https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html">Clean-up
Variable Attribute</ulink>. Note that this function is defined as
inline function. Use a declaration like the following, in order to
allocate a login monitor object that is freed automatically as the
code block is left:</para>
<programlisting>{
__attribute__((cleanup(sd_login_monitor_unrefp)) sd_login_monitor *m = NULL;
int r;
r = sd_login_monitor_default(&amp;m);
if (r &lt; 0)
fprintf(stderr, "Failed to allocate login monitor object: %s\n", strerror(-r));
}</programlisting>
<para><function>sd_login_monitor_flush()</function> may be used to
reset the wakeup state of the monitor object. Whenever an event
causes the monitor to wake up the event loop via the file
@@ -128,6 +154,11 @@
state. If this call is not invoked, the file descriptor will
immediately wake up the event loop again.</para>
<para><function>sd_login_monitor_unref()</function> and
<function>sd_login_monitor_unrefp()</function> execute no
operation if the passed in monitor object is
<constant>NULL</constant>.</para>
<para><function>sd_login_monitor_get_fd()</function> may be used
to retrieve the file descriptor of the monitor object that may be
integrated in an application defined event loop, based around

View File

@@ -164,7 +164,7 @@ static int verify_documentation(Unit *u, bool check_man) {
}
static int verify_unit(Unit *u, bool check_man) {
_cleanup_bus_error_free_ sd_bus_error err = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_error_free) sd_bus_error err = SD_BUS_ERROR_NULL;
int r, k;
assert(u);
@@ -193,7 +193,7 @@ static int verify_unit(Unit *u, bool check_man) {
}
int verify_units(char **filenames, ManagerRunningAs running_as, bool check_man) {
_cleanup_bus_error_free_ sd_bus_error err = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_error_free) sd_bus_error err = SD_BUS_ERROR_NULL;
Manager *m = NULL;
FILE *serial = NULL;
FDSet *fdset = NULL;

View File

@@ -134,7 +134,7 @@ static void pager_open_if_enabled(void) {
}
static int bus_get_uint64_property(sd_bus *bus, const char *path, const char *interface, const char *property, uint64_t *val) {
_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;
int r;
assert(bus);
@@ -161,7 +161,7 @@ static int bus_get_uint64_property(sd_bus *bus, const char *path, const char *in
}
static int bus_get_unit_property_strv(sd_bus *bus, const char *path, const char *property, char ***strv) {
_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;
int r;
assert(bus);
@@ -339,8 +339,8 @@ static void free_host_info(struct host_info *hi) {
DEFINE_TRIVIAL_CLEANUP_FUNC(struct host_info*, free_host_info);
static int acquire_time_data(sd_bus *bus, struct unit_times **out) {
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
int r, c = 0;
struct boot_times *boot_times = NULL;
struct unit_times *unit_times = NULL;
@@ -455,7 +455,7 @@ static int acquire_host_info(sd_bus *bus, struct host_info **hi) {
{}
};
_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;
_cleanup_(free_host_infop) struct host_info *host;
int r;
@@ -899,8 +899,8 @@ static int list_dependencies(sd_bus *bus, const char *name) {
int r;
const char *id;
_cleanup_free_ char *path = NULL;
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
struct boot_times *boot;
assert(bus);
@@ -1096,7 +1096,7 @@ static int expand_patterns(sd_bus *bus, char **patterns, char ***ret) {
int r;
STRV_FOREACH(pattern, patterns) {
_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;
_cleanup_free_ char *unit = NULL, *unit_id = NULL;
if (strv_extend(&expanded_patterns, *pattern) < 0)
@@ -1133,8 +1133,8 @@ static int expand_patterns(sd_bus *bus, char **patterns, char ***ret) {
}
static int dot(sd_bus *bus, char* patterns[]) {
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_strv_free_ char **expanded_patterns = NULL;
_cleanup_strv_free_ char **expanded_from_patterns = NULL;
_cleanup_strv_free_ char **expanded_to_patterns = NULL;
@@ -1198,8 +1198,8 @@ static int dot(sd_bus *bus, char* patterns[]) {
}
static int dump(sd_bus *bus, char **args) {
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
const char *text = NULL;
int r;
@@ -1231,7 +1231,7 @@ static int dump(sd_bus *bus, char **args) {
}
static int set_log_level(sd_bus *bus, char **args) {
_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;
int r;
assert(bus);
@@ -1258,7 +1258,7 @@ static int set_log_level(sd_bus *bus, char **args) {
}
static int set_log_target(sd_bus *bus, char **args) {
_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;
int r;
assert(bus);
@@ -1456,7 +1456,7 @@ int main(int argc, char *argv[]) {
arg_user ? MANAGER_USER : MANAGER_SYSTEM,
arg_man);
else {
_cleanup_bus_flush_close_unref_ sd_bus *bus = NULL;
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
r = bus_connect_transport_systemd(arg_transport, arg_host, arg_user, &bus);
if (r < 0) {

View File

@@ -40,7 +40,7 @@
#include "util.h"
static int get_creds_by_name(sd_bus *bus, const char *name, uint64_t mask, sd_bus_creds **_creds, sd_bus_error *error) {
_cleanup_bus_creds_unref_ sd_bus_creds *c = NULL;
_cleanup_(sd_bus_creds_unrefp) sd_bus_creds *c = NULL;
int r;
assert(bus);
@@ -75,7 +75,7 @@ static int get_creds_by_message(sd_bus *bus, sd_bus_message *m, uint64_t mask, s
}
static int driver_activation(sd_bus_message *reply, void *userdata, sd_bus_error *error) {
_cleanup_bus_message_unref_ sd_bus_message *m = NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
ProxyActivation *activation = userdata;
/*
@@ -239,9 +239,9 @@ int bus_proxy_process_driver(Proxy *p, sd_bus *a, sd_bus *b, sd_bus_message *m,
return synthetic_reply_method_return(m, NULL);
} else if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus", "GetConnectionCredentials")) {
_cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
if (!sd_bus_message_has_signature(m, "s"))
return synthetic_reply_method_error(m, &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters"));
@@ -305,9 +305,9 @@ int bus_proxy_process_driver(Proxy *p, sd_bus *a, sd_bus *b, sd_bus_message *m,
return synthetic_driver_send(m->bus, reply);
} else if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus", "GetConnectionSELinuxSecurityContext")) {
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
_cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
_cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL;
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
if (!sd_bus_message_has_signature(m, "s"))
return synthetic_reply_method_error(m, &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters"));
@@ -330,8 +330,8 @@ int bus_proxy_process_driver(Proxy *p, sd_bus *a, sd_bus *b, sd_bus_message *m,
return synthetic_driver_send(m->bus, reply);
} else if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus", "GetConnectionUnixProcessID")) {
_cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL;
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
if (!sd_bus_message_has_signature(m, "s"))
return synthetic_reply_method_error(m, &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters"));
@@ -346,8 +346,8 @@ int bus_proxy_process_driver(Proxy *p, sd_bus *a, sd_bus *b, sd_bus_message *m,
return synthetic_reply_method_return(m, "u", (uint32_t) creds->pid);
} else if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus", "GetConnectionUnixUser")) {
_cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL;
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
if (!sd_bus_message_has_signature(m, "s"))
return synthetic_reply_method_error(m, &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters"));
@@ -376,8 +376,8 @@ int bus_proxy_process_driver(Proxy *p, sd_bus *a, sd_bus *b, sd_bus_message *m,
} else if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus", "GetNameOwner")) {
const char *name;
_cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL;
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
if (!sd_bus_message_has_signature(m, "s"))
return synthetic_reply_method_error(m, &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_INVALID_ARGS, "Invalid parameters"));
@@ -439,7 +439,7 @@ int bus_proxy_process_driver(Proxy *p, sd_bus *a, sd_bus *b, sd_bus_message *m,
};
struct kdbus_info *name_list, *name;
_cleanup_strv_free_ char **owners = NULL;
_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;
char *arg0;
int err = 0;
@@ -610,7 +610,7 @@ int bus_proxy_process_driver(Proxy *p, sd_bus *a, sd_bus *b, sd_bus_message *m,
return synthetic_reply_method_return(m, "u", BUS_NAME_PRIMARY_OWNER);
} else if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus", "StartServiceByName")) {
_cleanup_bus_message_unref_ sd_bus_message *msg = NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *msg = NULL;
ProxyActivation *activation;
const char *name;
uint64_t cookie;
@@ -674,7 +674,7 @@ int bus_proxy_process_driver(Proxy *p, sd_bus *a, sd_bus *b, sd_bus_message *m,
return 1;
} else if (sd_bus_message_is_method_call(m, "org.freedesktop.DBus", "UpdateActivationEnvironment")) {
_cleanup_bus_message_unref_ sd_bus_message *msg = NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *msg = NULL;
_cleanup_strv_free_ char **args = NULL;
if (!sd_bus_message_has_signature(m, "a{ss}"))
@@ -738,7 +738,7 @@ int bus_proxy_process_driver(Proxy *p, sd_bus *a, sd_bus *b, sd_bus_message *m,
return synthetic_reply_method_return(m, NULL);
} else {
_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 = sd_bus_error_setf(&error, SD_BUS_ERROR_UNKNOWN_METHOD, "Unknown method '%s'.", m->member);

View File

@@ -49,7 +49,7 @@
#include "util.h"
static int proxy_create_destination(Proxy *p, const char *destination, const char *local_sec, bool negotiate_fds) {
_cleanup_bus_flush_close_unref_ sd_bus *b = NULL;
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *b = NULL;
int r;
r = sd_bus_new(&b);
@@ -491,7 +491,7 @@ static int process_policy_unlocked(sd_bus *from, sd_bus *to, sd_bus_message *m,
(void) sd_bus_creds_get_egid(&m->creds, &sender_gid);
if (sender_uid == UID_INVALID || sender_gid == GID_INVALID) {
_cleanup_bus_creds_unref_ sd_bus_creds *sender_creds = NULL;
_cleanup_(sd_bus_creds_unrefp) sd_bus_creds *sender_creds = NULL;
/* If the message came from another legacy
* client, then the message creds will be
@@ -522,7 +522,7 @@ static int process_policy_unlocked(sd_bus *from, sd_bus *to, sd_bus_message *m,
}
if (to->is_kernel) {
_cleanup_bus_creds_unref_ sd_bus_creds *destination_creds = NULL;
_cleanup_(sd_bus_creds_unrefp) sd_bus_creds *destination_creds = NULL;
uid_t destination_uid = UID_INVALID;
gid_t destination_gid = GID_INVALID;
const char *destination_unique = NULL;
@@ -609,7 +609,7 @@ static int process_policy(sd_bus *from, sd_bus *to, sd_bus_message *m, SharedPol
}
static int process_hello(Proxy *p, sd_bus_message *m) {
_cleanup_bus_message_unref_ sd_bus_message *n = NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *n = NULL;
bool is_hello;
int r;
@@ -723,7 +723,7 @@ static int patch_sender(sd_bus *a, sd_bus_message *m) {
}
static int proxy_process_destination_to_local(Proxy *p) {
_cleanup_bus_message_unref_ sd_bus_message *m = NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
bool matched, matched_synthetic;
int r;
@@ -832,7 +832,7 @@ static int proxy_process_destination_to_local(Proxy *p) {
}
static int proxy_process_local_to_destination(Proxy *p) {
_cleanup_bus_message_unref_ sd_bus_message *m = NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
int r;
assert(p);

View File

@@ -146,7 +146,7 @@ static int parse_argv(int argc, char *argv[]) {
}
static int rename_service(sd_bus *a, sd_bus *b) {
_cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
_cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL;
_cleanup_free_ char *p = NULL, *name = NULL;
const char *comm;
char **cmdline;

View File

@@ -50,7 +50,7 @@ int synthetic_driver_send(sd_bus *b, sd_bus_message *m) {
}
int synthetic_reply_method_error(sd_bus_message *call, const sd_bus_error *e) {
_cleanup_bus_message_unref_ sd_bus_message *m = NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
int r;
assert(call);
@@ -66,7 +66,7 @@ int synthetic_reply_method_error(sd_bus_message *call, const sd_bus_error *e) {
}
int synthetic_reply_method_errorf(sd_bus_message *call, const char *name, const char *format, ...) {
_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;
va_list ap;
va_start(ap, format);
@@ -77,7 +77,7 @@ int synthetic_reply_method_errorf(sd_bus_message *call, const char *name, const
}
int synthetic_reply_method_errno(sd_bus_message *call, int error, const sd_bus_error *p) {
_cleanup_bus_error_free_ sd_bus_error berror = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_error_free) sd_bus_error berror = SD_BUS_ERROR_NULL;
assert(call);
@@ -93,7 +93,7 @@ int synthetic_reply_method_errno(sd_bus_message *call, int error, const sd_bus_e
}
int synthetic_reply_method_errnof(sd_bus_message *call, int error, const char *format, ...) {
_cleanup_bus_error_free_ sd_bus_error berror = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_error_free) sd_bus_error berror = SD_BUS_ERROR_NULL;
va_list ap;
assert(call);
@@ -109,7 +109,7 @@ int synthetic_reply_method_errnof(sd_bus_message *call, int error, const char *f
}
int synthetic_reply_method_return(sd_bus_message *call, const char *types, ...) {
_cleanup_bus_message_unref_ sd_bus_message *m = NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
int r;
assert(call);
@@ -135,7 +135,7 @@ int synthetic_reply_method_return(sd_bus_message *call, const char *types, ...)
}
int synthetic_reply_method_return_strv(sd_bus_message *call, char **l) {
_cleanup_bus_message_unref_ sd_bus_message *m = NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
int r;
assert(call);
@@ -155,7 +155,7 @@ int synthetic_reply_method_return_strv(sd_bus_message *call, char **l) {
}
int synthesize_name_acquired(Proxy *p, sd_bus *a, sd_bus *b, sd_bus_message *m) {
_cleanup_bus_message_unref_ sd_bus_message *n = NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *n = NULL;
const char *name, *old_owner, *new_owner;
int r;

View File

@@ -123,8 +123,8 @@ static int parse_argv(int argc, char *argv[]) {
}
static int get_cgroup_root(char **ret) {
_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_free_ char *unit = NULL, *path = NULL;
const char *m;
int r;

View File

@@ -27,7 +27,7 @@
#include "log.h"
int main(int argc, char *argv[]) {
_cleanup_bus_flush_close_unref_ sd_bus *bus = NULL;
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
int r;
if (argc != 2) {

View File

@@ -841,8 +841,8 @@ static const char* counting_what(void) {
}
static int get_cgroup_root(char **ret) {
_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_free_ char *unit = NULL, *path = NULL;
const char *m;
int r;

View File

@@ -702,7 +702,7 @@ static int automount_start_expire(Automount *a) {
}
static void automount_enter_runnning(Automount *a) {
_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;
struct stat st;
int r;
@@ -897,7 +897,7 @@ static bool automount_check_gc(Unit *u) {
}
static int automount_dispatch_io(sd_event_source *s, int fd, uint32_t events, void *userdata) {
_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;
union autofs_v5_packet_union packet;
Automount *a = AUTOMOUNT(userdata);
struct stat st;

View File

@@ -557,7 +557,7 @@ fail:
}
static void busname_enter_running(BusName *n) {
_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;
bool pending = false;
Unit *other;
Iterator i;

View File

@@ -93,7 +93,7 @@ const sd_bus_vtable bus_job_vtable[] = {
};
static int send_new_signal(sd_bus *bus, void *userdata) {
_cleanup_bus_message_unref_ sd_bus_message *m = NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
_cleanup_free_ char *p = NULL;
Job *j = userdata;
int r;
@@ -153,7 +153,7 @@ void bus_job_send_change_signal(Job *j) {
}
static int send_removed_signal(sd_bus *bus, void *userdata) {
_cleanup_bus_message_unref_ sd_bus_message *m = NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
_cleanup_free_ char *p = NULL;
Job *j = userdata;
int r;

View File

@@ -384,7 +384,7 @@ static int method_get_unit(sd_bus_message *message, void *userdata, sd_bus_error
return r;
if (isempty(name)) {
_cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
_cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL;
pid_t pid;
r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID, &creds);
@@ -436,7 +436,7 @@ static int method_get_unit_by_pid(sd_bus_message *message, void *userdata, sd_bu
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid PID " PID_FMT, pid);
if (pid == 0) {
_cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
_cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL;
r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID, &creds);
if (r < 0)
@@ -479,7 +479,7 @@ static int method_load_unit(sd_bus_message *message, void *userdata, sd_bus_erro
return r;
if (isempty(name)) {
_cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
_cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL;
pid_t pid;
r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID, &creds);
@@ -865,7 +865,7 @@ static int method_reset_failed(sd_bus_message *message, void *userdata, sd_bus_e
}
static int list_units_filtered(sd_bus_message *message, void *userdata, sd_bus_error *error, char **states) {
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
Manager *m = userdata;
const char *k;
Iterator i;
@@ -953,7 +953,7 @@ static int method_list_units_filtered(sd_bus_message *message, void *userdata, s
}
static int method_list_jobs(sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
Manager *m = userdata;
Iterator i;
Job *j;
@@ -1441,7 +1441,7 @@ static int method_set_exit_code(sd_bus_message *message, void *userdata, sd_bus_
}
static int method_list_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
Manager *m = userdata;
UnitFileList *item;
Hashmap *h;
@@ -1547,7 +1547,7 @@ static int method_get_default_target(sd_bus_message *message, void *userdata, sd
}
static int send_unit_files_changed(sd_bus *bus, void *userdata) {
_cleanup_bus_message_unref_ sd_bus_message *message = NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *message = NULL;
int r;
assert(bus);
@@ -1566,7 +1566,7 @@ static int reply_unit_file_changes_and_free(
UnitFileChange *changes,
unsigned n_changes) {
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
unsigned i;
int r;
@@ -2023,7 +2023,7 @@ const sd_bus_vtable bus_manager_vtable[] = {
};
static int send_finished(sd_bus *bus, void *userdata) {
_cleanup_bus_message_unref_ sd_bus_message *message = NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *message = NULL;
usec_t *times = userdata;
int r;
@@ -2071,7 +2071,7 @@ void bus_manager_send_finished(
}
static int send_reloading(sd_bus *bus, void *userdata) {
_cleanup_bus_message_unref_ sd_bus_message *message = NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *message = NULL;
int r;
assert(bus);

Some files were not shown because too many files have changed in this diff Show More