From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ian Lance Taylor To: Franz.Sirl-kernel@lauterbach.com Cc: gas2@sourceware.cygnus.com Subject: Re: strip looses original file ownership and file permissions Date: Thu, 06 May 1999 11:03:00 -0000 Message-id: <19990506180307.24286.qmail@daffy.airs.com> References: <4.2.0.37.19990506133808.0363a9f0@mail.lauterbach.com> <4.2.0.37.19990506133808.0363a9f0@mail.lauterbach.com> <4.2.0.37.19990506183739.0372b0e0@mail.lauterbach.com> <4.2.0.37.19990506183739.0372b0e0@mail.lauterbach.com> X-SW-Source: 1999/msg00091.html Date: Thu, 06 May 1999 18:54:16 +0200 From: Franz Sirl At 18:27 06.05.99 , Ian Lance Taylor wrote: > Date: Thu, 06 May 1999 13:44:47 +0200 > From: Franz Sirl > > >I just verified that strip out of gas-990418 looses original > ownership and > >permissions of a file. > >This is on glibc-2.1.1pre2, Linux-2.2.6 (PPC). > > > >Is this platform specific or does anybody else notice this? > > After a quick browse through the source I came up with the following > untested patch. Does it look right? > >It doesn't look right to me. > >We need to rename the file FROM to TO. In the normal case of strip, >FROM is a temporary file, and TO is the original file which we are >stripping. However, this function is also used in other cases. > >If TO does not exist, we should just use rename. This is not the >normal case of strip, but it happens in other cases. Your patch >breaks that. That seems to be only significant change in your patch. >Perhaps I am missing something. > >I think the only way to reliably preserve ownership is to avoid using >rename. Perhaps the code should be changed to call simple_copy when >the owner of the file differs from the effective uid. I think my patch produces the behavior that the comments are suggesting. The old code was bogus anyway, cause it tried to chmod/chown "to" after rename with values from a non-existing (exists != 0, this is really a bad-named variable, it's named the opposite of it's meaning) file. You're right. I applied the appended patch, which I think should fix the problem. Ian Index: rename.c =================================================================== RCS file: /cvs/binutils/binutils/binutils/rename.c,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 rename.c --- rename.c 1999/05/03 07:29:10 1.1.1.1 +++ rename.c 1999/05/06 18:02:05 @@ -139,17 +139,17 @@ const char *to; int preserve_dates; { - int exists; + boolean exists; struct stat s; int ret = 0; - exists = lstat (to, &s); + exists = lstat (to, &s) == 0; #if defined (_WIN32) && !defined (__CYGWIN32__) /* Win32, unlike unix, will not erase `to' in `rename(from, to)' but fail instead. Also, chown is not present. */ - if (exists == 0) + if (exists) remove (to); ret = rename (from, to); @@ -163,7 +163,7 @@ #else /* Use rename only if TO is not a symbolic link and has only one hard link. */ - if (exists < 0 || (!S_ISLNK (s.st_mode) && s.st_nlink == 1)) + if (! exists || (!S_ISLNK (s.st_mode) && s.st_nlink == 1)) { ret = rename (from, to); if (ret == 0)