chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
treewide: use log_*_errno whenever %m is in the format string
[elogind.git]
/
src
/
systemctl
/
systemctl.c
diff --git
a/src/systemctl/systemctl.c
b/src/systemctl/systemctl.c
index d9e9c2a6c32087b1c9b955fe3461f0242b7fa934..69f157cebbc625db448ebd444ccfa21b1e10b8e1 100644
(file)
--- a/
src/systemctl/systemctl.c
+++ b/
src/systemctl/systemctl.c
@@
-67,6
+67,7
@@
#include "logs-show.h"
#include "socket-util.h"
#include "fileio.h"
#include "logs-show.h"
#include "socket-util.h"
#include "fileio.h"
+#include "copy.h"
#include "env-util.h"
#include "bus-util.h"
#include "bus-message.h"
#include "env-util.h"
#include "bus-util.h"
#include "bus-message.h"
@@
-621,7
+622,7
@@
static int get_unit_list_recursive(
r = sd_bus_open_system_container(&container, *i);
if (r < 0) {
r = sd_bus_open_system_container(&container, *i);
if (r < 0) {
- log_error
("Failed to connect to container %s: %s", *i, strerror(-r)
);
+ log_error
_errno(r, "Failed to connect to container %s: %m", *i
);
continue;
}
continue;
}
@@
-1359,7
+1360,7
@@
static int list_unit_files(sd_bus *bus, char **args) {
r = unit_file_get_list(arg_scope, arg_root, h);
if (r < 0) {
unit_file_list_free(h);
r = unit_file_get_list(arg_scope, arg_root, h);
if (r < 0) {
unit_file_list_free(h);
- log_error
("Failed to get unit file list: %s", strerror(-r)
);
+ log_error
_errno(r, "Failed to get unit file list: %m"
);
return r;
}
return r;
}
@@
-1479,11
+1480,13
@@
static int list_dependencies_get_dependencies(sd_bus *bus, const char *name, cha
"RequiresOverridable\0"
"Requisite\0"
"RequisiteOverridable\0"
"RequiresOverridable\0"
"Requisite\0"
"RequisiteOverridable\0"
- "Wants\0",
+ "Wants\0"
+ "BindsTo\0",
[DEPENDENCY_REVERSE] = "RequiredBy\0"
"RequiredByOverridable\0"
"WantedBy\0"
[DEPENDENCY_REVERSE] = "RequiredBy\0"
"RequiredByOverridable\0"
"WantedBy\0"
- "PartOf\0",
+ "PartOf\0"
+ "BoundBy\0",
[DEPENDENCY_AFTER] = "After\0",
[DEPENDENCY_BEFORE] = "Before\0",
};
[DEPENDENCY_AFTER] = "After\0",
[DEPENDENCY_BEFORE] = "Before\0",
};
@@
-1903,10
+1906,8
@@
static int get_default(sd_bus *bus, char **args) {
if (!bus || avoid_bus()) {
r = unit_file_get_default(arg_scope, arg_root, &_path);
if (!bus || avoid_bus()) {
r = unit_file_get_default(arg_scope, arg_root, &_path);
- if (r < 0) {
- log_error("Failed to get default target: %s", strerror(-r));
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to get default target: %m");
path = _path;
} else {
path = _path;
} else {
@@
-1986,10
+1987,8
@@
static int set_default(sd_bus *bus, char **args) {
if (!bus || avoid_bus()) {
r = unit_file_set_default(arg_scope, arg_root, unit, true, &changes, &n_changes);
if (!bus || avoid_bus()) {
r = unit_file_set_default(arg_scope, arg_root, unit, true, &changes, &n_changes);
- if (r < 0) {
- log_error("Failed to set default target: %s", strerror(-r));
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to set default target: %m");
if (!arg_quiet)
dump_unit_file_changes(changes, n_changes);
if (!arg_quiet)
dump_unit_file_changes(changes, n_changes);
@@
-2197,10
+2196,8
@@
static int cancel_job(sd_bus *bus, char **args) {
int q;
q = safe_atou32(*name, &id);
int q;
q = safe_atou32(*name, &id);
- if (q < 0) {
- log_error("Failed to parse job id \"%s\": %s", *name, strerror(-q));
- return q;
- }
+ if (q < 0)
+ return log_error_errno(q, "Failed to parse job id \"%s\": %m", *name);
q = sd_bus_message_new_method_call(
bus,
q = sd_bus_message_new_method_call(
bus,
@@
-2428,10
+2425,8
@@
static int wait_for_jobs(sd_bus *bus, Set *s) {
while (!set_isempty(s)) {
q = bus_process_wait(bus);
while (!set_isempty(s)) {
q = bus_process_wait(bus);
- if (q < 0) {
- log_error("Failed to wait for response: %s", strerror(-q));
- return q;
- }
+ if (q < 0)
+ return log_error_errno(q, "Failed to wait for response: %m");
if (d.result) {
q = check_wait_response(&d);
if (d.result) {
q = check_wait_response(&d);
@@
-2557,10
+2552,8
@@
static int check_triggering_units(
STRV_FOREACH(i, triggered_by) {
r = check_one_unit(bus, *i, "active\0reloading\0", true);
STRV_FOREACH(i, triggered_by) {
r = check_one_unit(bus, *i, "active\0reloading\0", true);
- if (r < 0) {
- log_error("Failed to check unit: %s", strerror(-r));
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to check unit: %m");
if (r == 0)
continue;
if (r == 0)
continue;
@@
-2804,15
+2797,13
@@
static int start_unit(sd_bus *bus, char **args) {
else {
r = expand_names(bus, args + 1, suffix, &names);
if (r < 0)
else {
r = expand_names(bus, args + 1, suffix, &names);
if (r < 0)
- log_error
("Failed to expand names: %s", strerror(-r)
);
+ log_error
_errno(r, "Failed to expand names: %m"
);
}
if (!arg_no_block) {
r = enable_wait_for_jobs(bus);
}
if (!arg_no_block) {
r = enable_wait_for_jobs(bus);
- if (r < 0) {
- log_error("Could not watch jobs: %s", strerror(-r));
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Could not watch jobs: %m");
s = set_new(&string_hash_ops);
if (!s)
s = set_new(&string_hash_ops);
if (!s)
@@
-3071,10
+3062,8
@@
static int check_unit_generic(sd_bus *bus, int code, const char *good_states, ch
assert(args);
r = expand_names(bus, args, NULL, &names);
assert(args);
r = expand_names(bus, args, NULL, &names);
- if (r < 0) {
- log_error("Failed to expand names: %s", strerror(-r));
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to expand names: %m");
STRV_FOREACH(name, names) {
int state;
STRV_FOREACH(name, names) {
int state;
@@
-3112,7
+3101,7
@@
static int kill_unit(sd_bus *bus, char **args) {
r = expand_names(bus, args + 1, NULL, &names);
if (r < 0)
r = expand_names(bus, args + 1, NULL, &names);
if (r < 0)
- log_error
("Failed to expand names: %s", strerror(-r)
);
+ log_error
_errno(r, "Failed to expand names: %m"
);
STRV_FOREACH(name, names) {
_cleanup_bus_message_unref_ sd_bus_message *m = NULL;
STRV_FOREACH(name, names) {
_cleanup_bus_message_unref_ sd_bus_message *m = NULL;
@@
-4435,10
+4424,8
@@
static int show_system_status(sd_bus *bus) {
return log_oom();
r = bus_map_all_properties(bus, "org.freedesktop.systemd1", "/org/freedesktop/systemd1", machine_info_property_map, &mi);
return log_oom();
r = bus_map_all_properties(bus, "org.freedesktop.systemd1", "/org/freedesktop/systemd1", machine_info_property_map, &mi);
- if (r < 0) {
- log_error("Failed to read server status: %s", strerror(-r));
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to read server status: %m");
if (streq_ptr(mi.state, "degraded")) {
on = ansi_highlight_red();
if (streq_ptr(mi.state, "degraded")) {
on = ansi_highlight_red();
@@
-4555,7
+4542,7
@@
static int show(sd_bus *bus, char **args) {
r = expand_names(bus, patterns, NULL, &names);
if (r < 0)
r = expand_names(bus, patterns, NULL, &names);
if (r < 0)
- log_error
("Failed to expand names: %s", strerror(-r)
);
+ log_error
_errno(r, "Failed to expand names: %m"
);
STRV_FOREACH(name, names) {
_cleanup_free_ char *unit;
STRV_FOREACH(name, names) {
_cleanup_free_ char *unit;
@@
-4591,7
+4578,7
@@
static int cat(sd_bus *bus, char **args) {
r = expand_names(bus, args + 1, NULL, &names);
if (r < 0)
r = expand_names(bus, args + 1, NULL, &names);
if (r < 0)
- log_error
("Failed to expand names: %s", strerror(-r)
);
+ log_error
_errno(r, "Failed to expand names: %m"
);
pager_open_if_enabled();
pager_open_if_enabled();
@@
-4647,9
+4634,9
@@
static int cat(sd_bus *bus, char **args) {
ansi_highlight_off());
fflush(stdout);
ansi_highlight_off());
fflush(stdout);
- r =
sendfile_full(STDOUT_FILENO, fragment_path
);
+ r =
copy_file_fd(fragment_path, STDOUT_FILENO
);
if (r < 0) {
if (r < 0) {
- log_warning
("Failed to cat %s: %s", fragment_path, strerror(-r)
);
+ log_warning
_errno(r, "Failed to cat %s: %m", fragment_path
);
continue;
}
}
continue;
}
}
@@
-4662,9
+4649,9
@@
static int cat(sd_bus *bus, char **args) {
ansi_highlight_off());
fflush(stdout);
ansi_highlight_off());
fflush(stdout);
- r =
sendfile_full(STDOUT_FILENO, *path
);
+ r =
copy_file_fd(*path, STDOUT_FILENO
);
if (r < 0) {
if (r < 0) {
- log_warning
("Failed to cat %s: %s", *path, strerror(-r)
);
+ log_warning
_errno(r, "Failed to cat %s: %m", *path
);
continue;
}
}
continue;
}
}
@@
-4804,7
+4791,7
@@
static int delete_snapshot(sd_bus *bus, char **args) {
r = expand_names(bus, args + 1, ".snapshot", &names);
if (r < 0)
r = expand_names(bus, args + 1, ".snapshot", &names);
if (r < 0)
- log_error
("Failed to expand names: %s", strerror(-r)
);
+ log_error
_errno(r, "Failed to expand names: %m"
);
STRV_FOREACH(name, names) {
_cleanup_bus_message_unref_ sd_bus_message *m = NULL;
STRV_FOREACH(name, names) {
_cleanup_bus_message_unref_ sd_bus_message *m = NULL;
@@
-4905,7
+4892,7
@@
static int reset_failed(sd_bus *bus, char **args) {
r = expand_names(bus, args + 1, NULL, &names);
if (r < 0)
r = expand_names(bus, args + 1, NULL, &names);
if (r < 0)
- log_error
("Failed to expand names: %s", strerror(-r)
);
+ log_error
_errno(r, "Failed to expand names: %m"
);
STRV_FOREACH(name, names) {
_cleanup_bus_message_unref_ sd_bus_message *m = NULL;
STRV_FOREACH(name, names) {
_cleanup_bus_message_unref_ sd_bus_message *m = NULL;
@@
-4999,7
+4986,7
@@
static int switch_root(sd_bus *bus, char **args) {
"init", &cmdline_init,
NULL);
if (r < 0)
"init", &cmdline_init,
NULL);
if (r < 0)
- log_debug
("Failed to parse /proc/cmdline: %s", strerror(-r)
);
+ log_debug
_errno(r, "Failed to parse /proc/cmdline: %m"
);
init = cmdline_init;
}
init = cmdline_init;
}
@@
-5233,7
+5220,7
@@
static int enable_sysv_units(const char *verb, char **args) {
pid = fork();
if (pid < 0) {
pid = fork();
if (pid < 0) {
- log_error
(
"Failed to fork: %m");
+ log_error
_errno(errno,
"Failed to fork: %m");
return -errno;
} else if (pid == 0) {
/* Child */
return -errno;
} else if (pid == 0) {
/* Child */
@@
-5244,7
+5231,7
@@
static int enable_sysv_units(const char *verb, char **args) {
j = wait_for_terminate(pid, &status);
if (j < 0) {
j = wait_for_terminate(pid, &status);
if (j < 0) {
- log_error
("Failed to wait for child: %s", strerror(-r)
);
+ log_error
_errno(r, "Failed to wait for child: %m"
);
return j;
}
return j;
}
@@
-5358,7
+5345,7
@@
static int enable_unit(sd_bus *bus, char **args) {
assert_not_reached("Unknown verb");
if (r < 0) {
assert_not_reached("Unknown verb");
if (r < 0) {
- log_error
("Operation failed: %s", strerror(-r)
);
+ log_error
_errno(r, "Operation failed: %m"
);
goto finish;
}
goto finish;
}
@@
-5506,10
+5493,8
@@
static int add_dependency(sd_bus *bus, char **args) {
r = unit_file_add_dependency(arg_scope, arg_runtime, arg_root, names, target, dep, arg_force, &changes, &n_changes);
r = unit_file_add_dependency(arg_scope, arg_runtime, arg_root, names, target, dep, arg_force, &changes, &n_changes);
- if (r < 0) {
- log_error("Can't add dependency: %s", strerror(-r));
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Can't add dependency: %m");
if (!arg_quiet)
dump_unit_file_changes(changes, n_changes);
if (!arg_quiet)
dump_unit_file_changes(changes, n_changes);
@@
-5570,7
+5555,7
@@
static int preset_all(sd_bus *bus, char **args) {
r = unit_file_preset_all(arg_scope, arg_runtime, arg_root, arg_preset_mode, arg_force, &changes, &n_changes);
if (r < 0) {
r = unit_file_preset_all(arg_scope, arg_runtime, arg_root, arg_preset_mode, arg_force, &changes, &n_changes);
if (r < 0) {
- log_error
("Operation failed: %s", strerror(-r)
);
+ log_error
_errno(r, "Operation failed: %m"
);
goto finish;
}
goto finish;
}
@@
-5652,14
+5637,13
@@
static int unit_is_enabled(sd_bus *bus, char **args) {
UnitFileState state;
state = unit_file_get_state(arg_scope, arg_root, *name);
UnitFileState state;
state = unit_file_get_state(arg_scope, arg_root, *name);
- if (state < 0) {
- log_error("Failed to get unit file state for %s: %s", *name, strerror(-state));
- return state;
- }
+ if (state < 0)
+ return log_error_errno(state, "Failed to get unit file state for %s: %m", *name);
if (state == UNIT_FILE_ENABLED ||
state == UNIT_FILE_ENABLED_RUNTIME ||
if (state == UNIT_FILE_ENABLED ||
state == UNIT_FILE_ENABLED_RUNTIME ||
- state == UNIT_FILE_STATIC)
+ state == UNIT_FILE_STATIC ||
+ state == UNIT_FILE_INDIRECT)
enabled = true;
if (!arg_quiet)
enabled = true;
if (!arg_quiet)
@@
-5689,9
+5673,7
@@
static int unit_is_enabled(sd_bus *bus, char **args) {
if (r < 0)
return bus_log_parse_error(r);
if (r < 0)
return bus_log_parse_error(r);
- if (streq(s, "enabled") ||
- streq(s, "enabled-runtime") ||
- streq(s, "static"))
+ if (STR_IN_SET(s, "enabled", "enabled-runtime", "static", "indirect"))
enabled = true;
if (!arg_quiet)
enabled = true;
if (!arg_quiet)
@@
-6739,14
+6721,14
@@
static int talk_initctl(void) {
if (errno == ENOENT)
return 0;
if (errno == ENOENT)
return 0;
- log_error
(
"Failed to open "INIT_FIFO": %m");
+ log_error
_errno(errno,
"Failed to open "INIT_FIFO": %m");
return -errno;
}
errno = 0;
r = loop_write(fd, &request, sizeof(request), false) != sizeof(request);
if (r) {
return -errno;
}
errno = 0;
r = loop_write(fd, &request, sizeof(request), false) != sizeof(request);
if (r) {
- log_error
(
"Failed to write to "INIT_FIFO": %m");
+ log_error
_errno(errno,
"Failed to write to "INIT_FIFO": %m");
return errno > 0 ? -errno : -EIO;
}
return errno > 0 ? -errno : -EIO;
}
@@
-6895,7
+6877,7
@@
found:
* enable/disable */
if (verb->bus == NOBUS) {
if (!bus && !avoid_bus()) {
* enable/disable */
if (verb->bus == NOBUS) {
if (!bus && !avoid_bus()) {
- log_error
("Failed to get D-Bus connection: %s", strerror(-bus_error)
);
+ log_error
_errno(bus_error, "Failed to get D-Bus connection: %m"
);
return -EIO;
}
return -EIO;
}
@@
-6906,7
+6888,7
@@
found:
}
if ((verb->bus != FORCE || arg_force <= 0) && !bus) {
}
if ((verb->bus != FORCE || arg_force <= 0) && !bus) {
- log_error
("Failed to get D-Bus connection: %s", strerror(-bus_error)
);
+ log_error
_errno(bus_error, "Failed to get D-Bus connection: %m"
);
return -EIO;
}
}
return -EIO;
}
}
@@
-6971,7
+6953,7
@@
static int reload_with_fallback(sd_bus *bus) {
assert(arg_action == ACTION_RELOAD || arg_action == ACTION_REEXEC);
if (kill(1, arg_action == ACTION_RELOAD ? SIGHUP : SIGTERM) < 0) {
assert(arg_action == ACTION_RELOAD || arg_action == ACTION_REEXEC);
if (kill(1, arg_action == ACTION_RELOAD ? SIGHUP : SIGTERM) < 0) {
- log_error
(
"kill() failed: %m");
+ log_error
_errno(errno,
"kill() failed: %m");
return -errno;
}
return -errno;
}
@@
-7084,7
+7066,7
@@
static int halt_main(sd_bus *bus) {
m);
if (r < 0)
m);
if (r < 0)
- log_warning
("Failed to talk to shutdownd, proceeding with immediate shutdown: %s", strerror(-r)
);
+ log_warning
_errno(r, "Failed to talk to shutdownd, proceeding with immediate shutdown: %m"
);
else {
char date[FORMAT_TIMESTAMP_MAX];
else {
char date[FORMAT_TIMESTAMP_MAX];
@@
-7103,7
+7085,7
@@
static int halt_main(sd_bus *bus) {
else {
r = utmp_put_shutdown();
if (r < 0)
else {
r = utmp_put_shutdown();
if (r < 0)
- log_warning
("Failed to write utmp record: %s", strerror(-r)
);
+ log_warning
_errno(r, "Failed to write utmp record: %m"
);
}
}
}
}
@@
-7111,7
+7093,7
@@
static int halt_main(sd_bus *bus) {
return 0;
r = halt_now(arg_action);
return 0;
r = halt_now(arg_action);
- log_error
("Failed to reboot: %s", strerror(-r)
);
+ log_error
_errno(r, "Failed to reboot: %m"
);
return r;
}
return r;
}
@@
-7209,7
+7191,7
@@
int main(int argc, char*argv[]) {
r = send_shutdownd(arg_when, SD_SHUTDOWN_NONE, false, !arg_no_wall, m);
if (r < 0)
r = send_shutdownd(arg_when, SD_SHUTDOWN_NONE, false, !arg_no_wall, m);
if (r < 0)
- log_warning
("Failed to talk to shutdownd, shutdown hasn't been cancelled: %s", strerror(-r)
);
+ log_warning
_errno(r, "Failed to talk to shutdownd, shutdown hasn't been cancelled: %m"
);
break;
}
break;
}