child_common.c revision a9402e5d8e75f7f361a5754e91180ed4f4ee98e1
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff Common helper functions to be used in child processes
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence Sumit Bose <sbose@redhat.com>
15a44745412679c30a6d022733925af70a38b715David Lawrence Copyright (C) 2009 Red Hat
15a44745412679c30a6d022733925af70a38b715David Lawrence This program is free software; you can redistribute it and/or modify
15a44745412679c30a6d022733925af70a38b715David Lawrence it under the terms of the GNU General Public License as published by
15a44745412679c30a6d022733925af70a38b715David Lawrence the Free Software Foundation; either version 3 of the License, or
15a44745412679c30a6d022733925af70a38b715David Lawrence (at your option) any later version.
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff This program is distributed in the hope that it will be useful,
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff but WITHOUT ANY WARRANTY; without even the implied warranty of
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence GNU General Public License for more details.
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff You should have received a copy of the GNU General Public License
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff along with this program. If not, see <http://www.gnu.org/licenses/>.
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff/* Async communication with the child process via a pipe */
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graffstatic void write_pipe_handler(struct tevent_context *ev,
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graffstruct tevent_req *write_pipe_send(TALLOC_CTX *mem_ctx,
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff req = tevent_req_create(mem_ctx, &state, struct write_pipe_state);
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff fde = tevent_add_fd(ev, state, fd, TEVENT_FD_WRITE,
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graffstatic void write_pipe_handler(struct tevent_context *ev,
9f95b0199c3f1b0ef3d40c1854a7501d72112e5aMichael Graff struct tevent_req *req = talloc_get_type(pvt, struct tevent_req);
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff struct write_pipe_state *state = tevent_req_data(req,
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff DEBUG(1, ("write_pipe_done called with TEVENT_FD_READ,"
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff " this should not happen.\n"));
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff if (errno == EAGAIN || errno == EINTR) return;
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff DEBUG(1, ("write failed [%d][%s].\n", errno, strerror(errno)));
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff } else if (size >= 0) {
153d59973f4434d80adfa6097a31d1e349f2d3baBrian Wellington DEBUG(1, ("write to much, this should never happen.\n"));
153d59973f4434d80adfa6097a31d1e349f2d3baBrian Wellington DEBUG(1, ("unexpected return value of write [%d].\n", size));
return EOK;
struct read_pipe_state {
int fd;
goto fail;
return req;
fail:
return NULL;
struct read_pipe_state);
} else if (size > 0) {
} else if (size == 0) {
return EOK;
int flags;
int ret;
int ret;
int child_status;
errno = 0;
} else if (ret == 0) {
child_status));
--count;
} while (count < 0);
int child_debug_fd,
const char *binary,
char ***_argv)
char ** argv;
return ENOMEM;
goto fail;
if (child_debug_to_file) {
goto fail;
if (!child_debug_timestamps) {
goto fail;
goto fail;
if (argc != 0) {
goto fail;
return EOK;
fail:
return ret;
int ret;
char **argv;
return err;
return err;
return ret;
return err;
return EOK;
int ret;