mboxd_dbus: Handle errors in reply path

We were seeing some odd errors in the journal, for example:

	dbus[736]: [system] Rejected send message, 0 matched rules; type="error", sender=":1.14" (uid=0 pid=773 comm="/usr/sbin/mboxd --flash 64M --verbose --window-siz") interface="(unset)" member="(unset)" error name="org.freedesktop.DBus.Error.UnknownMethod" requested_reply="0" destination=":1.123" (uid=0 pid=2157 comm="/usr/sbin/mboxctl --reset ")

However, coinciding with the deployment of the patched mboxd the errors
went away. This patch shouldn't fix whatever was going on, but at
least we might see some report of problems in the reply codepath if it
occurs again in the future.

Change-Id: I90dc4dd8e69e3fc998ab7f04cbeec37c20c92bcf
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/mboxd_dbus.c b/mboxd_dbus.c
index 3b09bb1..a72e48b 100644
--- a/mboxd_dbus.c
+++ b/mboxd_dbus.c
@@ -314,12 +314,31 @@
 	if (rc < 0) {
 		resp.cmd = -rc;
 	}
-	sd_bus_message_new_method_return(m, &n); /* Generate response */
-	sd_bus_message_append(n, "y", resp.cmd); /* Set return code */
-	sd_bus_message_append_array(n, 'y', resp.args, resp.num_args);
-	sd_bus_send(sd_bus_message_get_bus(m), n, NULL); /* Send response */
+	rc = sd_bus_message_new_method_return(m, &n); /* Generate response */
+	if (rc < 0) {
+		MSG_ERR("sd_bus_message_new_method_return failed: %d\n", rc);
+		goto cleanup;
+	}
+
+	rc = sd_bus_message_append(n, "y", resp.cmd); /* Set return code */
+	if (rc < 0) {
+		MSG_ERR("sd_bus_message_append failed: %d\n", rc);
+		goto cleanup;
+	}
+
+	rc = sd_bus_message_append_array(n, 'y', resp.args, resp.num_args);
+	if (rc < 0) {
+		MSG_ERR("sd_bus_message_append_array failed: %d\n", rc);
+		goto cleanup;
+	}
+
+	rc = sd_bus_send(NULL, n, NULL); /* Send response */
+	if (rc < 0)
+		MSG_ERR("sd_bus_send failed: %d\n", rc);
+
+cleanup:
 	free(resp.args);
-	return 0;
+	return rc;
 }
 
 static const sd_bus_vtable mboxd_vtable[] = {