X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fbus-proxyd%2Fproxy.c;h=a07c4036dfdb944eeedae5db5d0c6f11a1c3879c;hb=5f6cb091278906423f8b7e70c40131db7269916a;hp=0b8c448757f8f8013d96fe1c2d0b45a713a2b919;hpb=d27efd93841a2ac2127fd53321368cc3f975c564;p=elogind.git diff --git a/src/bus-proxyd/proxy.c b/src/bus-proxyd/proxy.c index 0b8c44875..a07c4036d 100644 --- a/src/bus-proxyd/proxy.c +++ b/src/bus-proxyd/proxy.c @@ -431,7 +431,7 @@ static int process_policy_unlocked(sd_bus *from, sd_bus *to, sd_bus_message *m, return 0; /* The message came from the kernel, and is sent to our legacy client. */ - sd_bus_creds_get_well_known_names(&m->creds, &sender_names); + (void) sd_bus_creds_get_well_known_names(&m->creds, &sender_names); (void) sd_bus_creds_get_euid(&m->creds, &sender_uid); (void) sd_bus_creds_get_egid(&m->creds, &sender_gid); @@ -492,7 +492,7 @@ static int process_policy_unlocked(sd_bus *from, sd_bus *to, sd_bus_message *m, if (r < 0) return handle_policy_error(m, r); - sd_bus_creds_get_well_known_names(destination_creds, &destination_names); + (void) sd_bus_creds_get_well_known_names(destination_creds, &destination_names); (void) sd_bus_creds_get_euid(destination_creds, &destination_uid); (void) sd_bus_creds_get_egid(destination_creds, &destination_gid); @@ -576,11 +576,11 @@ static int process_hello(Proxy *p, sd_bus_message *m) { if (p->got_hello) return 0; - return log_error_errno(-EIO, "First packet isn't hello (it's %s.%s), aborting.", m->interface, m->member); + return log_error_errno(EIO, "First packet isn't hello (it's %s.%s), aborting.", m->interface, m->member); } if (p->got_hello) - return log_error_errno(-EIO, "Got duplicate hello, aborting."); + return log_error_errno(EIO, "Got duplicate hello, aborting."); p->got_hello = true; @@ -673,13 +673,12 @@ static int proxy_process_destination_to_local(Proxy *p) { assert(p); r = sd_bus_process(p->destination_bus, &m); + if (r == -ECONNRESET) /* Treat 'connection reset by peer' as clean exit condition */ + return r; if (r < 0) { - /* treat 'connection reset by peer' as clean exit condition */ - if (r != -ECONNRESET) - log_error_errno(r, "Failed to process destination bus: %m"); + log_error_errno(r, "Failed to process destination bus: %m"); return r; } - if (r == 0) return 0; if (!m) @@ -699,29 +698,35 @@ static int proxy_process_destination_to_local(Proxy *p) { r = process_policy(p->destination_bus, p->local_bus, m, p->policy, &p->local_creds, p->owned_names); if (r < 0) return log_error_errno(r, "Failed to process policy: %m"); - else if (r > 0) + if (r > 0) return 1; } r = sd_bus_send(p->local_bus, m, NULL); if (r < 0) { - if (r == -EPERM && m->reply_cookie > 0) { - /* If the peer tries to send a reply and it is rejected with EPERM - * by the kernel, we ignore the error. This catches cases where the - * original method-call didn't had EXPECT_REPLY set, but the proxy-peer - * still sends a reply. This is allowed in dbus1, but not in kdbus. We - * don't want to track reply-windows in the proxy, so we simply ignore - * EPERM for all replies. The only downside is, that callers are no - * longer notified if their replies are dropped. However, this is - * equivalent to the caller's timeout to expire, so this should be - * acceptable. Nobody sane sends replies without a matching method-call, - * so nobody should care. */ - return 1; - } else { - if (r != -ECONNRESET) - log_error_errno(r, "Failed to send message to client: %m"); + if (r == -ECONNRESET) return r; - } + + /* If the peer tries to send a reply and it is + * rejected with EPERM by the kernel, we ignore the + * error. This catches cases where the original + * method-call didn't had EXPECT_REPLY set, but the + * proxy-peer still sends a reply. This is allowed in + * dbus1, but not in kdbus. We don't want to track + * reply-windows in the proxy, so we simply ignore + * EPERM for all replies. The only downside is, that + * callers are no longer notified if their replies are + * dropped. However, this is equivalent to the + * caller's timeout to expire, so this should be + * acceptable. Nobody sane sends replies without a + * matching method-call, so nobody should care. */ + if (r == -EPERM && m->reply_cookie > 0) + return 1; + + /* Return the error to the client, if we can */ + synthetic_reply_method_errnof(m, r, "Failed to forward message we got from destination: %m"); + log_error_errno(r, "Failed to send message to client, ignoring: %m"); + return 1; } return 1; @@ -734,13 +739,12 @@ static int proxy_process_local_to_destination(Proxy *p) { assert(p); r = sd_bus_process(p->local_bus, &m); + if (r == -ECONNRESET) /* Treat 'connection reset by peer' as clean exit condition */ + return r; if (r < 0) { - /* treat 'connection reset by peer' as clean exit condition */ - if (r != -ECONNRESET) - log_error_errno(r, "Failed to process local bus: %m"); + log_error_errno(r, "Failed to process local bus: %m"); return r; } - if (r == 0) return 0; if (!m) @@ -753,13 +757,13 @@ static int proxy_process_local_to_destination(Proxy *p) { r = process_hello(p, m); if (r < 0) return log_error_errno(r, "Failed to process HELLO: %m"); - else if (r > 0) + if (r > 0) return 1; r = bus_proxy_process_driver(p->destination_bus, p->local_bus, m, p->policy, &p->local_creds, p->owned_names); if (r < 0) return log_error_errno(r, "Failed to process driver calls: %m"); - else if (r > 0) + if (r > 0) return 1; for (;;) { @@ -773,17 +777,20 @@ static int proxy_process_local_to_destination(Proxy *p) { r = sd_bus_send(p->destination_bus, m, NULL); if (r < 0) { - if (r == -EREMCHG) { - /* The name database changed since the policy check, hence let's check again */ + if (r == -ECONNRESET) + return r; + + /* The name database changed since the policy check, hence let's check again */ + if (r == -EREMCHG) continue; - } else if (r == -EPERM && m->reply_cookie > 0) { - /* see above why EPERM is ignored for replies */ + + /* see above why EPERM is ignored for replies */ + if (r == -EPERM && m->reply_cookie > 0) return 1; - } else { - if (r != -ECONNRESET) - log_error_errno(r, "Failed to send message to bus: %m"); - return r; - } + + synthetic_reply_method_errnof(m, r, "Failed to forward message we got from local: %m"); + log_error_errno(r, "Failed to send message to bus: %m"); + return 1; } break; @@ -805,9 +812,9 @@ int proxy_run(Proxy *p) { r = proxy_process_destination_to_local(p); if (r == -ECONNRESET) return 0; - else if (r < 0) + if (r < 0) return r; - else if (r > 0) + if (r > 0) busy = true; } @@ -815,9 +822,9 @@ int proxy_run(Proxy *p) { r = proxy_process_local_to_destination(p); if (r == -ECONNRESET) return 0; - else if (r < 0) + if (r < 0) return r; - else if (r > 0) + if (r > 0) busy = true; if (!busy) {