Grep exits abnormally with code 123 when running rgrep on emacs

7

1

Greetings fellow Emacsers

I'm running GNU Emacs 23.1.1 on "Ubuntu 10.04.1 LTS" and any search I perform using the built-in M-x rgrep on the standard Linux kernel source code (vanilla) ends prematurely with the following error printed to the emacs echo area:

Grep exited abnormally with code 123

I have been seeing it for a while on Redhat systems as well, and with other (large) code bases, Anybody seen or even better cured that?

Thanks!

Edit: for reasons beyond me stackexchange does not allow me to edit my comment below so I'll update here.

following the comment below I have tried to run the same command that rgrep runs in an emacs shell buffer

 find . \( -path \*/SCCS -o -path \*/RCS -o -path \*/CVS -o -path \*/MCVS -o -path \*/.svn -o -path \*/.git
-o -path \*/.hg -o -path \*/.bzr -o -path \*/_MTN -o -path \*/_darcs -o -path \*/\{arch\} \) -prune -o  -type f \( -name \*.\[ch\] \) -p
rint0 | xargs -0 -e grep -i -nH -e v4l_compat_ioctl32

while it does not print any error, interrogating the exit code shows the same 123 again.

/home/mcradle/linux> echo $?
123

following the comment from Gilles I've tried to run

/home/mcradle/linux> find . -type f \( -name \*.\[ch\] \) -exec grep -i -nH -e v4l_compat_ioctl32 '{}' \;

which is functionally equivalent to the find and xargs combination and it completed with exit code 0

/home/mcradle/linux> echo $?
0

so it does seems to be something with xargs.

Mcradle

Posted 2010-10-07T16:27:57.733

Reputation: 780

1M-x rgrep runs find … | xargs grep …, and 123 means that at least one of xargs's invocations of grep returned a non-zero error code. If this happens only in large code bases, it might be related to xargs invoking more than one instance of grep (perhaps one instance finds no file?). Is a *grep* buffer created? – Gilles 'SO- stop being evil' – 2010-10-07T23:00:28.787

it does open the *grep* buffer even shows a bunch of results and then prints "Grep exited abnormally with code 123 at ..." – Mcradle – 2010-10-08T14:51:57.703

Answers

10

Looking at xargs exit code documentation:

123 if any invocation of the command exited with status 1-125

but according to grep documentation 1 is the exit status if grep didn't match the pattern

EXIT STATUS
   Normally, the exit status is 0 if selected lines are found and 1 otherwise.  

So to me it seems that the command line that emacs uses to issue an 'rgrep' search will always return 123, and this error either needs to be suppressed or replaced with a command line such as

find . -type f \( -name \*.\[ch\] \) -exec grep -i -nH -e v4l

Mcradle

Posted 2010-10-07T16:27:57.733

Reputation: 780

2

It looks like you're trying to do a recursive grep through a bunch of C .c and .h files, while ignoring directories used by version control systems. You want ack. See http://betterthangrep.com/

The command to do exactly what you are doing, in ack:

ack --cc -i v4l_compat_ioctl32

The effects of -r, -n and -H are assumed in ack. The -i is still case-insensitive, and --cc says "Search *.c and *.h files only"

No need for find. No need for xargs. Just a version of Perl installed and a single Perl program, with no external modules.

Andy Lester

Posted 2010-10-07T16:27:57.733

Reputation: 1 121

Thanks Andy. I have ack installed but never came around to download and install ack.el for emacs, I might do eventually. – Mcradle – 2010-10-09T00:14:18.777