Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 23 Sep 2005 01:40:04 -0700
From:      Doug Barton <dougb@FreeBSD.org>
To:        freebsd-hackers@FreeBSD.org
Subject:   Fixing an error condition for 'rm -P'
Message-ID:  <4333BF64.8060800@FreeBSD.org>

next in thread | raw e-mail | index | archive | help
This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
--------------enig30CFA0F9AC8D39308ACE893B
Content-Type: multipart/mixed; boundary="------------090205000709030308020100"

This is a multi-part message in MIME format.
--------------090205000709030308020100
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

I have rm aliased to '/bin/rm -P', mostly for fun, but I like the idea. 
There is an oddity however when you use the -P flag, and the file is not 
writable. The check() function in rm.c specifically ignores this condition, 
and lets the thing fail later in the program. I think this is bad on an 
objective level, but it definitely leads to annoying problems for the user 
when you hit this condition. I therefore propose the attached patch.

Doug

-- 

     This .signature sanitized for your protection


--------------090205000709030308020100
Content-Type: text/plain;
 name="rm-P-errx.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="rm-P-errx.diff"

Index: rm.c
===================================================================
RCS file: /usr/local/ncvs/src/bin/rm/rm.c,v
retrieving revision 1.52
diff -u -r1.52 rm.c
--- rm.c	13 Nov 2004 04:07:01 -0000	1.52
+++ rm.c	23 Sep 2005 08:29:38 -0000
@@ -452,11 +452,8 @@
 		 * talking to a terminal, ask.	Symbolic links are excluded
 		 * because their permissions are meaningless.  Check stdin_ok
 		 * first because we may not have stat'ed the file.
-		 * Also skip this check if the -P option was specified because
-		 * we will not be able to overwrite file contents and will
-		 * barf later.
 		 */
-		if (!stdin_ok || S_ISLNK(sp->st_mode) || Pflag ||
+		if (!stdin_ok || S_ISLNK(sp->st_mode) ||
 		    (!access(name, W_OK) &&
 		    !(sp->st_flags & (SF_APPEND|SF_IMMUTABLE)) &&
 		    (!(sp->st_flags & (UF_APPEND|UF_IMMUTABLE)) || !uid)))
@@ -464,6 +461,9 @@
 		strmode(sp->st_mode, modep);
 		if ((flagsp = fflagstostr(sp->st_flags)) == NULL)
 			err(1, "fflagstostr");
+		if (Pflag)
+			errx(1,
+			    "-P was specified, but %s is not writable", path);
 		(void)fprintf(stderr, "override %s%s%s/%s %s%sfor %s? ",
 		    modep + 1, modep[9] == ' ' ? "" : " ",
 		    user_from_uid(sp->st_uid, 0),

--------------090205000709030308020100--

--------------enig30CFA0F9AC8D39308ACE893B
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (FreeBSD)

iD8DBQFDM79oyIakK9Wy8PsRAoMpAJ9xXeZVocG3G4dvR020VsX5xQQw5QCgnFfU
yebHKrFRZTzt2RIgEEgDNrc=
=KVoZ
-----END PGP SIGNATURE-----

--------------enig30CFA0F9AC8D39308ACE893B--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4333BF64.8060800>