summaryrefslogtreecommitdiffstats
path: root/man/vtable-example.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 03:50:42 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 03:50:42 +0000
commit78e9bb837c258ac0ec7712b3d612cc2f407e731e (patch)
treef515d16b6efd858a9aeb5b0ef5d6f90bf288283d /man/vtable-example.c
parentAdding debian version 255.5-1. (diff)
downloadsystemd-78e9bb837c258ac0ec7712b3d612cc2f407e731e.tar.xz
systemd-78e9bb837c258ac0ec7712b3d612cc2f407e731e.zip
Merging upstream version 256.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--man/vtable-example.c75
1 files changed, 53 insertions, 22 deletions
diff --git a/man/vtable-example.c b/man/vtable-example.c
index e3346a8..2e89944 100644
--- a/man/vtable-example.c
+++ b/man/vtable-example.c
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: MIT-0 */
+#define _GNU_SOURCE 1
#include <errno.h>
#include <stdbool.h>
#include <stddef.h>
@@ -9,20 +10,14 @@
#define _cleanup_(f) __attribute__((cleanup(f)))
-#define check(x) ({ \
- int r = (x); \
- errno = r < 0 ? -r : 0; \
- printf(#x ": %m\n"); \
- if (r < 0) \
- return EXIT_FAILURE; \
- })
-
typedef struct object {
char *name;
uint32_t number;
} object;
static int method(sd_bus_message *m, void *userdata, sd_bus_error *error) {
+ int r;
+
printf("Got called with userdata=%p\n", userdata);
if (sd_bus_message_is_method_call(m,
@@ -31,8 +26,17 @@ static int method(sd_bus_message *m, void *userdata, sd_bus_error *error) {
return 1;
const char *string;
- check(sd_bus_message_read(m, "s", &string));
- check(sd_bus_reply_method_return(m, "s", string));
+ r = sd_bus_message_read(m, "s", &string);
+ if (r < 0) {
+ fprintf(stderr, "sd_bus_message_read() failed: %s\n", strerror(-r));
+ return 0;
+ }
+
+ r = sd_bus_reply_method_return(m, "s", string);
+ if (r < 0) {
+ fprintf(stderr, "sd_bus_reply_method_return() failed: %s\n", strerror(-r));
+ return 0;
+ }
return 1;
}
@@ -84,28 +88,55 @@ static const sd_bus_vtable vtable[] = {
int main(int argc, char **argv) {
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
+ int r;
sd_bus_default(&bus);
object object = { .number = 666 };
- check((object.name = strdup("name")) != NULL);
+ object.name = strdup("name");
+ if (!object.name) {
+ fprintf(stderr, "OOM\n");
+ return EXIT_FAILURE;
+ }
- check(sd_bus_add_object_vtable(bus, NULL,
- "/org/freedesktop/systemd/VtableExample",
- "org.freedesktop.systemd.VtableExample",
- vtable,
- &object));
+ r = sd_bus_add_object_vtable(bus, NULL,
+ "/org/freedesktop/systemd/VtableExample",
+ "org.freedesktop.systemd.VtableExample",
+ vtable,
+ &object);
+ if (r < 0) {
+ fprintf(stderr, "sd_bus_add_object_vtable() failed: %s\n", strerror(-r));
+ return EXIT_FAILURE;
+ }
- check(sd_bus_request_name(bus,
- "org.freedesktop.systemd.VtableExample",
- 0));
+ r = sd_bus_request_name(bus,
+ "org.freedesktop.systemd.VtableExample",
+ 0);
+ if (r < 0) {
+ fprintf(stderr, "sd_bus_request_name() failed: %s\n", strerror(-r));
+ return EXIT_FAILURE;
+ }
for (;;) {
- check(sd_bus_wait(bus, UINT64_MAX));
- check(sd_bus_process(bus, NULL));
+ r = sd_bus_wait(bus, UINT64_MAX);
+ if (r < 0) {
+ fprintf(stderr, "sd_bus_wait() failed: %s\n", strerror(-r));
+ return EXIT_FAILURE;
+ }
+
+ r = sd_bus_process(bus, NULL);
+ if (r < 0) {
+ fprintf(stderr, "sd_bus_process() failed: %s\n", strerror(-r));
+ return EXIT_FAILURE;
+ }
+ }
+
+ r = sd_bus_release_name(bus, "org.freedesktop.systemd.VtableExample");
+ if (r < 0) {
+ fprintf(stderr, "sd_bus_release_name() failed: %s\n", strerror(-r));
+ return EXIT_FAILURE;
}
- check(sd_bus_release_name(bus, "org.freedesktop.systemd.VtableExample"));
free(object.name);
return 0;