NetBSD Problem Report #38754

From martin@duskware.de  Mon May 26 07:58:24 2008
Return-Path: <martin@duskware.de>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by narn.NetBSD.org (Postfix) with ESMTP id 9FDDE63B880
	for <gnats-bugs@gnats.netbsd.org>; Mon, 26 May 2008 07:58:24 +0000 (UTC)
Message-Id: <20080526063028.E903E63B880@narn.NetBSD.org>
Date: Mon, 26 May 2008 06:30:28 +0000 (UTC)
From: murray@river-styx.org
Reply-To: murray@river-styx.org
To: netbsd-bugs-owner@NetBSD.org
Subject: /bin/rm rm.c consistancy with other bsds
X-Send-Pr-Version: www-1.0

>Number:         38754
>Category:       standards
>Synopsis:       /bin/rm rm.c consistancy with other bsds
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    standards-manager
>State:          closed
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Mon May 26 08:00:06 +0000 2008
>Closed-Date:    Mon May 26 14:12:48 +0000 2008
>Last-Modified:  Mon Jun 02 17:05:01 +0000 2008
>Originator:     murray armfield
>Release:        NetBSD-current
>Organization:
N/A
>Environment:
NetBSD zeus.river-styx.org 4.99.63 NetBSD 4.99.63 (ZEUS) #1: Sun May 25 11:08:57 EST 2008  admin@zeus.river-styx.org:/vol01/build/obj/sys/arch/amd64/compile/ZEUS amd64
>Description:
rm will display the usage message if there are no file arguments and the -f flag is used. This does not follow POSIX. POSIX says...
"Do not write diagnostic messages or modify the exit status in the case of nonexistent operands."
Also, while here, exit immediately if there are no arguments and -f given, and remove a NULL cast and improve an error message.
>How-To-Repeat:
Inspect code from NetBSD versus *BSD
>Fix:
Index: rm.c
===================================================================
RCS file: /cvsroot/src/bin/rm/rm.c,v
retrieving revision 1.46
diff -u -u -p -r1.46 rm.c
--- rm.c        24 Jun 2007 17:59:31 -0000      1.46
+++ rm.c        26 May 2008 06:24:03 -0000
@@ -126,8 +126,11 @@ main(int argc, char *argv[])
        argc -= optind;
        argv += optind;

-       if (argc < 1)
+       if (argc < 1) {
+               if (fflag)
+                       exit(0);
                usage();
+       }

        checkdot(argv);

@@ -168,9 +171,8 @@ rm_tree(char **argv)
                flags |= FTS_NOSTAT;
        if (Wflag)
                flags |= FTS_WHITEOUT;
-       if (!(fts = fts_open(argv, flags,
-           (int (*)(const FTSENT **, const FTSENT **))NULL)))
-               err(1, NULL);
+       if (!(fts = fts_open(argv, flags, NULL)))
+               err(1, "fts_open");
        while ((p = fts_read(fts)) != NULL) {

                switch (p->fts_info) {

>Release-Note:

>Audit-Trail:

State-Changed-From-To: open->closed
State-Changed-By: christos@NetBSD.org
State-Changed-When: Mon, 26 May 2008 10:12:48 -0400
State-Changed-Why:
fixed,thanks


From: Christos Zoulas <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/38754 CVS commit: src/bin/rm
Date: Mon, 26 May 2008 14:12:06 +0000 (UTC)

 Module Name:	src
 Committed By:	christos
 Date:		Mon May 26 14:12:06 UTC 2008

 Modified Files:
 	src/bin/rm: rm.c

 Log Message:
 PR/38754: murray armfield: Rm prints diagnostic messages when invoked with -f
 and no other arguments, contrary to POSIX. Also cosmetic fixes.


 To generate a diff of this commit:
 cvs rdiff -r1.46 -r1.47 src/bin/rm/rm.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: Alan Barrett <apb@cequrux.com>
To: gnats-bugs@NetBSD.org
Cc: netbsd-bugs@NetBSD.org
Subject: Re: standards/38754: /bin/rm rm.c consistancy with other bsds
Date: Mon, 2 Jun 2008 00:00:13 +0100

 On Mon, 26 May 2008, murray@river-styx.org wrote:
 > rm will display the usage message if there are no file arguments and
 > the -f flag is used. This does not follow POSIX. POSIX says...
 > "Do not write diagnostic messages or modify the exit status in the
 > case of nonexistent operands."

 You seem to interpret "nonexistent operands" to mean the number of
 operands (not counting options such as the "-f" itself) is zero.

 I believe that "nonexistent operands" should be interpreted to mean
 operands that contain strings that do not refer to entities that exist
 in the file system.

 Thus, "rm -f" does not contain any "nonexistent operands"; it contains
 no operands at all, and "rm" should print a diagnostic message
 complaining about incorrect usage, and exit with an error status.

 However, "rm -f /this/file/or/directory/does/not/exist" does contain
 a "nonexistent operand", and "rm" should exit without any error or
 diagnostic message.

 --apb (Alan Barrett)

From: Murray Armfield <murray@river-styx.org>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: standards/38754: /bin/rm rm.c consistancy with other bsds
Date: Mon, 2 Jun 2008 16:51:22 +1000

 On Mon, 2 Jun 2008 09:05:03 am you wrote:
 > The following reply was made to PR standards/38754; it has been noted by
 > GNATS.
 >
 > From: Alan Barrett <apb@cequrux.com>
 > To: gnats-bugs@NetBSD.org
 > Cc: netbsd-bugs@NetBSD.org
 > Subject: Re: standards/38754: /bin/rm rm.c consistancy with other bsds
 > Date: Mon, 2 Jun 2008 00:00:13 +0100
 >
 >  On Mon, 26 May 2008, murray@river-styx.org wrote:
 >  > rm will display the usage message if there are no file arguments and
 >  > the -f flag is used. This does not follow POSIX. POSIX says...
 >  > "Do not write diagnostic messages or modify the exit status in the
 >  > case of nonexistent operands."
 >
 >  You seem to interpret "nonexistent operands" to mean the number of
 >  operands (not counting options such as the "-f" itself) is zero.
 >
 >  I believe that "nonexistent operands" should be interpreted to mean
 >  operands that contain strings that do not refer to entities that exist
 >  in the file system.
 >
 >  Thus, "rm -f" does not contain any "nonexistent operands"; it contains
 >  no operands at all, and "rm" should print a diagnostic message
 >  complaining about incorrect usage, and exit with an error status.
 >
 >  However, "rm -f /this/file/or/directory/does/not/exist" does contain
 >  a "nonexistent operand", and "rm" should exit without any error or
 >  diagnostic message.
 >
 >  --apb (Alan Barrett)

 I see your point. "Nonexistent operands" could refer to no operands, or no 
 operands that exist. The original code used the "if (argc < 1)" just as a 
 fast exit path. The addition of testing for the -f flag in the fast exit path 
 is to just drop the usage message in that case and bring rm in line with how 
 I read the standard around 'file' processing. FreeBSD and OpenBSD both drop 
 the usage message if the -f flag is used. A concern here is obviously the 
 change in behaviour which may affect existing shell script, while at the same 
 time bringing rm -f behaviour in line with other BSD's. Yet to be consistant 
 with other utility programs, if no operand is given, usage is displayed.

 The way I was also thinking about this was from a shell scripting point of 
 view. If I have a list variable building up a list of files to remove, when I 
 pass it to rm -f, I want it to quietly do its thing. If my variable had no 
 items, I would still want it to quietly do its thing and not issue a usage 
 message and exit with non-zero.

 I don't know where to go from here other than to ask other people for their 
 point of view.

 Thanks for questioning this point.

 Take care,
 	Murray Armfield


From: "Greg A. Woods; Planix, Inc." <woods@planix.ca>
To: gnats-bugs@NetBSD.org
Cc: standards-manager@netbsd.org,
 murray@river-styx.org
Subject: Re: standards/38754: /bin/rm rm.c consistancy with other bsds
Date: Mon, 2 Jun 2008 12:58:53 -0400

 On 2-Jun-08, at 2:50 AM, Murray Armfield wrote:
 >> From: Alan Barrett <apb@cequrux.com>
 >> Date: Mon, 2 Jun 2008 00:00:13 +0100
 >>
 >> On Mon, 26 May 2008, murray@river-styx.org wrote:
 >>> rm will display the usage message if there are no file arguments and
 >>> the -f flag is used. This does not follow POSIX. POSIX says...
 >>> "Do not write diagnostic messages or modify the exit status in the
 >>> case of nonexistent operands."
 >>
 >> You seem to interpret "nonexistent operands" to mean the number of
 >> operands (not counting options such as the "-f" itself) is zero.
 >>
 >> I believe that "nonexistent operands" should be interpreted to mean
 >> operands that contain strings that do not refer to entities that  
 >> exist
 >> in the file system.
 >>
 >> Thus, "rm -f" does not contain any "nonexistent operands"; it  
 >> contains
 >> no operands at all, and "rm" should print a diagnostic message
 >> complaining about incorrect usage, and exit with an error status.
 >>
 >> However, "rm -f /this/file/or/directory/does/not/exist" does contain
 >> a "nonexistent operand", and "rm" should exit without any error or
 >> diagnostic message.
 >>
 >> --apb (Alan Barrett)
 >
 > I see your point. "Nonexistent operands" could refer to no operands,  
 > or no
 > operands that exist.

 FWIW, In the way that I normally read documents, especially standards  
 documents, I believe Alan's interpretation is the correct one.

 "non-existant operands" are operands that do not exist.

 Any decent document, and especially a standards document, would  
 normally say "no operands" when it means "no operands".  An operand  
 cannot exist, or "not exist", if it is not given.  ;-)

 -- 
 					Greg A. Woods; Planix, Inc.
 					<woods@planix.ca>

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.