chiark / gitweb /
treewide: use log_*_errno whenever %m is in the format string
[elogind.git] / src / run / run.c
index f8f0ea2832851f8f0fdb48d105eab70f1010e58e..d61f8db35096abaa1ccc055ece85b1caa9251cc9 100644 (file)
@@ -489,7 +489,7 @@ static int start_transient_scope(
 
         if (arg_nice_set) {
                 if (setpriority(PRIO_PROCESS, 0, arg_nice) < 0) {
-                        log_error("Failed to set nice level: %m");
+                        log_error_errno(errno, "Failed to set nice level: %m");
                         return -errno;
                 }
         }
@@ -498,13 +498,11 @@ static int start_transient_scope(
                 gid_t gid;
 
                 r = get_group_creds(&arg_exec_group, &gid);
-                if (r < 0) {
-                        log_error("Failed to resolve group %s: %s", arg_exec_group, strerror(-r));
-                        return r;
-                }
+                if (r < 0)
+                        return log_error_errno(r, "Failed to resolve group %s: %m", arg_exec_group);
 
                 if (setresgid(gid, gid, gid) < 0) {
-                        log_error("Failed to change GID to " GID_FMT ": %m", gid);
+                        log_error_errno(errno, "Failed to change GID to " GID_FMT ": %m", gid);
                         return -errno;
                 }
         }
@@ -515,10 +513,8 @@ static int start_transient_scope(
                 gid_t gid;
 
                 r = get_user_creds(&arg_exec_user, &uid, &gid, &home, &shell);
-                if (r < 0) {
-                        log_error("Failed to resolve user %s: %s", arg_exec_user, strerror(-r));
-                        return r;
-                }
+                if (r < 0)
+                        return log_error_errno(r, "Failed to resolve user %s: %m", arg_exec_user);
 
                 r = strv_extendf(&user_env, "HOME=%s", home);
                 if (r < 0)
@@ -538,13 +534,13 @@ static int start_transient_scope(
 
                 if (!arg_exec_group) {
                         if (setresgid(gid, gid, gid) < 0) {
-                                log_error("Failed to change GID to " GID_FMT ": %m", gid);
+                                log_error_errno(errno, "Failed to change GID to " GID_FMT ": %m", gid);
                                 return -errno;
                         }
                 }
 
                 if (setresuid(uid, uid, uid) < 0) {
-                        log_error("Failed to change UID to " UID_FMT ": %m", uid);
+                        log_error_errno(errno, "Failed to change UID to " UID_FMT ": %m", uid);
                         return -errno;
                 }
         }
@@ -556,13 +552,13 @@ static int start_transient_scope(
         log_info("Running as unit %s.", name);
 
         execvpe(argv[0], argv, env);
-        log_error("Failed to execute: %m");
+        log_error_errno(errno, "Failed to execute: %m");
         return -errno;
 }
 
 int main(int argc, char* argv[]) {
         _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
-        _cleanup_bus_unref_ sd_bus *bus = NULL;
+        _cleanup_bus_close_unref_ sd_bus *bus = NULL;
         _cleanup_free_ char *description = NULL, *command = NULL;
         int r;
 
@@ -573,9 +569,11 @@ int main(int argc, char* argv[]) {
         if (r <= 0)
                 goto finish;
 
-        r = find_binary(argv[optind], &command);
+        r = find_binary(argv[optind], arg_transport == BUS_TRANSPORT_LOCAL, &command);
         if (r < 0) {
-                log_error("Failed to find executable %s: %s", argv[optind], strerror(-r));
+                log_error_errno(r, "Failed to find executable %s%s: %m",
+                                argv[optind],
+                                arg_transport == BUS_TRANSPORT_LOCAL ? "" : " on local system");
                 goto finish;
         }
         argv[optind] = command;
@@ -592,7 +590,7 @@ int main(int argc, char* argv[]) {
 
         r = bus_open_transport_systemd(arg_transport, arg_host, arg_user, &bus);
         if (r < 0) {
-                log_error("Failed to create bus connection: %s", strerror(-r));
+                log_error_errno(r, "Failed to create bus connection: %m");
                 goto finish;
         }