chiark / gitweb /
event: rename sd_event_get() to sd_event_source_get_event()
[elogind.git] / src / libsystemd-bus / sd-bus.c
index 0ae52563e7524a51d90687523f8c0585ce50444b..85d1154433ed41d95a07732652ab9b6fa5840d0a 100644 (file)
@@ -365,7 +365,7 @@ _public_ int sd_bus_set_anonymous(sd_bus *bus, int b) {
         return 0;
 }
 
-static int hello_callback(sd_bus *bus, sd_bus_message *reply, void *userdata) {
+static int hello_callback(sd_bus *bus, sd_bus_message *reply, void *userdata, sd_bus_error *error) {
         const char *s;
         int r;
 
@@ -1824,6 +1824,7 @@ _public_ int sd_bus_get_timeout(sd_bus *bus, uint64_t *timeout_usec) {
 }
 
 static int process_timeout(sd_bus *bus) {
+        _cleanup_bus_error_free_ sd_bus_error error_buffer = SD_BUS_ERROR_NULL;
         _cleanup_bus_message_unref_ sd_bus_message* m = NULL;
         struct reply_callback *c;
         usec_t n;
@@ -1842,7 +1843,7 @@ static int process_timeout(sd_bus *bus) {
         r = bus_message_new_synthetic_error(
                         bus,
                         c->serial,
-                        &SD_BUS_ERROR_MAKE(SD_BUS_ERROR_NO_REPLY, "Method call timed out"),
+                        &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_NO_REPLY, "Method call timed out"),
                         &m);
         if (r < 0)
                 return r;
@@ -1857,12 +1858,13 @@ static int process_timeout(sd_bus *bus) {
         bus->current = m;
         bus->iteration_counter ++;
 
-        r = c->callback(bus, m, c->userdata);
+        r = c->callback(bus, m, c->userdata, &error_buffer);
+        r = bus_maybe_reply_error(m, r, &error_buffer);
         free(c);
 
         bus->current = NULL;
 
-        return r < 0 ? r : 1;
+        return r;
 }
 
 static int process_hello(sd_bus *bus, sd_bus_message *m) {
@@ -1888,6 +1890,7 @@ static int process_hello(sd_bus *bus, sd_bus_message *m) {
 }
 
 static int process_reply(sd_bus *bus, sd_bus_message *m) {
+        _cleanup_bus_error_free_ sd_bus_error error_buffer = SD_BUS_ERROR_NULL;
         struct reply_callback *c;
         int r;
 
@@ -1909,13 +1912,15 @@ static int process_reply(sd_bus *bus, sd_bus_message *m) {
         if (r < 0)
                 return r;
 
-        r = c->callback(bus, m, c->userdata);
+        r = c->callback(bus, m, c->userdata, &error_buffer);
+        r = bus_maybe_reply_error(m, r, &error_buffer);
         free(c);
 
-        return r < 0 ? r : 1;
+        return r;
 }
 
 static int process_filter(sd_bus *bus, sd_bus_message *m) {
+        _cleanup_bus_error_free_ sd_bus_error error_buffer = SD_BUS_ERROR_NULL;
         struct filter_callback *l;
         int r;
 
@@ -1940,7 +1945,8 @@ static int process_filter(sd_bus *bus, sd_bus_message *m) {
                         if (r < 0)
                                 return r;
 
-                        r = l->callback(bus, m, l->userdata);
+                        r = l->callback(bus, m, l->userdata, &error_buffer);
+                        r = bus_maybe_reply_error(m, r, &error_buffer);
                         if (r != 0)
                                 return r;
 
@@ -1986,7 +1992,7 @@ static int process_builtin(sd_bus *bus, sd_bus_message *m) {
                 return 1;
 
         if (streq_ptr(m->member, "Ping"))
-                r = sd_bus_message_new_method_return(bus, m, &reply);
+                r = sd_bus_message_new_method_return(m, &reply);
         else if (streq_ptr(m->member, "GetMachineId")) {
                 sd_id128_t id;
                 char sid[33];
@@ -1995,14 +2001,14 @@ static int process_builtin(sd_bus *bus, sd_bus_message *m) {
                 if (r < 0)
                         return r;
 
-                r = sd_bus_message_new_method_return(bus, m, &reply);
+                r = sd_bus_message_new_method_return(m, &reply);
                 if (r < 0)
                         return r;
 
                 r = sd_bus_message_append(reply, "s", sd_id128_to_string(id, sid));
         } else {
                 r = sd_bus_message_new_method_errorf(
-                                bus, m, &reply,
+                                m, &reply,
                                 SD_BUS_ERROR_UNKNOWN_METHOD,
                                  "Unknown method '%s' on interface '%s'.", m->member, m->interface);
         }
@@ -2097,7 +2103,7 @@ static int process_running(sd_bus *bus, sd_bus_message **ret) {
         if (m->header->type == SD_BUS_MESSAGE_METHOD_CALL) {
 
                 r = sd_bus_reply_method_errorf(
-                                bus, m,
+                                m,
                                 SD_BUS_ERROR_UNKNOWN_OBJECT,
                                 "Unknown object '%s'.", m->path);
                 if (r < 0)
@@ -2123,11 +2129,13 @@ static int process_closing(sd_bus *bus, sd_bus_message **ret) {
 
         c = hashmap_first(bus->reply_callbacks);
         if (c) {
+                _cleanup_bus_error_free_ sd_bus_error error_buffer = SD_BUS_ERROR_NULL;
+
                 /* First, fail all outstanding method calls */
                 r = bus_message_new_synthetic_error(
                                 bus,
                                 c->serial,
-                                &SD_BUS_ERROR_MAKE(SD_BUS_ERROR_NO_REPLY, "Connection terminated"),
+                                &SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_NO_REPLY, "Connection terminated"),
                                 &m);
                 if (r < 0)
                         return r;
@@ -2144,12 +2152,10 @@ static int process_closing(sd_bus *bus, sd_bus_message **ret) {
                 bus->current = m;
                 bus->iteration_counter++;
 
-                r = c->callback(bus, m, c->userdata);
+                r = c->callback(bus, m, c->userdata, &error_buffer);
+                r = bus_maybe_reply_error(m, r, &error_buffer);
                 free(c);
 
-                if (r >= 0)
-                        r = 1;
-
                 goto finish;
         }
 
@@ -2652,6 +2658,12 @@ _public_ int sd_bus_detach_event(sd_bus *bus) {
         return 0;
 }
 
+_public_ sd_event* sd_bus_get_event(sd_bus *bus) {
+        assert_return(bus, NULL);
+
+        return bus->event;
+}
+
 _public_ sd_bus_message* sd_bus_get_current(sd_bus *bus) {
         assert_return(bus, NULL);