Bug 112920 - [PATCH]: wrong realpath(1) behaviour
Summary: [PATCH]: wrong realpath(1) behaviour
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 6.2-STABLE
Hardware: Any Any
: Normal Affects Only Me
Assignee: Robert Watson
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-05-24 01:20 UTC by Ighighi
Modified: 2008-08-03 17:18 UTC (History)
0 users

See Also:


Attachments
realpath.patch (1.19 KB, patch)
2007-08-19 06:58 UTC, Ighighi
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ighighi 2007-05-24 01:20:00 UTC
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
Comment 1 Mark Linimon 2007-05-24 01:26:26 UTC
it looks like the patch got trimmed.  Please reply with a followup.

mcl
Comment 2 Ighighi 2007-05-24 12:46:58 UTC
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
Comment 3 Ighighi 2007-08-19 06:58:38 UTC
The patch that should have been attached in the previous post.
Comment 4 Robert Watson freebsd_committer freebsd_triage 2008-03-09 11:20:59 UTC
Responsible Changed
From-To: freebsd-bugs->rwatson

Take ownership of this PR.
Comment 5 dfilter service freebsd_committer freebsd_triage 2008-03-09 12:46:46 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"
Comment 6 Robert Watson freebsd_committer freebsd_triage 2008-03-09 12:54:51 UTC
State Changed
From-To: open->patched

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.
Comment 7 dfilter service freebsd_committer freebsd_triage 2008-03-16 18:56:01 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"
Comment 8 Robert Watson freebsd_committer freebsd_triage 2008-08-03 17:17:48 UTC
State Changed
From-To: patched->closed

Close this PR as the changes have been committed and merged to 7.x -- 
thanks!