From nobody@FreeBSD.org  Thu May 24 00:14:12 2007
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id BAC3E16A46E
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 24 May 2007 00:14:12 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [69.147.83.33])
	by mx1.freebsd.org (Postfix) with ESMTP id AF9F713C45A
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 24 May 2007 00:14:12 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id l4O0ECsL020954
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 24 May 2007 00:14:12 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id l4O0ECYh020953;
	Thu, 24 May 2007 00:14:12 GMT
	(envelope-from nobody)
Message-Id: <200705240014.l4O0ECYh020953@www.freebsd.org>
Date: Thu, 24 May 2007 00:14:12 GMT
From: Ighighi<ighighi@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [PATCH]: wrong realpath(1) behaviour
X-Send-Pr-Version: www-3.0

>Number:         112920
>Category:       bin
>Synopsis:       [PATCH]: wrong realpath(1) behaviour
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    rwatson
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu May 24 00:20:00 GMT 2007
>Closed-Date:    Sun Aug 03 16:18:07 UTC 2008
>Last-Modified:  Sun Aug 03 16:18:07 UTC 2008
>Originator:     Ighighi
>Release:        6.2-STABLE
>Organization:
>Environment:
FreeBSD orion 6.2-STABLE FreeBSD 6.2-STABLE #1: Fri May 18 01:56:15 VET 2007     root@orion:/usr/obj/usr/src/sys/CUSTOM  i386
>Description:
When printing the message error, the realpath(1) utility uses the buf
passed to realpath(3) instead of the passed argv[1].  When errno is set
to ENAMETOOLONG, it prints the current directory, which is misleading, IMO.
>How-To-Repeat:
$ cd /
$ realpath `perl -e 'print "A"x1026'`
realpath: /: File name too long
$ cd /tmp
$ realpath `perl -e 'print "A"x1026'`
realpath: /tmp: File name too long

>Fix:


>Release-Note:
>Audit-Trail:

From: linimon@lonesome.com (Mark Linimon)
To: Ighighi <ighighi@gmail.com>
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: bin/112920: [PATCH]: wrong realpath(1) behaviour
Date: Wed, 23 May 2007 19:26:26 -0500

 it looks like the patch got trimmed.  Please reply with a followup.
 
 mcl

From: "Ighighi Ighighi" <ighighi@gmail.com>
To: bug-followup@freebsd.org
Cc: "Mark Linimon" <linimon@lonesome.com>
Subject: Re: bin/112920: [PATCH]: wrong realpath(1) behaviour
Date: Thu, 24 May 2007 07:46:58 -0400

 At the last moment I decided against submitting it because it is far too
 trivial and because the CVS log available at
 http://www.FreeBSD.org/cgi/cvsweb.cgi/src/bin/realpath/realpath.c clearly
 shows that in version 1.3 the change was made to make it what it is today
 but without the rationale to justify the use of realpath(3) in such
 non-standard way.  The CVS log (between double quotes): "use the
 problematic part of the path, instead of the argument, when reporting
 an error".
 
 Can anybody explain to me the usefulness of this from within a shell
 script (other than debugging realpath(3)) and provide real world
 examples ?  If the need exists for this, why not use another name or
 create an option in realpath(1) for it ?  It's completely useless in
 shell scripts when printing to stderr anyway, so we're left with
 interactive shells where these errors may be misleading.
 
 The attached patch also adds preliminary getopt() support for invocations
 using "--" as in "realpath -- /path/file".  A nice option to implement
 would be "-q" to turn off those error messages.
 
 The POSIX page on realpath(3):
 http://www.opengroup.org/onlinepubs/000095399/functions/realpath.html
 
 LS0tIHJlYWxwYXRoLmMub3JpZwlUdWUgQXByICA2IDE2OjA2OjUwIDIwMDQKKysrIHJlYWxwYXRo
 LmMJVGh1IE1heSAyNCAwNzowNToyNSAyMDA3CkBAIC00NCwxMyArNDQsMjQgQEAKIHsKIAljaGFy
 IGJ1ZltQQVRIX01BWF07CiAJY2hhciAqcDsKKwlpbnQgY2g7CiAKLQlpZiAoYXJnYyA9PSAyKSB7
 Ci0JCWlmICgocCA9IHJlYWxwYXRoKGFyZ3ZbMV0sIGJ1ZikpID09IE5VTEwpCi0JCQllcnIoMSwg
 IiVzIiwgYnVmKTsKLQl9IGVsc2UKKwl3aGlsZSAoKGNoID0gZ2V0b3B0KGFyZ2MsIGFyZ3YsICIi
 KSkgIT0gLTEpCisJCXN3aXRjaChjaCkgeworCQljYXNlICc/JzoKKwkJZGVmYXVsdDoKKwkJCXVz
 YWdlKCk7CisJCX0KKwlhcmdjIC09IG9wdGluZDsKKwlhcmd2ICs9IG9wdGluZDsKKworCWlmIChh
 cmdjICE9IDEpCiAJCXVzYWdlKCk7Ci0JKHZvaWQpcHJpbnRmKCIlc1xuIiwgcCk7CisKKwlpZiAo
 KHAgPSByZWFscGF0aCgqYXJndiwgYnVmKSkgPT0gTlVMTCkKKwkJZXJyKDEsICIlcyIsICphcmd2
 KTsKKwllbHNlCisJCSh2b2lkKXByaW50ZigiJXNcbiIsIHApOwogCWV4aXQoMCk7CiB9CiAK

From: Ighighi <ighighi@gmail.com>
To: bug-followup@freebsd.org
Cc:  
Subject: Re: bin/112920: [PATCH]: wrong realpath(1) behaviour
Date: Sun, 19 Aug 2007 01:58:38 -0400

 This is a multi-part message in MIME format.
 --------------020007070406020003010508
 Content-Type: text/plain; charset=ISO-8859-1; format=flowed
 Content-Transfer-Encoding: 7bit
 
 The patch that should have been attached in the previous post.
 
 --------------020007070406020003010508
 Content-Type: text/x-patch;
  name="realpath.patch"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline;
  filename="realpath.patch"
 
 #
 # (c) 2007 by Ighighi
 #
 # This patch adds support for multiple arguments to realpath(1) and
 # makes it use getopt(3). It also corrects the following problem:
 # http://www.freebsd.org/cgi/query-pr.cgi?pr=112920
 #
 
 --- src/bin/realpath/realpath.c.orig	Tue Apr  6 16:06:50 2004
 +++ src/bin/realpath/realpath.c	Thu May 24 18:28:49 2007
 @@ -44,13 +44,26 @@
  {
  	char buf[PATH_MAX];
  	char *p;
 +	int ch;
  
 -	if (argc == 2) {
 -		if ((p = realpath(argv[1], buf)) == NULL)
 -			err(1, "%s", buf);
 -	} else
 +	while ((ch = getopt(argc, argv, "")) != -1)
 +		switch(ch) {
 +		case '?':
 +		default:
 +			usage();
 +		}
 +	argc -= optind;
 +	argv += optind;
 +
 +	if (argc < 1)
  		usage();
 -	(void)printf("%s\n", p);
 +
 +	do {
 +		if ((p = realpath(*argv, buf)) == NULL)
 +			err(1, "%s", *argv);
 +		else
 +			(void)printf("%s\n", p);
 +	} while (*++argv != NULL);
  	exit(0);
  }
  
 @@ -58,6 +71,6 @@
  usage(void)
  {
  
 -	(void)fprintf(stderr, "usage: realpath path\n");
 +	(void)fprintf(stderr, "usage: realpath path [...]\n");
    	exit(1);
  }
 --- src/bin/realpath/realpath.1.orig	Sun Jan 16 12:41:58 2005
 +++ src/bin/realpath/realpath.1	Thu May 24 03:20:11 2007
 @@ -42,6 +42,7 @@
  .Sh SYNOPSIS
  .Nm
  .Ar path
 +.Op Ar ...
  .Sh DESCRIPTION
  The
  .Nm
 
 --------------020007070406020003010508--
Responsible-Changed-From-To: freebsd-bugs->rwatson 
Responsible-Changed-By: rwatson 
Responsible-Changed-When: Sun Mar 9 11:20:59 UTC 2008 
Responsible-Changed-Why:  
Take ownership of this PR. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=112920 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/112920: commit references a PR
Date: Sun,  9 Mar 2008 12:46:46 +0000 (UTC)

 rwatson     2008-03-09 12:46:39 UTC
 
   FreeBSD src repository
 
   Modified files:
     bin/realpath         realpath.1 realpath.c 
   Log:
   Enhance realpath(1) in a number of ways:
   
   - Allow realpath to accept multiple paths on the command line.
   - Add -q to suppress warnings if some paths can't be processed, and use
     getopt(3) to process flags.
   - Print the path being requested rather than a possibly partially
     processed path when a failure occurs so that you can tell which of
     several passed paths did fail.
   
   MFC after:      1 week
   PR:             112920
   Submitted by:   Ighighi <ighighi@gmail.com>
   
   Revision  Changes    Path
   1.11      +8 -0      src/bin/realpath/realpath.1
   1.7       +26 -7     src/bin/realpath/realpath.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: rwatson 
State-Changed-When: Sun Mar 9 12:54:51 UTC 2008 
State-Changed-Why:  
Transition to patched until MFC. 

I modified the patch some before committing, including adding the suggested 
-q option, and generating a warning rather than an error when a path fails 
(but still returning the right return value, I believe). 

Thanks. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=112920 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/112920: commit references a PR
Date: Sun, 16 Mar 2008 18:56:01 +0000 (UTC)

 rwatson     2008-03-16 18:55:56 UTC
 
   FreeBSD src repository
 
   Modified files:        (Branch: RELENG_7)
     bin/realpath         realpath.1 realpath.c 
   Log:
   Merge realpath.1:1.11, realpath.c:1.7 from HEAD to RELENG_7:
   
     Enhance realpath(1) in a number of ways:
   
     - Allow realpath to accept multiple paths on the command line.
     - Add -q to suppress warnings if some paths can't be processed, and use
       getopt(3) to process flags.
     - Print the path being requested rather than a possibly partially
       processed path when a failure occurs so that you can tell which of
       several passed paths did fail.
   
     PR:             112920
     Submitted by:   Ighighi <ighighi@gmail.com>
   
   Revision   Changes    Path
   1.10.10.1  +8 -0      src/bin/realpath/realpath.1
   1.6.18.1   +26 -7     src/bin/realpath/realpath.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: rwatson 
State-Changed-When: Sun Aug 3 16:17:48 UTC 2008 
State-Changed-Why:  
Close this PR as the changes have been committed and merged to 7.x -- 
thanks! 

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