From 154ca82e4436cc4ae30c647ab0cade5f909f7d3f Mon Sep 17 00:00:00 2001
From: Ondrej Oprala
Date: Thu, 21 Feb 2013 20:06:03 +0100
Subject: [PATCH] install: cleanup properly if the strip program failed for
any reason
* src/install.c (strip): Indicate failure with a return code instead
of terminating the program.
(install_file_in_file): Handle strip's return code and unlink the
created file if necessary.
* tests/install/strip-program.sh: Add a test to cover the changes.
---
src/install.c | 21 +++++++++++++++++----
tests/install/strip-program.sh | 5 +++++
2 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/src/install.c b/src/install.c
index 94374df..904c0ea 100644
--- a/src/install.c
+++ b/src/install.c
@@ -25,6 +25,7 @@
#include
#include
#include
+#include
#include "system.h"
#include "backupfile.h"
@@ -515,7 +516,7 @@ change_timestamps (struct stat const *src_sb, char const *dest)
magic numbers vary so much from system to system that making
it portable would be very difficult. Not worth the effort. */
-static void
+static int
strip (char const *name)
{
int status;
@@ -532,11 +533,18 @@ strip (char const *name)
break;
default: /* Parent. */
if (waitpid (pid, &status, 0) < 0)
- error (EXIT_FAILURE, errno, _("waiting for strip"));
+ {
+ error (0, errno, _("waiting for strip"));
+ return -1;
+ }
else if (! WIFEXITED (status) || WEXITSTATUS (status))
- error (EXIT_FAILURE, 0, _("strip process terminated abnormally"));
+ {
+ error (0, 0, _("strip process terminated abnormally"));
+ return -1;
+ }
break;
}
+ return 0;
}
/* Initialize the user and group ownership of the files to install. */
@@ -681,7 +689,12 @@ install_file_in_file (const char *from, const char *to,
if (! copy_file (from, to, x))
return false;
if (strip_files)
- strip (to);
+ if (strip (to))
+ {
+ if (unlink (to))
+ error (EXIT_FAILURE, errno, _("cannot unlink %s"), to);
+ return false;
+ }
if (x->preserve_timestamps && (strip_files || ! S_ISREG (from_sb.st_mode))
&& ! change_timestamps (&from_sb, to))
return false;
diff --git a/tests/install/strip-program.sh b/tests/install/strip-program.sh
index 8950d50..1ee4a7a 100755
--- a/tests/install/strip-program.sh
+++ b/tests/install/strip-program.sh
@@ -33,4 +33,9 @@ echo aBc > exp || fail=1
ginstall src dest -s --strip-program=./b || fail=1
compare exp dest || fail=1
+#check that install cleans up properly if strip fails
+
+ginstall src dest -s --strip-program=./FOO &>/dev/null && fail=1
+test -e dest && fail=1
+
Exit $fail
--
1.7.11.7