]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-bus: add new API call sd_bus_error_move()
authorLennart Poettering <lennart@poettering.net>
Mon, 6 Aug 2018 16:54:03 +0000 (18:54 +0200)
committerLennart Poettering <lennart@poettering.net>
Sat, 13 Oct 2018 10:59:29 +0000 (12:59 +0200)
This new call move an sd_bus_error into another one.

man/rules/meson.build
man/sd_bus_error.xml
src/libsystemd/libsystemd.sym
src/libsystemd/sd-bus/bus-error.c
src/systemd/sd-bus.h

index 303b584654977d01609b089b2106081cfb0996cd..3602bbaa1a820a040b47e2f937fb2ebe7434c3fc 100644 (file)
@@ -180,6 +180,7 @@ manpages = [
    'sd_bus_error_get_errno',
    'sd_bus_error_has_name',
    'sd_bus_error_is_set',
+   'sd_bus_error_move',
    'sd_bus_error_set',
    'sd_bus_error_set_const',
    'sd_bus_error_set_errno',
index 807ca86302dce197d234aa9173b9c64a91d7e2a4..c208f04cb6723c351111b7dbe4113b4168e2437c 100644 (file)
@@ -31,6 +31,7 @@
     <refname>sd_bus_error_set_errnofv</refname>
     <refname>sd_bus_error_get_errno</refname>
     <refname>sd_bus_error_copy</refname>
+    <refname>sd_bus_error_move</refname>
     <refname>sd_bus_error_is_set</refname>
     <refname>sd_bus_error_has_name</refname>
 
         <paramdef>const sd_bus_error *<parameter>e</parameter></paramdef>
       </funcprototype>
 
+      <funcprototype>
+        <funcdef>int <function>sd_bus_error_move</function></funcdef>
+        <paramdef>sd_bus_error *<parameter>dst</parameter></paramdef>
+        <paramdef>sd_bus_error *<parameter>e</parameter></paramdef>
+      </funcprototype>
+
       <funcprototype>
         <funcdef>int <function>sd_bus_error_is_set</function></funcdef>
         <paramdef>const sd_bus_error *<parameter>e</parameter></paramdef>
     Otherwise, they will be copied. Returns a converted
     <varname>errno</varname>-like, negative error code.</para>
 
+    <para><function>sd_bus_error_move()</function> is similar to <function>sd_bus_error_copy()</function>, but will
+    move any error information from <parameter>e</parameter> into <parameter>dst</parameter>, resetting the
+    former. This function cannot fail, as no new memory is allocated. Note that if <parameter>e</parameter> is not set
+    (or <constant>NULL</constant>) <parameter>dst</parameter> is initializated to
+    <constant>SD_BUS_ERROR_NULL</constant>. Moreover, if <parameter>dst</parameter> is <constant>NULL</constant> no
+    operation is executed on it and and resources held by <parameter>e</parameter> are freed and reset. Returns a
+    converted <varname>errno</varname>-like, negative error code.</para>
+
     <para><function>sd_bus_error_is_set()</function> will return a
     non-zero value if <parameter>e</parameter> is
     non-<constant>NULL</constant> and an error has been set,
     <constant>NULL</constant>, and a positive errno value mapped from
     <parameter>e-&gt;name</parameter> otherwise.</para>
 
-    <para><function>sd_bus_error_copy()</function> returns 0 or a
-    positive integer on success, and a negative error value converted
-    from the error name otherwise.</para>
+    <para><function>sd_bus_error_copy()</function> and <function>sd_bus_error_move()</function> return 0 or a positive
+    integer on success, and a negative error value converted from the error name otherwise.</para>
 
     <para><function>sd_bus_error_is_set()</function> returns a
     non-zero value when <parameter>e</parameter> and the
index ba682b879aff9911b8c74b980ea7e3d21e4fcac1..8d0bebe2adf4e621f5c73189dc9b02c0c4840dc0 100644 (file)
@@ -577,6 +577,8 @@ global:
         sd_bus_set_method_call_timeout;
         sd_bus_get_method_call_timeout;
 
+        sd_bus_error_move;
+
         sd_device_ref;
         sd_device_unref;
 
index 0f79ddc4278be68fd8280e5f0a49d99086cacf20..e73f7057e1ee27a3f31ac6a7eb6b66d8d19f1ce5 100644 (file)
@@ -308,6 +308,28 @@ finish:
         return -bus_error_name_to_errno(e->name);
 }
 
+_public_ int sd_bus_error_move(sd_bus_error *dest, sd_bus_error *e) {
+        int r;
+
+        if (!sd_bus_error_is_set(e)) {
+
+                if (dest)
+                        *dest = SD_BUS_ERROR_NULL;
+
+                return 0;
+        }
+
+        r = -bus_error_name_to_errno(e->name);
+
+        if (dest) {
+                *dest = *e;
+                *e = SD_BUS_ERROR_NULL;
+        } else
+                sd_bus_error_free(e);
+
+        return r;
+}
+
 _public_ int sd_bus_error_set_const(sd_bus_error *e, const char *name, const char *message) {
         if (!name)
                 return 0;
index 5bc696591661dd1c695572aae0e3d7855d8559fc..ce35756861dc0333454af70ee12658b29da9c553 100644 (file)
@@ -422,6 +422,7 @@ int sd_bus_error_set_errnof(sd_bus_error *e, int error, const char *format, ...)
 int sd_bus_error_set_errnofv(sd_bus_error *e, int error, const char *format, va_list ap) _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_move(sd_bus_error *dest, sd_bus_error *e);
 int sd_bus_error_is_set(const sd_bus_error *e);
 int sd_bus_error_has_name(const sd_bus_error *e, const char *name);