Blame SOURCES/coreutils-8.21-install-strip.patch

47d86b
From 3a20f6888575be7059e9acac07d397009e98c213 Mon Sep 17 00:00:00 2001
47d86b
From: Ondrej Oprala <ooprala@redhat.com>
47d86b
Date: Fri, 22 Feb 2013 12:48:57 +0000
47d86b
Subject: install: cleanup properly if the strip program failed for any reason
47d86b
47d86b
* src/install.c (strip): Indicate failure with a return code instead
47d86b
of terminating the program.
47d86b
(install_file_in_file): Handle strip's return code and unlink the
47d86b
created file if necessary.
47d86b
* tests/install/strip-program.sh: Add a test to cover the changes.
47d86b
---
47d86b
diff --git a/src/install.c b/src/install.c
47d86b
index 94374df..a5ed7a8 100644
47d86b
--- a/src/install.c
47d86b
+++ b/src/install.c
47d86b
@@ -515,16 +515,17 @@ change_timestamps (struct stat const *src_sb, char const *dest)
47d86b
    magic numbers vary so much from system to system that making
47d86b
    it portable would be very difficult.  Not worth the effort. */
47d86b
 
47d86b
-static void
47d86b
+static bool
47d86b
 strip (char const *name)
47d86b
 {
47d86b
   int status;
47d86b
+  bool ok = false;
47d86b
   pid_t pid = fork ();
47d86b
 
47d86b
   switch (pid)
47d86b
     {
47d86b
     case -1:
47d86b
-      error (EXIT_FAILURE, errno, _("fork system call failed"));
47d86b
+      error (0, errno, _("fork system call failed"));
47d86b
       break;
47d86b
     case 0:			/* Child. */
47d86b
       execlp (strip_program, strip_program, name, NULL);
47d86b
@@ -532,11 +533,14 @@ strip (char const *name)
47d86b
       break;
47d86b
     default:			/* Parent. */
47d86b
       if (waitpid (pid, &status, 0) < 0)
47d86b
-        error (EXIT_FAILURE, errno, _("waiting for strip"));
47d86b
+        error (0, errno, _("waiting for strip"));
47d86b
       else if (! WIFEXITED (status) || WEXITSTATUS (status))
47d86b
-        error (EXIT_FAILURE, 0, _("strip process terminated abnormally"));
47d86b
+        error (0, 0, _("strip process terminated abnormally"));
47d86b
+      else
47d86b
+        ok = true;      /* strip succeeded */
47d86b
       break;
47d86b
     }
47d86b
+  return ok;
47d86b
 }
47d86b
 
47d86b
 /* Initialize the user and group ownership of the files to install. */
47d86b
@@ -681,7 +685,12 @@ install_file_in_file (const char *from, const char *to,
47d86b
   if (! copy_file (from, to, x))
47d86b
     return false;
47d86b
   if (strip_files)
47d86b
-    strip (to);
47d86b
+    if (! strip (to))
47d86b
+      {
47d86b
+        if (unlink (to) != 0)  /* Cleanup.  */
47d86b
+          error (EXIT_FAILURE, errno, _("cannot unlink %s"), to);
47d86b
+        return false;
47d86b
+      }
47d86b
   if (x->preserve_timestamps && (strip_files || ! S_ISREG (from_sb.st_mode))
47d86b
       && ! change_timestamps (&from_sb, to))
47d86b
     return false;
47d86b
diff --git a/tests/install/strip-program.sh b/tests/install/strip-program.sh
47d86b
index 8950d50..5d65373 100755
47d86b
--- a/tests/install/strip-program.sh
47d86b
+++ b/tests/install/strip-program.sh
47d86b
@@ -33,4 +33,8 @@ echo aBc > exp || fail=1
47d86b
 ginstall src dest -s --strip-program=./b || fail=1
47d86b
 compare exp dest || fail=1
47d86b
 
47d86b
+# Check that install cleans up properly if strip fails.
47d86b
+ginstall src dest2 -s --strip-program=./FOO && fail=1
47d86b
+test -e dest2 && fail=1
47d86b
+
47d86b
 Exit $fail
47d86b
--
47d86b
cgit v0.9.0.2