summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-08-06 18:54:03 +0200
committerLennart Poettering <lennart@poettering.net>2018-10-13 12:59:29 +0200
commit190128e407eb24a445554c0e1f956a1d51f97338 (patch)
tree1a859c35a9a13533c2be519cae157737fa64ba86
parentcce08496e7353e3e9903b42695aba3f9d259b90a (diff)
downloadsystemd-190128e407eb24a445554c0e1f956a1d51f97338.tar.gz
sd-bus: add new API call sd_bus_error_move()
This new call move an sd_bus_error into another one.
-rw-r--r--man/rules/meson.build1
-rw-r--r--man/sd_bus_error.xml20
-rw-r--r--src/libsystemd/libsystemd.sym2
-rw-r--r--src/libsystemd/sd-bus/bus-error.c22
-rw-r--r--src/systemd/sd-bus.h1
5 files changed, 43 insertions, 3 deletions
diff --git a/man/rules/meson.build b/man/rules/meson.build
index 303b584654..3602bbaa1a 100644
--- a/man/rules/meson.build
+++ b/man/rules/meson.build
@@ -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',
diff --git a/man/sd_bus_error.xml b/man/sd_bus_error.xml
index 807ca86302..c208f04cb6 100644
--- a/man/sd_bus_error.xml
+++ b/man/sd_bus_error.xml
@@ -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>
@@ -115,6 +116,12 @@
</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>
</funcprototype>
@@ -245,6 +252,14 @@
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,
@@ -287,9 +302,8 @@
<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
diff --git a/src/libsystemd/libsystemd.sym b/src/libsystemd/libsystemd.sym
index ba682b879a..8d0bebe2ad 100644
--- a/src/libsystemd/libsystemd.sym
+++ b/src/libsystemd/libsystemd.sym
@@ -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;
diff --git a/src/libsystemd/sd-bus/bus-error.c b/src/libsystemd/sd-bus/bus-error.c
index 0f79ddc427..e73f7057e1 100644
--- a/src/libsystemd/sd-bus/bus-error.c
+++ b/src/libsystemd/sd-bus/bus-error.c
@@ -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;
diff --git a/src/systemd/sd-bus.h b/src/systemd/sd-bus.h
index 5bc6965916..ce35756861 100644
--- a/src/systemd/sd-bus.h
+++ b/src/systemd/sd-bus.h
@@ -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);