ls dangling symlink
Version:
7.6 (fixed in 8.0)
How it is diagnosed (reproduced or source analysis)?
We couldn’t reproduce the failure, so we just analyzed the source code. .
Symptom:
Wrong result.
ls -Lis prints “0” for a dangling symlink. It should print “?”.
In addition, it will print an error msg: “cannot access”.
Root cause:
stat failed, but didn’t handle the failed stat properly.
gobble_file (.. ){
err = stat (absolute_name, &f->stat); ← detect error!
if (err != 0)
{
// the error message below will be printed!
/* Failure to stat a command line argument leads to
an exit status of 2. For other files, stat failure
provokes an exit status of 1. */
file_failure (command_line_arg,
_("cannot access %s"), absolute_name);
if (command_line_arg) ← command_line_arg = false
return 0;
f->name = xstrdup (name);
cwd_n_used++;
return 0;
}
f->stat_ok = true; ← f_stat_ok is not set
}
/* Here is where the “0” is printed by human_readable (ST_NBLOCKS (f->stat)..). Here f->stat_ok equals to 0. The fix is to add an additional check for f->stat_ok, and in this case, print “?”. */
print_file_name_and_frills ( … ) {
if (print_block_size)
printf ("%*s ", format == with_commas ? 0 : block_size_width,
+ ! f->stat_ok ? "?" :
human_readable (ST_NBLOCKS (f->stat), buf, human_output_opts,
ST_NBLOCKSIZE, output_block_size));
}
Is there Error Message?
Yes.
Can Errlog automatically insert the error message?
Yes. System error return pattern.