This service will be undergoing maintenance at 20:00 UTC, 2017-04-03. It is expected to last about 30 minutes
Bug 76735 - [ls] Bad errormessages on broken symlinks
[ls] Bad errormessages on broken symlinks
Status: CLOSED RAWHIDE
Product: Red Hat Raw Hide
Classification: Retired
Component: fileutils (Show other bugs)
1.0
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Tim Waugh
Mike McLean
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2002-10-25 12:46 EDT by Enrico Scholz
Modified: 2007-04-18 12:47 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2002-11-07 12:15:38 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Enrico Scholz 2002-10-25 12:46:54 EDT
Description of Problem:

'ls' gives a misleading errormessage if the current directory contains a broken
symlink.


Version-Release number of selected component (if applicable):

fileutils-4.1.9-12
vanilla linux  2.4.19

How Reproducible:

100%


Steps to Reproduce:
1. mkdir /tmp/ftest && cd /tmp/ftest
2. ls --color=tty    ## or just 'ls' which is its alias
3. ln -s foo bar
4. ls --color=tty


Actual Results:

$ ls --color=tty
$ ln -s foo bar
$ ls --color=tty
ls: .: No such file or directory
bar
$


Expected Results:

no error-message
Comment 1 Tim Waugh 2002-11-07 11:18:47 EST
I don't see this.  Can you see what 'strace' says is going wrong?
Comment 2 Enrico Scholz 2002-11-07 11:33:38 EST
strace tells:

----
...
open(".", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY) = 3
fstat64(3, {st_mode=S_IFDIR|0775, st_size=0, ...}) = 0
fcntl64(3, F_SETFD, FD_CLOEXEC)         = 0
brk(0x805f000)                          = 0x805f000
getdents64(0x3, 0x805dc70, 0x1000, 0x805dc40) = 72
lstat64("bar", {st_mode=S_IFLNK|0777, st_size=3, ...}) = 0
readlink("bar", "foo", 128)             = 3
stat64("foo", 0xbffff460)               = -1 ENOENT (No such file or directory)
getdents64(0x3, 0x805dc70, 0x1000, 0x805dc40) = 0
close(3)                                = 0
write(1, "\33[00m", 5)                  = 5
write(2, "ls: ", 4ls: )                     = 4
write(2, ".", 1.)                        = 1
write(2, ": No such file or directory", 27: No such file or directory) = 27
write(2, "\n", 1
----
Comment 3 Enrico Scholz 2002-11-07 12:08:25 EST
Fix is

| 	  type = next->d_type;
| #endif
| 	total_blocks += gobble_file (next->d_name, type, 0, name);
|+ 	errno = 0;
|       }
| 
|   close_error = CLOSEDIR (reading);

in src/ls.c:2110


Alternatively, you can do the more obviously

|   clear_files ();
| 
|-  errno = 0;
|-  while ((next = readdir (reading)) != NULL) 
|+  while ((next = (errno=0, readdir (reading))) != NULL)
|     if (file_interesting (next))
|       {
| 	  enum filetype type = unknown;

Comment 4 Enrico Scholz 2002-11-07 12:10:29 EST
This will fix bug #76738 too
Comment 5 Tim Waugh 2002-11-07 12:21:45 EST
Fixed package is 4.1.9-13, which will show up in rawhide shortly.

Note You need to log in before you can comment on or make changes to this bug.