chiark / gitweb /
Move function to cat file & dropins into basic/
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 26 Apr 2018 11:03:39 +0000 (13:03 +0200)
committerSven Eden <yamakuzure@gmx.net>
Fri, 24 Aug 2018 14:47:08 +0000 (16:47 +0200)
This fixes a buglet where the second and later drop-in would not be seperated
properly by a newline.

src/basic/terminal-util.c
src/basic/terminal-util.h

index 889de7c6a50c1af4674df3edae51ec5633d8bbdb..abd125f8f3df6a3a650288a25de9044edb86954e 100644 (file)
@@ -28,6 +28,7 @@
 #include <unistd.h>
 
 #include "alloc-util.h"
+//#include "copy.h"
 #include "env-util.h"
 #include "fd-util.h"
 #include "fileio.h"
@@ -1381,3 +1382,39 @@ int terminal_urlify_path(const char *path, const char *text, char **ret) {
 
         return terminal_urlify(url, text, ret);
 }
+
+static int cat_file(const char *filename, bool newline) {
+        _cleanup_close_ int fd;
+
+        fd = open(filename, O_RDONLY|O_CLOEXEC|O_NOCTTY);
+        if (fd < 0)
+                return -errno;
+
+        printf("%s%s# %s%s\n",
+               newline ? "\n" : "",
+               ansi_highlight_blue(),
+               filename,
+               ansi_normal());
+        fflush(stdout);
+
+        return copy_bytes(fd, STDOUT_FILENO, (uint64_t) -1, 0);
+}
+
+int cat_files(const char *file, char **dropins) {
+        char **path;
+        int r;
+
+        if (file) {
+                r = cat_file(file, false);
+                if (r < 0)
+                        return log_warning_errno(r, "Failed to cat %s: %m", file);
+        }
+
+        STRV_FOREACH(path, dropins) {
+                r = cat_file(*path, file || path != dropins);
+                if (r < 0)
+                        return log_warning_errno(r, "Failed to cat %s: %m", *path);
+        }
+
+        return 0;
+}
index b5e755eba745fad74a2de7dcbc91118438328c56..4550e1fc0046a2fed9eb42045a90613aeb1e22be 100644 (file)
@@ -177,3 +177,5 @@ int vt_reset_keyboard(int fd);
 
 int terminal_urlify(const char *url, const char *text, char **ret);
 int terminal_urlify_path(const char *path, const char *text, char **ret);
+
+int cat_files(const char *file, char **files);