]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-bus: add sd_bus_close_unref() helper
authorLennart Poettering <lennart@poettering.net>
Thu, 17 Jan 2019 14:51:08 +0000 (15:51 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 17 Jan 2019 15:12:38 +0000 (16:12 +0100)
It's similar to sd_bus_flush_close_unref() but doesn't do the flushing.
This is useful since this will still discnnect the connection properly
but not synchronously wait for the peer to take our messages.

Primary usecase is within _cleanup_() expressions where synchronously
waiting on the peer is not OK.

man/sd_bus_new.xml
src/core/dbus.c
src/libsystemd/libsystemd.sym
src/libsystemd/sd-bus/sd-bus.c
src/systemd/sd-bus.h

index 1bc011d70a10e03569cb371843afa40b6fe12fdb..cc08e6be17dcb7c5504237a557ffd4b43b08e6e0 100644 (file)
@@ -23,6 +23,8 @@
     <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>
 
@@ -49,8 +51,8 @@
       </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>
index 5908ad792a7cc6f4b6712d6a93be3d64aecfe2d2..ae595e0567e58a61818e6864676ce5f527d698a5 100644 (file)
@@ -611,7 +611,7 @@ static int bus_setup_disconnected_match(Manager *m, sd_bus *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;
index 96e63477956c61e99b6c4497ebfb1d1ab4b10b3e..a6748ceb209cd7845851d2bb478d2b42b16bc00f 100644 (file)
@@ -671,3 +671,8 @@ global:
         sd_event_source_get_floating;
         sd_event_source_set_floating;
 } LIBSYSTEMD_239;
+
+LIBSYSTEMD_241 {
+global:
+        sd_bus_close_unref;
+} LIBSYSTEMD_240;
index 3b00bc815725dbc607b86f3e1d7fdf28e3f98669..1ff858f32d379922f3d75c7d4df35f2f63d340ac 100644 (file)
@@ -1556,17 +1556,24 @@ _public_ void sd_bus_close(sd_bus *bus) {
         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) {
index 4c1acab9f3af876702a79fb864e9fbeb965b8807..129cc933288c783cc84d4868f52a5936cc225a59 100644 (file)
@@ -170,6 +170,7 @@ void sd_bus_close(sd_bus *bus);
 
 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);
@@ -493,6 +494,7 @@ int sd_bus_track_get_destroy_callback(sd_bus_track *s, sd_bus_destroy_t *ret);
 
 /* 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);