package procps
tags 354255 + patch
thanks
Hi,
after a normal quit, top returns with exit code 1 which indicates an
error.
Bye, Jörg.
In the file top.c, there is a function called do_key(). If 'q' is
pressed to quit the program, end_pgm(0) is called. Here is the
function:
/*
* Normal end of execution.
* catches:
* SIGALRM, SIGHUP, SIGINT, SIGPIPE, SIGQUIT and SIGTERM */
static void end_pgm (int dont_care_sig) NORETURN;
static void end_pgm (int dont_care_sig)
{
(void)dont_care_sig;
bye_bye(stdout, 1, NULL);
}
The parameter '0' is never used in this function, instead, a function
is called - bye_bye(stdout, 1, NULL). In bye_bye(), exit() is called
with the second parameter, thus /usr/bin/top always exits with the
exit code '1' if you type 'q'.
If you grep for bye_bye, you will see it called with parameters
(stderr, 1, NULL). I think the call in end_pgm() should be
bye_bye(stdout, 0, NULL), as the comments for end_pgm() reads "Normal
end of execution". Alternatively, you can call bye_bye() with the
dont_care_sig parameter, but be aware that there are a few functions
that take the dont_care_sig parameter, but throw that value away.
Patch attached.
--- top.c 2006-06-24 23:41:48.000000000 -0700
+++ topFIX.c 2007-04-29 19:34:44.000000000 -0700
@@ -409,7 +409,7 @@
static void end_pgm (int dont_care_sig)
{
(void)dont_care_sig;
- bye_bye(stdout, 1, NULL);
+ bye_bye(stdout, 0, NULL);
}