From root@marcus.grupos.com.br  Thu Sep 29 14:50:37 2005
Return-Path: <root@marcus.grupos.com.br>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 4310A16A41F
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 29 Sep 2005 14:50:37 +0000 (GMT)
	(envelope-from root@marcus.grupos.com.br)
Received: from mail.grupos.com.br (mail.grupos.com.br [200.203.183.72])
	by mx1.FreeBSD.org (Postfix) with ESMTP id ABAC043D48
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 29 Sep 2005 14:50:36 +0000 (GMT)
	(envelope-from root@marcus.grupos.com.br)
Received: from corp.grupos.com.br (unknown [150.162.166.55])
	by mail.grupos.com.br (Postfix) with ESMTP id B761B11E44A
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 29 Sep 2005 11:50:32 -0300 (BRT)
Received: from marcus.grupos.com.br (unknown [150.162.166.51])
	by corp.grupos.com.br (Postfix) with ESMTP id 7F0D85505
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 29 Sep 2005 11:50:32 -0300 (BRT)
Received: by marcus.grupos.com.br (Postfix, from userid 0)
	id 4D9E319; Thu, 29 Sep 2005 11:50:32 -0300 (BRT)
Message-Id: <20050929145032.4D9E319@marcus.grupos.com.br>
Date: Thu, 29 Sep 2005 11:50:32 -0300 (BRT)
From: Marcus Alves Grando <mnag@FreeBSD.org>
Reply-To: Marcus Alves Grando <mnag@FreeBSD.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: Update bin/ls to have option to cancel -A with super user
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         86710
>Category:       bin
>Synopsis:       [patch] update bin/ls to have option to cancel -A with super user
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          update
>Submitter-Id:   current-users
>Arrival-Date:   Thu Sep 29 15:00:21 GMT 2005
>Closed-Date:    Thu Nov 10 00:07:28 GMT 2005
>Last-Modified:  Thu Nov 10 00:07:28 GMT 2005
>Originator:     Marcus Alves Grando
>Release:        FreeBSD 6.0-BETA5 i386
>Organization:
>Environment:
System: FreeBSD marcus.grupos.com.br 6.0-BETA5 FreeBSD 6.0-BETA5 #14: Wed Sep 28 12:52:25 BRT 2005 root@marcus.grupos.com.br:/space/obj/usr/src/sys/MARCUS i386


	
>Description:

Update bin/ls to have option to cancel -A with super user

	
>How-To-Repeat:
	
>Fix:

	

--- ls.patch begins here ---
Index: ls.1
===================================================================
RCS file: /home/ncvs/src/bin/ls/ls.1,v
retrieving revision 1.91
diff -u -r1.91 ls.1
--- ls.1	6 Sep 2005 20:14:39 -0000	1.91
+++ ls.1	29 Sep 2005 04:21:49 -0000
@@ -40,7 +40,7 @@
 .Nd list directory contents
 .Sh SYNOPSIS
 .Nm
-.Op Fl ABCFGHLPRSTWZabcdfghiklmnopqrstuwx1
+.Op Fl ABCFGHILPRSTWZabcdfghiklmnopqrstuwx1
 .Op Ar
 .Sh DESCRIPTION
 For each operand that names a
@@ -73,6 +73,8 @@
 and
 .Pa .. .
 Always set for the super-user.
+.Fl I
+cancel this option.
 .It Fl B
 Force printing of non-printable characters (as defined by
 .Xr ctype 3
@@ -117,6 +119,12 @@
 or
 .Fl l
 options are specified.
+.It Fl I
+This option cancels the
+.Fl A
+option. Usually used by super user when
+.Fl A
+is not necessary.
 .It Fl L
 If argument is a symbolic link, list the file or directory the link references
 rather than the link itself.
Index: ls.c
===================================================================
RCS file: /home/ncvs/src/bin/ls/ls.c,v
retrieving revision 1.80
diff -u -r1.80 ls.c
--- ls.c	3 Jun 2005 11:05:58 -0000	1.80
+++ ls.c	29 Sep 2005 04:21:49 -0000
@@ -110,6 +110,8 @@
 static int f_kblocks;		/* print size in kilobytes */
 static int f_listdir;		/* list actual directory, not contents */
 static int f_listdot;		/* list files beginning with . */
+static int f_nolistdot;		/* don't list files beginning with . */
+static int f_forcelistdot;	/* force list files beginning with . */
        int f_longform;		/* long listing format */
        int f_nonprint;		/* show unprintables as ? */
 static int f_nosort;		/* don't sort output */
@@ -175,13 +177,9 @@
 			termwidth = atoi(p);
 	}
 
-	/* Root is -A automatically. */
-	if (!getuid())
-		f_listdot = 1;
-
 	fts_options = FTS_PHYSICAL;
  	while ((ch = getopt(argc, argv,
-	    "1ABCFGHLPRSTWZabcdfghiklmnopqrstuwx")) != -1) {
+	    "1ABCFGHILPRSTWZabcdfghiklmnopqrstuwx")) != -1) {
 		switch (ch) {
 		/*
 		 * The -1, -C, -x and -l options all override each other so
@@ -243,10 +241,14 @@
 			break;
 		case 'a':
 			fts_options |= FTS_SEEDOT;
-			/* FALLTHROUGH */
+			f_forcelistdot = 1;
+			break;
 		case 'A':
 			f_listdot = 1;
 			break;
+		case 'I':
+			f_nolistdot = 1;
+			break;
 		/* The -d option turns off the -R option. */
 		case 'd':
 			f_listdir = 1;
@@ -326,6 +328,10 @@
 	argc -= optind;
 	argv += optind;
 
+	/* Root is -A automatically. */
+	if (!getuid() && !f_nolistdot)
+		f_listdot = 1;
+
 	/* Enabling of colours is conditional on the environment. */
 	if (getenv("CLICOLOR") &&
 	    (isatty(STDOUT_FILENO) || getenv("CLICOLOR_FORCE")))
@@ -490,7 +496,8 @@
 			break;
 		case FTS_D:
 			if (p->fts_level != FTS_ROOTLEVEL &&
-			    p->fts_name[0] == '.' && !f_listdot)
+			    p->fts_name[0] == '.' && ((!f_listdot ||
+			    f_nolistdot) && !f_forcelistdot))
 				break;
 
 			/*
@@ -650,7 +657,8 @@
 			}
 		} else {
 			/* Only display dot file if -a/-A set. */
-			if (cur->fts_name[0] == '.' && !f_listdot) {
+			if (cur->fts_name[0] == '.' && ((!f_listdot ||
+			    f_nolistdot) && !f_forcelistdot)) {
 				cur->fts_number = NO_PRINT;
 				continue;
 			}
--- ls.patch ends here ---


>Release-Note:
>Audit-Trail:

From: Giorgos Keramidas <keramida@ceid.upatras.gr>
To: Marcus Alves Grando <mnag@freebsd.org>
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: bin/86710: Update bin/ls to have option to cancel -A with super user
Date: Thu, 29 Sep 2005 19:48:33 +0300

 On 2005-09-29 11:50, Marcus Alves Grando <mnag@freebsd.org> wrote:
 > +	/* Root is -A automatically. */
 > +	if (!getuid() && !f_nolistdot)
 > +		f_listdot = 1;
 > +
 
 If you are going to touch this check, then please change it to avoid the
 use of the !condition idiom :)
 
 	if (getuid() == 0 && f_nolistdot == 0)
 		f_listdot = 1;
 

From: Marcus Alves Grando <mnag@FreeBSD.org>
To: bug-followup@FreeBSD.org,  keramida@ceid.upatras.gr
Cc:  
Subject: Re: bin/86710: Update bin/ls to have option to cancel -A with super
 user
Date: Thu, 29 Sep 2005 15:13:23 -0300

 This is a multi-part message in MIME format.
 --------------000304070007040709010902
 Content-Type: text/plain; charset=ISO-8859-1
 Content-Transfer-Encoding: 7bit
 
 New patch attached.
 
 -- 
 Marcus Alves Grando
 Grupos Internet S/A
 marcus(at)corp.grupos.com.br
   mnag(at)FreeBSD.org
 
 --------------000304070007040709010902
 Content-Type: text/x-patch;
  name="ls.patch"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline;
  filename="ls.patch"
 
 Index: ls.1
 ===================================================================
 RCS file: /home/ncvs/src/bin/ls/ls.1,v
 retrieving revision 1.91
 diff -u -r1.91 ls.1
 --- ls.1	6 Sep 2005 20:14:39 -0000	1.91
 +++ ls.1	29 Sep 2005 18:07:47 -0000
 @@ -40,7 +40,7 @@
  .Nd list directory contents
  .Sh SYNOPSIS
  .Nm
 -.Op Fl ABCFGHLPRSTWZabcdfghiklmnopqrstuwx1
 +.Op Fl ABCFGHILPRSTWZabcdfghiklmnopqrstuwx1
  .Op Ar
  .Sh DESCRIPTION
  For each operand that names a
 @@ -73,6 +73,8 @@
  and
  .Pa .. .
  Always set for the super-user.
 +.Fl I
 +cancel this option.
  .It Fl B
  Force printing of non-printable characters (as defined by
  .Xr ctype 3
 @@ -117,6 +119,12 @@
  or
  .Fl l
  options are specified.
 +.It Fl I
 +This option cancels the
 +.Fl A
 +option. Usually used by super user when
 +.Fl A
 +is not necessary.
  .It Fl L
  If argument is a symbolic link, list the file or directory the link references
  rather than the link itself.
 Index: ls.c
 ===================================================================
 RCS file: /home/ncvs/src/bin/ls/ls.c,v
 retrieving revision 1.80
 diff -u -r1.80 ls.c
 --- ls.c	3 Jun 2005 11:05:58 -0000	1.80
 +++ ls.c	29 Sep 2005 18:07:47 -0000
 @@ -110,6 +110,8 @@
  static int f_kblocks;		/* print size in kilobytes */
  static int f_listdir;		/* list actual directory, not contents */
  static int f_listdot;		/* list files beginning with . */
 +static int f_nolistdot;		/* don't list files beginning with . */
 +static int f_forcelistdot;	/* force list files beginning with . */
         int f_longform;		/* long listing format */
         int f_nonprint;		/* show unprintables as ? */
  static int f_nosort;		/* don't sort output */
 @@ -175,13 +177,9 @@
  			termwidth = atoi(p);
  	}
  
 -	/* Root is -A automatically. */
 -	if (!getuid())
 -		f_listdot = 1;
 -
  	fts_options = FTS_PHYSICAL;
   	while ((ch = getopt(argc, argv,
 -	    "1ABCFGHLPRSTWZabcdfghiklmnopqrstuwx")) != -1) {
 +	    "1ABCFGHILPRSTWZabcdfghiklmnopqrstuwx")) != -1) {
  		switch (ch) {
  		/*
  		 * The -1, -C, -x and -l options all override each other so
 @@ -243,10 +241,14 @@
  			break;
  		case 'a':
  			fts_options |= FTS_SEEDOT;
 -			/* FALLTHROUGH */
 +			f_forcelistdot = 1;
 +			break;
  		case 'A':
  			f_listdot = 1;
  			break;
 +		case 'I':
 +			f_nolistdot = 1;
 +			break;
  		/* The -d option turns off the -R option. */
  		case 'd':
  			f_listdir = 1;
 @@ -326,6 +328,10 @@
  	argc -= optind;
  	argv += optind;
  
 +	/* Root is -A automatically. */
 +	if (getuid() == 0 && f_nolistdot != 1)
 +		f_listdot = 1;
 +
  	/* Enabling of colours is conditional on the environment. */
  	if (getenv("CLICOLOR") &&
  	    (isatty(STDOUT_FILENO) || getenv("CLICOLOR_FORCE")))
 @@ -350,7 +356,7 @@
  #endif /*COLORLS*/
  
  #ifdef COLORLS
 -	if (f_color) {
 +	if (f_color == 1) {
  		/*
  		 * We can't put tabs and color sequences together:
  		 * column number will be incremented incorrectly
 @@ -368,10 +374,10 @@
  	 * information, unless in color mode in which case we do
  	 * need this to determine which colors to display.
  	 */
 -	if (!f_inode && !f_longform && !f_size && !f_timesort &&
 -	    !f_sizesort && !f_type
 +	if (f_inode != 1 && f_longform != 1 && f_size != 1
 +	    && f_timesort != 1 && f_sizesort != 1 && f_type != 1
  #ifdef COLORLS
 -	    && !f_color
 +	    && f_color != 1
  #endif
  	    )
  		fts_options |= FTS_NOSTAT;
 @@ -380,20 +386,20 @@
  	 * If not -F, -d or -l options, follow any symbolic links listed on
  	 * the command line.
  	 */
 -	if (!f_longform && !f_listdir && !f_type)
 +	if (f_longform != 1 && f_listdir != 1 && f_type != 1)
  		fts_options |= FTS_COMFOLLOW;
  
  	/*
  	 * If -W, show whiteout entries
  	 */
  #ifdef FTS_WHITEOUT
 -	if (f_whiteout)
 +	if (f_whiteout == 1)
  		fts_options |= FTS_WHITEOUT;
  #endif
  
  	/* If -l or -s, figure out block size. */
 -	if (f_longform || f_size) {
 -		if (f_kblocks)
 +	if (f_longform == 1 || f_size == 1) {
 +		if (f_kblocks == 1)
  			blocksize = 2;
  		else {
  			(void)getbsize(&notused, &blocksize);
 @@ -401,36 +407,36 @@
  		}
  	}
  	/* Select a sort function. */
 -	if (f_reversesort) {
 -		if (!f_timesort && !f_sizesort)
 +	if (f_reversesort == 1) {
 +		if (f_timesort != 1 && f_sizesort != 1)
  			sortfcn = revnamecmp;
 -		else if (f_accesstime)
 +		else if (f_accesstime == 1)
  			sortfcn = revacccmp;
 -		else if (f_statustime)
 +		else if (f_statustime == 1)
  			sortfcn = revstatcmp;
 -		else if (f_sizesort)
 +		else if (f_sizesort == 1)
  			sortfcn = revsizecmp;
  		else		/* Use modification time. */
  			sortfcn = revmodcmp;
  	} else {
 -		if (!f_timesort && !f_sizesort)
 +		if (f_timesort != 1 && f_sizesort != 1)
  			sortfcn = namecmp;
 -		else if (f_accesstime)
 +		else if (f_accesstime == 1)
  			sortfcn = acccmp;
 -		else if (f_statustime)
 +		else if (f_statustime == 1)
  			sortfcn = statcmp;
 -		else if (f_sizesort)
 +		else if (f_sizesort == 1)
  			sortfcn = sizecmp;
  		else		/* Use modification time. */
  			sortfcn = modcmp;
  	}
  
  	/* Select a print function. */
 -	if (f_singlecol)
 +	if (f_singlecol == 1)
  		printfcn = printscol;
 -	else if (f_longform)
 +	else if (f_longform == 1)
  		printfcn = printlong;
 -	else if (f_stream)
 +	else if (f_stream == 1)
  		printfcn = printstream;
  	else
  		printfcn = printcol;
 @@ -468,7 +474,7 @@
  	chp = fts_children(ftsp, 0);
  	if (chp != NULL)
  		display(NULL, chp, options);
 -	if (f_listdir)
 +	if (f_listdir == 1)
  		return;
  
  	/*
 @@ -490,7 +496,8 @@
  			break;
  		case FTS_D:
  			if (p->fts_level != FTS_ROOTLEVEL &&
 -			    p->fts_name[0] == '.' && !f_listdot)
 +			    p->fts_name[0] == '.' && ((f_listdot != 1 ||
 +			    f_nolistdot == 1) && f_forcelistdot != 1))
  				break;
  
  			/*
 @@ -510,7 +517,7 @@
  			chp = fts_children(ftsp, ch_options);
  			display(p, chp, options);
  
 -			if (!f_recursive && chp != NULL)
 +			if (f_recursive != 1 && chp != NULL)
  				(void)fts_set(ftsp, p, FTS_SKIP);
  			break;
  		default:
 @@ -615,7 +622,7 @@
  			maxlabelstr = 0;
  			/* FALLTHROUGH */
  #ifdef COLORLS
 -			if (!f_color)
 +			if (f_color != 1)
  #endif
  				f_notabs = 0;
  			/* FALLTHROUGH */
 @@ -644,20 +651,21 @@
  		 */
  		if (p == NULL) {
  			/* Directories will be displayed later. */
 -			if (cur->fts_info == FTS_D && !f_listdir) {
 +			if (cur->fts_info == FTS_D && f_listdir != 1) {
  				cur->fts_number = NO_PRINT;
  				continue;
  			}
  		} else {
  			/* Only display dot file if -a/-A set. */
 -			if (cur->fts_name[0] == '.' && !f_listdot) {
 +			if (cur->fts_name[0] == '.' && ((f_listdot != 1 ||
 +			    f_nolistdot == 1) && f_forcelistdot != 1)) {
  				cur->fts_number = NO_PRINT;
  				continue;
  			}
  		}
  		if (cur->fts_namelen > maxlen)
  			maxlen = cur->fts_namelen;
 -		if (f_octal || f_octal_escape) {
 +		if (f_octal == 1 || f_octal_escape == 1) {
  			u_long t = len_octal(cur->fts_name, cur->fts_namelen);
  
  			if (t > maxlen)
 @@ -675,8 +683,8 @@
  				maxsize = sp->st_size;
  
  			btotal += sp->st_blocks;
 -			if (f_longform) {
 -				if (f_numericonly) {
 +			if (f_longform == 1) {
 +				if (f_numericonly == 1) {
  					(void)snprintf(nuser, sizeof(nuser),
  					    "%u", sp->st_uid);
  					(void)snprintf(ngroup, sizeof(ngroup),
 @@ -691,7 +699,7 @@
  					maxuser = ulen;
  				if ((glen = strlen(group)) > maxgroup)
  					maxgroup = glen;
 -				if (f_flags) {
 +				if (f_flags == 1) {
  					flags = fflagstostr(sp->st_flags);
  					if (flags != NULL && *flags == '\0') {
  						free(flags);
 @@ -705,7 +713,7 @@
  				} else
  					flen = 0;
  				labelstr = NULL;
 -				if (f_label) {
 +				if (f_label == 1) {
  					char name[PATH_MAX + 1];
  					mac_t label;
  					int error;
 @@ -772,12 +780,12 @@
  				    S_ISBLK(sp->st_mode))
  					bcfile = 1;
  
 -				if (f_flags) {
 +				if (f_flags == 1) {
  					np->flags = &np->data[ulen + glen + 2];
  					(void)strcpy(np->flags, flags);
  					free(flags);
  				}
 -				if (f_label) {
 +				if (f_label == 1) {
  					np->label = &np->data[ulen + glen + 2
  					    + (f_flags ? flen + 1 : 0)];
  					(void)strcpy(np->label, labelstr);
 @@ -820,7 +828,7 @@
  	printfcn(&d);
  	output = 1;
  
 -	if (f_longform)
 +	if (f_longform == 1)
  		for (cur = list; cur; cur = cur->fts_link)
  			free(cur->fts_pointer);
  }
 
 --------------000304070007040709010902--
State-Changed-From-To: open->closed 
State-Changed-By: mux 
State-Changed-When: Thu Nov 10 00:03:08 GMT 2005 
State-Changed-Why:  
I've just committed the first version of your patch, thank you.  I 
don't think changing the checks is really a good idea; I find it 
more readable the way it is now.  In any case, it should be committed 
separately if it's committed at all. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=86710 
>Unformatted:
