summaryrefslogtreecommitdiff
path: root/src/systemctl
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-12-16 20:53:55 +0100
committerLennart Poettering <lennart@poettering.net>2013-12-16 21:06:57 +0100
commit999b600390a2dff43d3367119ad594b7c40ed50d (patch)
tree472c475fb84d2ef1b46dad1de016c751c037cc86 /src/systemctl
parent1c5f57c5a73a90513f1f9c1f534923323b61f68f (diff)
systemctl: properly initialize and free sd_bus_error in "systemctl cat"
We need to properly initialize all error structs before use and free them after use. Also, there's no point in flushing stdout if we output a \n anyway...
Diffstat (limited to 'src/systemctl')
-rw-r--r--src/systemctl/systemctl.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 9a76349b40..3e6a6883f6 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -3743,20 +3743,19 @@ static int show_all(
}
static int cat(sd_bus *bus, char **args) {
+ _cleanup_free_ char *unit = NULL, *n = NULL;
int r = 0;
char **name;
- _cleanup_free_ char *unit = NULL, *n = NULL;
-
assert(bus);
assert(args);
pager_open_if_enabled();
STRV_FOREACH(name, args+1) {
- _cleanup_free_ char *fragment_path = NULL;
+ _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_strv_free_ char **dropin_paths = NULL;
- sd_bus_error error;
+ _cleanup_free_ char *fragment_path = NULL;
char **path;
n = unit_name_mangle(*name);
@@ -3800,6 +3799,7 @@ static int cat(sd_bus *bus, char **args) {
if (!isempty(fragment_path)) {
fprintf(stdout, "# %s\n", fragment_path);
fflush(stdout);
+
r = sendfile_full(STDOUT_FILENO, fragment_path);
if (r < 0) {
log_warning("Failed to cat %s: %s", fragment_path, strerror(-r));
@@ -3812,6 +3812,7 @@ static int cat(sd_bus *bus, char **args) {
isempty(fragment_path) && path == dropin_paths ? "" : "\n",
*path);
fflush(stdout);
+
r = sendfile_full(STDOUT_FILENO, *path);
if (r < 0) {
log_warning("Failed to cat %s: %s", *path, strerror(-r));