]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/delta/delta.c
util-lib: split our string related calls from util.[ch] into its own file string...
[thirdparty/systemd.git] / src / delta / delta.c
index 4753fb38c406e5f69f7f009014a2f5d21f316e1e..fbb6ab564b227473ca4db3d74d542c7f4fc8a1de 100644 (file)
 ***/
 
 #include <errno.h>
-#include <assert.h>
+#include <getopt.h>
 #include <string.h>
+#include <sys/prctl.h>
 #include <unistd.h>
-#include <getopt.h>
 
 #include "hashmap.h"
-#include "util.h"
-#include "path-util.h"
 #include "log.h"
 #include "pager.h"
-#include "build.h"
+#include "path-util.h"
+#include "process-util.h"
+#include "signal-util.h"
+#include "string-util.h"
 #include "strv.h"
+#include "terminal-util.h"
+#include "util.h"
 
 static const char prefixes[] =
         "/etc\0"
@@ -104,7 +107,7 @@ static int notify_override_masked(const char *top, const char *bottom) {
                 return 0;
 
         printf("%s%s%s     %s %s %s\n",
-               ansi_highlight_red(), "[MASKED]", ansi_highlight_off(),
+               ansi_highlight_red(), "[MASKED]", ansi_normal(),
                top, draw_special_char(DRAW_ARROW), bottom);
         return 1;
 }
@@ -114,7 +117,7 @@ static int notify_override_equivalent(const char *top, const char *bottom) {
                 return 0;
 
         printf("%s%s%s %s %s %s\n",
-               ansi_highlight_green(), "[EQUIVALENT]", ansi_highlight_off(),
+               ansi_highlight_green(), "[EQUIVALENT]", ansi_normal(),
                top, draw_special_char(DRAW_ARROW), bottom);
         return 1;
 }
@@ -123,8 +126,8 @@ static int notify_override_redirected(const char *top, const char *bottom) {
         if (!(arg_flags & SHOW_REDIRECTED))
                 return 0;
 
-        printf("%s%s%s   %s %s %s\n",
-               ansi_highlight(), "[REDIRECTED]", ansi_highlight_off(),
+        printf("%s%s%s %s %s %s\n",
+               ansi_highlight(), "[REDIRECTED]", ansi_normal(),
                top, draw_special_char(DRAW_ARROW), bottom);
         return 1;
 }
@@ -134,7 +137,7 @@ static int notify_override_overridden(const char *top, const char *bottom) {
                 return 0;
 
         printf("%s%s%s %s %s %s\n",
-               ansi_highlight(), "[OVERRIDDEN]", ansi_highlight_off(),
+               ansi_highlight(), "[OVERRIDDEN]", ansi_normal(),
                top, draw_special_char(DRAW_ARROW), bottom);
         return 1;
 }
@@ -144,7 +147,7 @@ static int notify_override_extended(const char *top, const char *bottom) {
                return 0;
 
         printf("%s%s%s   %s %s %s\n",
-               ansi_highlight(), "[EXTENDED]", ansi_highlight_off(),
+               ansi_highlight(), "[EXTENDED]", ansi_normal(),
                top, draw_special_char(DRAW_ARROW), bottom);
         return 1;
 }
@@ -185,16 +188,20 @@ static int found_override(const char *top, const char *bottom) {
         fflush(stdout);
 
         pid = fork();
-        if (pid < 0) {
-                log_error("Failed to fork off diff: %m");
-                return -errno;
-        } else if (pid == 0) {
+        if (pid < 0)
+                return log_error_errno(errno, "Failed to fork off diff: %m");
+        else if (pid == 0) {
+
+                (void) reset_all_signal_handlers();
+                (void) reset_signal_mask();
+                assert_se(prctl(PR_SET_PDEATHSIG, SIGTERM) == 0);
+
                 execlp("diff", "diff", "-us", "--", bottom, top, NULL);
-                log_error("Failed to execute diff: %m");
-                _exit(1);
+                log_error_errno(errno, "Failed to execute diff: %m");
+                _exit(EXIT_FAILURE);
         }
 
-        wait_for_terminate_and_warn("diff", pid);
+        wait_for_terminate_and_warn("diff", pid, false);
         putchar('\n');
 
         return k;
@@ -305,7 +312,7 @@ static int enumerate_dir(Hashmap *top, Hashmap *bottom, Hashmap *drops, const ch
                 if (errno == ENOENT)
                         return 0;
 
-                log_error("Failed to open %s: %m", path);
+                log_error_errno(errno, "Failed to open %s: %m", path);
                 return -errno;
         }
 
@@ -485,7 +492,7 @@ static int parse_flags(const char *flag_str, int flags) {
         const char *word, *state;
         size_t l;
 
-        FOREACH_WORD(word, l, flag_str, state) {
+        FOREACH_WORD_SEPARATOR(word, l, flag_str, ",", state) {
                 if (strneq("masked", word, l))
                         flags |= SHOW_MASKED;
                 else if (strneq ("equivalent", word, l))
@@ -537,9 +544,7 @@ static int parse_argv(int argc, char *argv[]) {
                         return 0;
 
                 case ARG_VERSION:
-                        puts(PACKAGE_STRING);
-                        puts(SYSTEMD_FEATURES);
-                        return 0;
+                        return version();
 
                 case ARG_NO_PAGER:
                         arg_no_pager = true;