Bug 76735

Summary: [ls] Bad errormessages on broken symlinks
Product: [Retired] Red Hat Raw Hide Reporter: Enrico Scholz <rh-bugzilla>
Component: fileutilsAssignee: Tim Waugh <twaugh>
Status: CLOSED RAWHIDE QA Contact: Mike McLean <mikem>
Severity: medium Docs Contact:
Priority: medium    
Version: 1.0   
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2002-11-07 17:15:38 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Enrico Scholz 2002-10-25 16:46:54 UTC
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 16:18:47 UTC
I don't see this.  Can you see what 'strace' says is going wrong?

Comment 2 Enrico Scholz 2002-11-07 16:33:38 UTC
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 17:08:25 UTC
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 17:10:29 UTC
This will fix bug #76738 too

Comment 5 Tim Waugh 2002-11-07 17:21:45 UTC
Fixed package is 4.1.9-13, which will show up in rawhide shortly.