From 68c91344b2e90bdedc978d52611bde920d2355f4 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Fri, 3 Jun 2005 16:00:23 +0000 Subject: [PATCH] Make -I only apply to rm's run in the foreground. Silently discard it if the rm is run in the background. Reported-by: "George Georgalis" --- bin/rm/rm.1 | 6 ++++-- bin/rm/rm.c | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/bin/rm/rm.1 b/bin/rm/rm.1 index 76dc66d1fc..55c1d06568 100644 --- a/bin/rm/rm.1 +++ b/bin/rm/rm.1 @@ -34,7 +34,7 @@ .\" .\" @(#)rm.1 8.5 (Berkeley) 12/5/94 .\" $FreeBSD: src/bin/rm/rm.1,v 1.19.2.6 2003/02/04 22:10:42 trhodes Exp $ -.\" $DragonFly: src/bin/rm/rm.1,v 1.5 2004/11/05 19:09:53 dillon Exp $ +.\" $DragonFly: src/bin/rm/rm.1,v 1.6 2005/06/03 16:00:23 dillon Exp $ .\" .Dd January 28, 1999 .Dt RM 1 @@ -83,7 +83,9 @@ option overrides any previous options. .It Fl I Request confirmation once if more than three files are being removed or if a -directory is being recursively removed. +directory is being recursively removed. This option only applies when the +.Nm +utility is run in the foreground. This is a far less intrusive option than .Fl i yet provides almost the same level of protection against mistakes. diff --git a/bin/rm/rm.c b/bin/rm/rm.c index 54d723f60e..a78b4ff06c 100644 --- a/bin/rm/rm.c +++ b/bin/rm/rm.c @@ -33,12 +33,13 @@ * @(#) Copyright (c) 1990, 1993, 1994 The Regents of the University of California. All rights reserved. * @(#)rm.c 8.5 (Berkeley) 4/18/94 * $FreeBSD: src/bin/rm/rm.c,v 1.29.2.5 2002/07/12 07:25:48 tjr Exp $ - * $DragonFly: src/bin/rm/rm.c,v 1.11 2005/01/05 16:24:19 liamfoy Exp $ + * $DragonFly: src/bin/rm/rm.c,v 1.12 2005/06/03 16:00:23 dillon Exp $ */ #include #include #include +#include #include #include @@ -74,6 +75,7 @@ main(int argc, char *argv[]) { int ch; const char *p; + pid_t tty_pgrp; /* * Test for the special case where the utility is called as @@ -110,7 +112,15 @@ main(int argc, char *argv[]) iflag = 1; break; case 'I': - Iflag = 1; + /* + * The -I flag is intended to be generally aliasable + * in /etc/csh.cshrc. We apply it only to foreground + * processes. + */ + if (ioctl(0, TIOCGPGRP, &tty_pgrp) == 0) { + if (tty_pgrp == getpgrp()) + Iflag = 1; + } break; case 'P': Pflag = 1; -- 2.28.0