chiark / gitweb /
udev link-config: add asserts to silence scan-build
[elogind.git] / src / systemctl / systemctl.c
index 9a76349b409ba5c79fbe92e58f392710e1f3e16f..aab92c466f2641e0d662ca7eab32acc1cc573914 100644 (file)
@@ -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);
@@ -3798,8 +3797,12 @@ static int cat(sd_bus *bus, char **args) {
                 }
 
                 if (!isempty(fragment_path)) {
-                        fprintf(stdout, "# %s\n", fragment_path);
+                        fprintf(stdout, "%s# %s%s\n",
+                                ansi_highlight_blue(),
+                                fragment_path,
+                                ansi_highlight_off());
                         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 +3815,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));
@@ -3820,7 +3824,7 @@ static int cat(sd_bus *bus, char **args) {
                 }
         }
 
-        return r;
+        return r < 0 ? r : 0;
 }
 
 static int show(sd_bus *bus, char **args) {