[v2] Correctly report nscd child process status
diff mbox

Message ID 20140627092516.1428a050@zion
State New
Headers show

Commit Message

Arjun Shankar June 27, 2014, 7:25 a.m. UTC
The nscd parent process returns the result of a `wait' call rather than
the exit status of the child it waits for. These two aren't exactly the
same. In my case (and probably on most machines), the exit status is in
the 2nd LSB of the result of `wait', and so:

e.g. if the nscd child process returns 1, the parent returns 1 << 8,
which Bash happily reports as 0.

This patch should fix that.

ChangeLog:

2014-06-27  Arjun Shankar  <arjun.is@lostca.se>

	[BZ #17092]
	* nscd/nscd.c (monitor_child): Fix how status reported by
	'wait' is interpreted.
---
 nscd/nscd.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

Changes in v2:
 - remove periods at the end of error messages

Comments

Siddhesh Poyarekar June 27, 2014, 6:04 p.m. UTC | #1
Thanks, I have committed this now.

Siddhesh

On Fri, Jun 27, 2014 at 09:25:16AM +0200, Arjun Shankar wrote:
> The nscd parent process returns the result of a `wait' call rather than
> the exit status of the child it waits for. These two aren't exactly the
> same. In my case (and probably on most machines), the exit status is in
> the 2nd LSB of the result of `wait', and so:
> 
> e.g. if the nscd child process returns 1, the parent returns 1 << 8,
> which Bash happily reports as 0.
> 
> This patch should fix that.
> 
> ChangeLog:
> 
> 2014-06-27  Arjun Shankar  <arjun.is@lostca.se>
> 
> 	[BZ #17092]
> 	* nscd/nscd.c (monitor_child): Fix how status reported by
> 	'wait' is interpreted.
> ---
>  nscd/nscd.c | 22 +++++++++++++---------
>  1 file changed, 13 insertions(+), 9 deletions(-)
> 
> Changes in v2:
>  - remove periods at the end of error messages

> diff --git a/nscd/nscd.c b/nscd/nscd.c
> index 3dd1135..7131ead 100644
> --- a/nscd/nscd.c
> +++ b/nscd/nscd.c
> @@ -612,21 +612,25 @@ monitor_child (int fd)
>       method, like a segfault.  */
>    if (ret <= 0 || child_ret != 0)
>      {
> -      int err = wait (&child_ret);
> +      int status;
> +      int err = wait (&status);
>  
>        if (err < 0)
>  	{
> -	  fprintf (stderr, _("wait failed"));
> +	  fprintf (stderr, _("'wait' failed\n"));
>  	  return 1;
>  	}
>  
> -      fprintf (stderr, _("child exited with status %d"),
> -	       WEXITSTATUS (child_ret));
> -      if (WIFSIGNALED (child_ret))
> -	fprintf (stderr, _(", terminated by signal %d.\n"),
> -		 WTERMSIG (child_ret));
> -      else
> -	fprintf (stderr, ".\n");
> +      if (WIFEXITED (status))
> +        {
> +          child_ret = WEXITSTATUS (status);
> +          fprintf (stderr, _("child exited with status %d\n"), child_ret);
> +        }
> +      if (WIFSIGNALED (status))
> +        {
> +          child_ret = WTERMSIG (status);
> +          fprintf (stderr, _("child terminated by signal %d\n"), child_ret);
> +        }
>      }
>  
>    /* We have the child status, so exit with that code.  */

Patch
diff mbox

diff --git a/nscd/nscd.c b/nscd/nscd.c
index 3dd1135..7131ead 100644
--- a/nscd/nscd.c
+++ b/nscd/nscd.c
@@ -612,21 +612,25 @@  monitor_child (int fd)
      method, like a segfault.  */
   if (ret <= 0 || child_ret != 0)
     {
-      int err = wait (&child_ret);
+      int status;
+      int err = wait (&status);
 
       if (err < 0)
 	{
-	  fprintf (stderr, _("wait failed"));
+	  fprintf (stderr, _("'wait' failed\n"));
 	  return 1;
 	}
 
-      fprintf (stderr, _("child exited with status %d"),
-	       WEXITSTATUS (child_ret));
-      if (WIFSIGNALED (child_ret))
-	fprintf (stderr, _(", terminated by signal %d.\n"),
-		 WTERMSIG (child_ret));
-      else
-	fprintf (stderr, ".\n");
+      if (WIFEXITED (status))
+        {
+          child_ret = WEXITSTATUS (status);
+          fprintf (stderr, _("child exited with status %d\n"), child_ret);
+        }
+      if (WIFSIGNALED (status))
+        {
+          child_ret = WTERMSIG (status);
+          fprintf (stderr, _("child terminated by signal %d\n"), child_ret);
+        }
     }
 
   /* We have the child status, so exit with that code.  */