ls --color can't be interrupted when processing large directory
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
coreutils (Ubuntu) |
Confirmed
|
Undecided
|
Unassigned |
Bug Description
Binary package hint: coreutils
When listing a large directory with --color, ls can't be interrupted with Ctrl-C or other signals.
To reproduce:
- Make a directory, /huge/dir, containing lots of files (I used about 400000 files)
- ls -l --color /huge/dir
- ls sits there for a bit while reading the directory and stat'ing all the files. Try hitting Ctrl-C. ls does not exit. Ctrl-Z, Ctrl-\ also do not work. Only SIGKILL works.
The problem appears to be that when --color is active, ls handles all signals, so that it can reset the terminal before exiting. When a signal such as SIGINT arrives, ls just sets a flag (e.g. `interrupt_signal') and at some later time calls `process_signals' to process it appropriately (by exiting). However, it seems that `process_signals' is not called while looping over the entries in a single directory; it is only called once output starts to be produced. The effect is that `ls' cannot be interrupted.
This should be easy to fix by calling `process_signals' from more places. Since it normally just tests a flag and returns, the overhead should be negligible.
This is ls from coreutils-
ProblemType: Bug
DistroRelease: Ubuntu 11.04
Package: coreutils 8.5-1ubuntu6
ProcVersionSign
Uname: Linux 2.6.38-8-generic i686
Architecture: i386
Date: Mon May 23 22:31:36 2011
ProcEnviron:
LANGUAGE=en_US:en
LANG=en_US.UTF-8
SHELL=/bin/bash
SourcePackage: coreutils
UpgradeStatus: Upgraded to natty on 2011-04-30 (23 days ago)
tags: | added: patch |
Here is a patch that fixes it.