chiark / gitweb /
sd-bus: make sure %m resolves to the specified error in bus_error_set_errnofv()
[elogind.git] / src / libsystemd / sd-bus / busctl.c
index 8cc309c01b46e9de2f248d8818d9ab9641db7d2a..febfc98a59f9834b55101669ead109b6360fb7d2 100644 (file)
@@ -90,7 +90,7 @@ static int list_bus_names(sd_bus *bus, char **argv) {
 
         r = sd_bus_list_names(bus, (arg_acquired || arg_unique) ? &acquired : NULL, arg_activatable ? &activatable : NULL);
         if (r < 0) {
-                log_error_errno(-r, "Failed to list names: %m");
+                log_error_errno(r, "Failed to list names: %m");
                 return r;
         }
 
@@ -105,7 +105,7 @@ static int list_bus_names(sd_bus *bus, char **argv) {
 
                 r = hashmap_put(names, *i, NAME_IS_ACQUIRED);
                 if (r < 0) {
-                        log_error_errno(-r, "Failed to add to hashmap: %m");
+                        log_error_errno(r, "Failed to add to hashmap: %m");
                         return r;
                 }
         }
@@ -115,7 +115,7 @@ static int list_bus_names(sd_bus *bus, char **argv) {
 
                 r = hashmap_put(names, *i, NAME_IS_ACTIVATABLE);
                 if (r < 0 && r != -EEXIST) {
-                        log_error_errno(-r, "Failed to add to hashmap: %m");
+                        log_error_errno(r, "Failed to add to hashmap: %m");
                         return r;
                 }
         }
@@ -439,7 +439,7 @@ static int tree(sd_bus *bus, char **argv) {
 
                 r = sd_bus_list_names(bus, &names, NULL);
                 if (r < 0) {
-                        log_error_errno(-r, "Failed to get name list: %m");
+                        log_error_errno(r, "Failed to get name list: %m");
                         return r;
                 }
 
@@ -1096,7 +1096,7 @@ static int monitor(sd_bus *bus, char *argv[], int (*dump)(sd_bus_message *m, FIL
 
                 r = sd_bus_add_match(bus, NULL, m, NULL, NULL);
                 if (r < 0) {
-                        log_error_errno(-r, "Failed to add match: %m");
+                        log_error_errno(r, "Failed to add match: %m");
                         return r;
                 }
 
@@ -1106,7 +1106,7 @@ static int monitor(sd_bus *bus, char *argv[], int (*dump)(sd_bus_message *m, FIL
         STRV_FOREACH(i, arg_matches) {
                 r = sd_bus_add_match(bus, NULL, *i, NULL, NULL);
                 if (r < 0) {
-                        log_error_errno(-r, "Failed to add match: %m");
+                        log_error_errno(r, "Failed to add match: %m");
                         return r;
                 }
 
@@ -1116,7 +1116,7 @@ static int monitor(sd_bus *bus, char *argv[], int (*dump)(sd_bus_message *m, FIL
         if (!added_something) {
                 r = sd_bus_add_match(bus, NULL, "", NULL, NULL);
                 if (r < 0) {
-                        log_error_errno(-r, "Failed to add match: %m");
+                        log_error_errno(r, "Failed to add match: %m");
                         return r;
                 }
         }
@@ -1126,7 +1126,7 @@ static int monitor(sd_bus *bus, char *argv[], int (*dump)(sd_bus_message *m, FIL
 
                 r = sd_bus_process(bus, &m);
                 if (r < 0) {
-                        log_error_errno(-r, "Failed to process bus: %m");
+                        log_error_errno(r, "Failed to process bus: %m");
                         return r;
                 }
 
@@ -1140,7 +1140,7 @@ static int monitor(sd_bus *bus, char *argv[], int (*dump)(sd_bus_message *m, FIL
 
                 r = sd_bus_wait(bus, (uint64_t) -1);
                 if (r < 0) {
-                        log_error_errno(-r, "Failed to wait for bus: %m");
+                        log_error_errno(r, "Failed to wait for bus: %m");
                         return r;
                 }
         }
@@ -1193,14 +1193,21 @@ static int status(sd_bus *bus, char *argv[]) {
                                         &creds,
                                         pid,
                                         _SD_BUS_CREDS_ALL);
-        } else
+        } else {
+                const char *scope;
+
+                r = sd_bus_get_scope(bus, &scope);
+                if (r >= 0)
+                        printf("Scope=%s%s%s\n", ansi_highlight(), scope, ansi_highlight_off());
+
                 r = sd_bus_get_owner_creds(
                                 bus,
                                 (arg_augment_creds ? SD_BUS_CREDS_AUGMENT : 0) | _SD_BUS_CREDS_ALL,
                                 &creds);
+        }
 
         if (r < 0) {
-                log_error_errno(-r, "Failed to get credentials: %m");
+                log_error_errno(r, "Failed to get credentials: %m");
                 return r;
         }
 
@@ -1962,7 +1969,7 @@ int main(int argc, char *argv[]) {
 
         r = sd_bus_new(&bus);
         if (r < 0) {
-                log_error_errno(-r, "Failed to allocate bus: %m");
+                log_error_errno(r, "Failed to allocate bus: %m");
                 goto finish;
         }
 
@@ -1971,25 +1978,25 @@ int main(int argc, char *argv[]) {
 
                 r = sd_bus_set_monitor(bus, true);
                 if (r < 0) {
-                        log_error_errno(-r, "Failed to set monitor mode: %m");
+                        log_error_errno(r, "Failed to set monitor mode: %m");
                         goto finish;
                 }
 
                 r = sd_bus_negotiate_creds(bus, true, _SD_BUS_CREDS_ALL);
                 if (r < 0) {
-                        log_error_errno(-r, "Failed to enable credentials: %m");
+                        log_error_errno(r, "Failed to enable credentials: %m");
                         goto finish;
                 }
 
                 r = sd_bus_negotiate_timestamp(bus, true);
                 if (r < 0) {
-                        log_error_errno(-r, "Failed to enable timestamps: %m");
+                        log_error_errno(r, "Failed to enable timestamps: %m");
                         goto finish;
                 }
 
                 r = sd_bus_negotiate_fds(bus, true);
                 if (r < 0) {
-                        log_error_errno(-r, "Failed to enable fds: %m");
+                        log_error_errno(r, "Failed to enable fds: %m");
                         goto finish;
                 }
         }
@@ -1999,17 +2006,20 @@ int main(int argc, char *argv[]) {
         else {
                 r = sd_bus_set_bus_client(bus, true);
                 if (r < 0) {
-                        log_error_errno(-r, "Failed to set bus client: %m");
+                        log_error_errno(r, "Failed to set bus client: %m");
                         goto finish;
                 }
 
                 switch (arg_transport) {
 
                 case BUS_TRANSPORT_LOCAL:
-                        if (arg_user)
+                        if (arg_user) {
+                                bus->is_user = true;
                                 r = bus_set_address_user(bus);
-                        else
+                        } else {
+                                bus->is_system = true;
                                 r = bus_set_address_system(bus);
+                        }
                         break;
 
                 case BUS_TRANSPORT_REMOTE:
@@ -2025,13 +2035,13 @@ int main(int argc, char *argv[]) {
                 }
         }
         if (r < 0) {
-                log_error_errno(-r, "Failed to set address: %m");
+                log_error_errno(r, "Failed to set address: %m");
                 goto finish;
         }
 
         r = sd_bus_start(bus);
         if (r < 0) {
-                log_error_errno(-r, "Failed to connect to bus: %m");
+                log_error_errno(r, "Failed to connect to bus: %m");
                 goto finish;
         }