* install-sh -s on readonly file
@ 2019-08-26 0:52 Karl Berry
2019-08-26 2:13 ` Paul Eggert
0 siblings, 1 reply; 4+ messages in thread
From: Karl Berry @ 2019-08-26 0:52 UTC (permalink / raw)
To: bug-gnulib
Hi - I sent this possible patch for install-sh to bug-automake
(https://debbugs.gnu.org/cgi/bugreport.cgi?bug=36966, appended below for
convenience). My fix seems clunky to me, but neither Jim nor I could
think of a better way and there were no replies on the list. I just
thought I'd send it here to see if anyone had any ideas before we
install it ... --thanks, karl.
From: Karl Berry <karl@freefriends.org>
To: bug-automake@gnu.org
Subject: install-sh -s on 555 executable fails
(I'm not on this list, so please keep me in cc if need be.)
It seems that install-sh -s (what automake's install-strip target can
end up doing) fails if the original file doesn't have the owner-write
bit set:
cp /bin/cp /tmp/rx # any binary will do
chmod 555 /tmp/rx # make unwritable to owner
install-sh -s /tmp/rx /tmp/sx # try to install, with strip
-> strip: unable to copy file '/tmp/_inst.31092_'; reason: Permission denied
echo $?
-> 1
Although install-sh (version 2018-03-11.20, lines 224ff.) does some
stuff to ensure that umask will not clear an owner-writable bit in the
destination, that's not enough to make it owner-writable if it's not
already.
The only less-than-wonderful fix I could come up with is to explicitly
do chmod u+w if strip is being executed. I thought maybe it would be
worth trying the strip even if the chmod failed, hence the ; instead of
&&, but it's not something I feel strongly about. And maybe there is
some nicer way to do it altogether.
--- a/build-aux/install-sh
+++ b/build-aux/install-sh
@@ -461,7 +461,7 @@ do
#
{ test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } &&
{ test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } &&
- { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } &&
+ { test -z "$stripcmd" || ($doit $chmodcmd u+w "$dsttmp"; $doit $stripcmd "$dsttmp") } &&
{ test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
# If -C, don't bother to copy if it wouldn't change the file.
Wdyt? --thanks, karl.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: install-sh -s on readonly file
2019-08-26 0:52 install-sh -s on readonly file Karl Berry
@ 2019-08-26 2:13 ` Paul Eggert
2019-08-26 21:34 ` Karl Berry
0 siblings, 1 reply; 4+ messages in thread
From: Paul Eggert @ 2019-08-26 2:13 UTC (permalink / raw)
To: Karl Berry; +Cc: bug-gnulib
[-- Attachment #1: Type: text/plain, Size: 287 bytes --]
Karl Berry wrote:
> - { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } &&
> + { test -z "$stripcmd" || ($doit $chmodcmd u+w "$dsttmp"; $doit $stripcmd "$dsttmp") } &&
How about the attached Automake patch instead? It avoids the extra forks and
exec. Admittedly it's longer.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-install-sh-support-s-with-read-only-source.patch --]
[-- Type: text/x-patch; name="0001-install-sh-support-s-with-read-only-source.patch", Size: 1281 bytes --]
From c50db415f06d3a29780fe9650654165f6fa28bf0 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Sun, 25 Aug 2019 18:51:26 -0700
Subject: [PATCH] install-sh: support -s with read-only source
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Problem reported by Karl Berry in:
https://lists.gnu.org/r/bug-gnulib/2019-08/msg00067.html
* lib/install-sh: If -s is given, create the temporary file
with $cp_umask so that ‘strip’ can write to it.
---
lib/install-sh | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/lib/install-sh b/lib/install-sh
index 8175c640f..1f5cdccc7 100755
--- a/lib/install-sh
+++ b/lib/install-sh
@@ -451,7 +451,16 @@ do
trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
# Copy the file name to the temp name.
- (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
+ (umask $cp_umask &&
+ { test -z "$stripcmd" || {
+ if test -z "$doit"; then
+ : >"$dsttmp" # No need to fork-exec 'touch'.
+ else
+ $doit touch "$dsttmp"
+ fi
+ }
+ } &&
+ $doit_exec $cpprog "$src" "$dsttmp") &&
# and set any options; do chmod last to preserve setuid bits.
#
--
2.21.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: install-sh -s on readonly file
2019-08-26 2:13 ` Paul Eggert
@ 2019-08-26 21:34 ` Karl Berry
2019-08-26 21:46 ` Paul Eggert
0 siblings, 1 reply; 4+ messages in thread
From: Karl Berry @ 2019-08-26 21:34 UTC (permalink / raw)
To: eggert; +Cc: bug-gnulib
Hi Paul,
How about the attached Automake patch instead?
Thanks much. Clever. Seems good to me. Can you install it in am, please?
Perhaps it is worth a comment that it's desired to create the file with
$cp_umask (not just cp-ing it), in order in ensure $dsttmp is writable,
else strip can fail. Otherwise there is no obvious reason for the
complicated sequence. At least if I'm understanding correctly what you
are doing ... --thanks, karl.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: install-sh -s on readonly file
2019-08-26 21:34 ` Karl Berry
@ 2019-08-26 21:46 ` Paul Eggert
0 siblings, 0 replies; 4+ messages in thread
From: Paul Eggert @ 2019-08-26 21:46 UTC (permalink / raw)
To: Karl Berry; +Cc: bug-gnulib
Karl Berry wrote:
> Can you install it in am, please?
>
> Perhaps it is worth a comment
Thanks for checking. I installed it into Automake master, with a comment.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-08-26 21:46 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-26 0:52 install-sh -s on readonly file Karl Berry
2019-08-26 2:13 ` Paul Eggert
2019-08-26 21:34 ` Karl Berry
2019-08-26 21:46 ` Paul Eggert
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).