<refname>sd_bus_ref</refname>
<refname>sd_bus_unref</refname>
<refname>sd_bus_unrefp</refname>
+ <refname>sd_bus_close_unref</refname>
+ <refname>sd_bus_close_unrefp</refname>
<refname>sd_bus_flush_close_unref</refname>
<refname>sd_bus_flush_close_unrefp</refname>
</funcprototype>
<funcprototype>
- <funcdef>void <function>sd_bus_unrefp</function></funcdef>
- <paramdef>sd_bus **<parameter>busp</parameter></paramdef>
+ <funcdef>sd_bus *<function>sd_bus_close_unref</function></funcdef>
+ <paramdef>sd_bus *<parameter>bus</parameter></paramdef>
</funcprototype>
<funcprototype>
<paramdef>sd_bus *<parameter>bus</parameter></paramdef>
</funcprototype>
+ <funcprototype>
+ <funcdef>void <function>sd_bus_unrefp</function></funcdef>
+ <paramdef>sd_bus **<parameter>busp</parameter></paramdef>
+ </funcprototype>
+
+ <funcprototype>
+ <funcdef>void <function>sd_bus_close_unrefp</function></funcdef>
+ <paramdef>sd_bus **<parameter>busp</parameter></paramdef>
+ </funcprototype>
+
<funcprototype>
<funcdef>void <function>sd_bus_flush_close_unrefp</function></funcdef>
<paramdef>sd_bus **<parameter>busp</parameter></paramdef>
execute no operation if <emphasis>that</emphasis> is <constant>NULL</constant>.
</para>
- <para><function>sd_bus_flush_close_unref()</function> is similar to <function>sd_bus_unref()</function>, but first
- executes <citerefentry><refentrytitle>sd_bus_flush</refentrytitle><manvolnum>3</manvolnum></citerefentry> as well
- as <citerefentry><refentrytitle>sd_bus_close</refentrytitle><manvolnum>3</manvolnum></citerefentry>, ensuring that
- any pending messages are properly flushed out before the reference to the connection is dropped and possibly the
- object freed. This call is particularly useful immediately before exiting from a program as it ensures that any
- pending outgoing messages are written out, and unprocessed but queued incoming messages released before the
- connection is terminated and released.</para>
-
- <para><function>sd_bus_flush_close_unrefp()</function> is similar to
- <function>sd_bus_flush_close_unref()</function>, but may be used in GCC's and LLVM's Clean-up Variable Attribute,
- see above.</para>
+ <para><function>sd_bus_close_unref()</function> is similar to <function>sd_bus_unref()</function>, but
+ first executes
+ <citerefentry><refentrytitle>sd_bus_close</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
+ ensuring that the connection is terminated before the reference to the connection is dropped and possibly
+ the object freed.</para>
+
+ <para><function>sd_bus_flush_close_unref()</function> is similar to <function>sd_bus_unref()</function>,
+ but first executes
+ <citerefentry><refentrytitle>sd_bus_flush</refentrytitle><manvolnum>3</manvolnum></citerefentry> as well
+ as <citerefentry><refentrytitle>sd_bus_close</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
+ ensuring that any pending messages are synchronously flushed out before the reference to the connection
+ is dropped and possibly the object freed. This call is particularly useful immediately before exiting
+ from a program as it ensures that any pending outgoing messages are written out, and unprocessed but
+ queued incoming messages released before the connection is terminated and released.</para>
+
+ <para><function>sd_bus_close_unrefp()</function> is similar to
+ <function>sd_bus_close_unref()</function>, but may be used in GCC's and LLVM's Clean-up Variable
+ Attribute, see above. Similarly, <function>sd_bus_flush_close_unrefp()</function> is similar to
+ <function>sd_bus_flush_close_unref()</function>.</para>
</refsect1>
<refsect1>
static void json_dump_with_flags(JsonVariant *v, FILE *f);
static int acquire_bus(bool set_monitor, sd_bus **ret) {
- _cleanup_(sd_bus_unrefp) sd_bus *bus = NULL;
+ _cleanup_(sd_bus_close_unrefp) sd_bus *bus = NULL;
int r;
r = sd_bus_new(&bus);
}
static int bus_on_connection(sd_event_source *s, int fd, uint32_t revents, void *userdata) {
- _cleanup_(sd_bus_unrefp) sd_bus *bus = NULL;
+ _cleanup_(sd_bus_close_unrefp) sd_bus *bus = NULL;
_cleanup_close_ int nfd = -1;
Manager *m = userdata;
sd_id128_t id;
}
int bus_init_api(Manager *m) {
- _cleanup_(sd_bus_unrefp) sd_bus *bus = NULL;
+ _cleanup_(sd_bus_close_unrefp) sd_bus *bus = NULL;
int r;
if (m->api_bus)
}
int bus_init_system(Manager *m) {
- _cleanup_(sd_bus_unrefp) sd_bus *bus = NULL;
+ _cleanup_(sd_bus_close_unrefp) sd_bus *bus = NULL;
int r;
if (m->system_bus)
sd_bus_flush(*bus);
/* And destroy the object */
- sd_bus_close(*bus);
- *bus = sd_bus_unref(*bus);
+ *bus = sd_bus_close_unref(*bus);
}
void bus_done_api(Manager *m) {
while (s->fifos)
fifo_free(s->fifos);
- safe_close(s->epoll_fd);
-
- if (s->bus) {
- sd_bus_flush(s->bus);
- sd_bus_unref(s->bus);
- }
+ s->epoll_fd = safe_close(s->epoll_fd);
+ s->bus = sd_bus_flush_close_unref(s->bus);
}
static int server_init(Server *s, unsigned n_sockets) {
sd_event_source_get_floating;
sd_event_source_set_floating;
} LIBSYSTEMD_239;
+
+LIBSYSTEMD_241 {
+global:
+ sd_bus_close_unref;
+} LIBSYSTEMD_240;
bus_close_inotify_fd(bus);
}
+_public_ sd_bus *sd_bus_close_unref(sd_bus *bus) {
+ if (!bus)
+ return NULL;
+
+ sd_bus_close(bus);
+
+ return sd_bus_unref(bus);
+}
+
_public_ sd_bus* sd_bus_flush_close_unref(sd_bus *bus) {
if (!bus)
return NULL;
/* Have to do this before flush() to prevent hang */
bus_kill_exec(bus);
-
sd_bus_flush(bus);
- sd_bus_close(bus);
- return sd_bus_unref(bus);
+ return sd_bus_close_unref(bus);
}
void bus_enter_closing(sd_bus *bus) {
bus_verify_polkit_async_registry_free(m->polkit_registry);
- sd_bus_unref(m->bus);
+ sd_bus_flush_close_unref(m->bus);
sd_event_unref(m->event);
safe_close(m->reserve_vt_fd);
static int acquire_runtime_dir_size(uint64_t *ret) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
- _cleanup_(sd_bus_unrefp) sd_bus *bus = NULL;
+ _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
int r;
r = sd_bus_default_system(&bus);
break;
case MACHINE_CONTAINER: {
- _cleanup_(sd_bus_unrefp) sd_bus *bus = NULL;
+ _cleanup_(sd_bus_close_unrefp) sd_bus *bus = NULL;
char *address;
r = sd_bus_new(&bus);
bus_verify_polkit_async_registry_free(m->polkit_registry);
- sd_bus_unref(m->bus);
+ sd_bus_flush_close_unref(m->bus);
sd_event_unref(m->event);
return mfree(m);
sd_device_monitor_unref(m->device_monitor);
- sd_bus_unref(m->bus);
+ sd_bus_flush_close_unref(m->bus);
free(m->dynamic_timezone);
free(m->dynamic_hostname);
bus_verify_polkit_async_registry_free(m->polkit_registry);
- sd_bus_unref(m->bus);
+ sd_bus_flush_close_unref(m->bus);
sd_event_unref(m->event);
return mfree(m);
manager_mdns_stop(m);
manager_dns_stub_stop(m);
- sd_bus_unref(m->bus);
+ sd_bus_flush_close_unref(m->bus);
sd_event_source_unref(m->sigusr1_event_source);
sd_event_source_unref(m->sigusr2_event_source);
}
int bus_connect_system_systemd(sd_bus **_bus) {
- _cleanup_(sd_bus_unrefp) sd_bus *bus = NULL;
+ _cleanup_(sd_bus_close_unrefp) sd_bus *bus = NULL;
int r;
assert(_bus);
}
int bus_connect_user_systemd(sd_bus **_bus) {
- _cleanup_(sd_bus_unrefp) sd_bus *bus = NULL;
+ _cleanup_(sd_bus_close_unrefp) sd_bus *bus = NULL;
_cleanup_free_ char *ee = NULL;
const char *e;
int r;
}
int bus_connect_transport(BusTransport transport, const char *host, bool user, sd_bus **ret) {
- _cleanup_(sd_bus_unrefp) sd_bus *bus = NULL;
+ _cleanup_(sd_bus_close_unrefp) sd_bus *bus = NULL;
int r;
assert(transport >= 0);
}
int bus_open_system_watch_bind_with_description(sd_bus **ret, const char *description) {
- _cleanup_(sd_bus_unrefp) sd_bus *bus = NULL;
+ _cleanup_(sd_bus_close_unrefp) sd_bus *bus = NULL;
const char *e;
int r;
}
static int run(int argc, char *argv[]) {
- _cleanup_(sd_bus_unrefp) sd_bus *a = NULL, *b = NULL;
+ _cleanup_(sd_bus_flush_close_unrefp) sd_bus *a = NULL, *b = NULL;
sd_id128_t server_id;
bool is_unix;
int r, in_fd, out_fd;
sd_bus *sd_bus_ref(sd_bus *bus);
sd_bus *sd_bus_unref(sd_bus *bus);
+sd_bus *sd_bus_close_unref(sd_bus *bus);
sd_bus *sd_bus_flush_close_unref(sd_bus *bus);
void sd_bus_default_flush_close(void);
/* Define helpers so that __attribute__((cleanup(sd_bus_unrefp))) and similar may be used. */
_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_bus, sd_bus_unref);
+_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_bus, sd_bus_close_unref);
_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_bus, sd_bus_flush_close_unref);
_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_bus_slot, sd_bus_slot_unref);
_SD_DEFINE_POINTER_CLEANUP_FUNC(sd_bus_message, sd_bus_message_unref);
sd_resolve_unref(m->resolve);
sd_event_unref(m->event);
- sd_bus_unref(m->bus);
+ sd_bus_flush_close_unref(m->bus);
free(m);
}