From: Alexandra Ellwood Date: Tue, 2 Sep 2003 18:14:37 +0000 (+0000) Subject: Fixed handling of krb5_net_write() failing (need to call waitpid() on child even... X-Git-Tag: krb5-1.4-beta1~744 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=ed2a6880088090e3170d632f08203d8190db8cb0;p=krb5.git Fixed handling of krb5_net_write() failing (need to call waitpid() on child even if we kill it) ticket: 1799 git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@15805 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/kadm5/srv/svr_principal.c b/src/lib/kadm5/srv/svr_principal.c index b988b5ea0..0666fe62b 100644 --- a/src/lib/kadm5/srv/svr_principal.c +++ b/src/lib/kadm5/srv/svr_principal.c @@ -1131,11 +1131,14 @@ kadm5_launch_task (krb5_context context, _exit (1); /* Fail if execv fails */ } else { /* The parent: */ - + int status; + if (data_buffer != NULL) { /* Write out the buffer to the child */ if (krb5_net_write (context, data_pipe[1], data_buffer, strlen (data_buffer)) < 0) { + /* kill the child to make sure waitpid() won't hang later */ + kill (pid, SIGKILL); ret = errno; } } @@ -1143,27 +1146,18 @@ kadm5_launch_task (krb5_context context, close (data_buffer[0]); close (data_buffer[1]); - if (!ret) { - int status = 0; - - waitpid (pid, &status, 0); - - /* fprintf (stderr, "Call \"%s\" returned status %d\n", argv[2], - WEXITSTATUS(status)); */ + waitpid (pid, &status, 0); + if (!ret) { if (WIFEXITED (status)) { - /* task finished. Check return value */ + /* child read password and exited. Check the return value. */ if ((WEXITSTATUS (status) != 0) && (WEXITSTATUS (status) != 252)) { ret = KRB5KDC_ERR_POLICY; /* password change rejected */ } } else { - /* task crashed or was killed */ + /* child read password but crashed or was killed */ ret = KRB5KRB_ERR_GENERIC; /* FIXME: better error */ } - } else { - /* since the password write failed, just try and kill the child - * process in order to clean up (it may already be gone). */ - kill (pid, SIGKILL); } } }