summaryrefslogtreecommitdiffstats
path: root/src/providers/ldap/sdap_child_helpers.c
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2014-12-08 14:08:26 +0100
committerJakub Hrozek <jhrozek@redhat.com>2015-01-15 10:32:56 +0100
commit752227a75c0349089f1d7fdd3a09c8d4a77f425d (patch)
tree9233b753ff9b2d78937261ef900e4437ca068121 /src/providers/ldap/sdap_child_helpers.c
parent44703b84feaafa4f0a4f8df11c5a503dcf48616e (diff)
downloadsssd-752227a75c0349089f1d7fdd3a09c8d4a77f425d.tar.gz
sssd-752227a75c0349089f1d7fdd3a09c8d4a77f425d.tar.xz
sssd-752227a75c0349089f1d7fdd3a09c8d4a77f425d.zip
LDAP: Use child_io_destructor instead of child_cleanup in a custom desctructor
ldap_child was the only child process that used child_cleanup instead of the common child_io_destructor. Unify the implementation to use the common function instead. Reviewed-by: Pavel Březina <pbrezina@redhat.com>
Diffstat (limited to 'src/providers/ldap/sdap_child_helpers.c')
-rw-r--r--src/providers/ldap/sdap_child_helpers.c39
1 files changed, 17 insertions, 22 deletions
diff --git a/src/providers/ldap/sdap_child_helpers.c b/src/providers/ldap/sdap_child_helpers.c
index 400109890..72435cc74 100644
--- a/src/providers/ldap/sdap_child_helpers.c
+++ b/src/providers/ldap/sdap_child_helpers.c
@@ -47,8 +47,7 @@
struct sdap_child {
/* child info */
pid_t pid;
- int read_from_child_fd;
- int write_to_child_fd;
+ struct child_io_fds *io;
};
static void sdap_close_fd(int *fd)
@@ -70,15 +69,6 @@ static void sdap_close_fd(int *fd)
*fd = -1;
}
-static int sdap_child_destructor(void *ptr)
-{
- struct sdap_child *child = talloc_get_type(ptr, struct sdap_child);
-
- child_cleanup(child->read_from_child_fd, child->write_to_child_fd);
-
- return 0;
-}
-
static errno_t sdap_fork_child(struct tevent_context *ev,
struct sdap_child *child)
{
@@ -114,12 +104,12 @@ static errno_t sdap_fork_child(struct tevent_context *ev,
return err;
} else if (pid > 0) { /* parent */
child->pid = pid;
- child->read_from_child_fd = pipefd_from_child[0];
+ child->io->read_from_child_fd = pipefd_from_child[0];
close(pipefd_from_child[1]);
- child->write_to_child_fd = pipefd_to_child[1];
+ child->io->write_to_child_fd = pipefd_to_child[1];
close(pipefd_to_child[0]);
- fd_nonblocking(child->read_from_child_fd);
- fd_nonblocking(child->write_to_child_fd);
+ fd_nonblocking(child->io->read_from_child_fd);
+ fd_nonblocking(child->io->write_to_child_fd);
ret = child_handler_setup(ev, pid, NULL, NULL, NULL);
if (ret != EOK) {
@@ -296,9 +286,14 @@ struct tevent_req *sdap_get_tgt_send(TALLOC_CTX *mem_ctx,
goto fail;
}
- state->child->read_from_child_fd = -1;
- state->child->write_to_child_fd = -1;
- talloc_set_destructor((TALLOC_CTX *)state->child, sdap_child_destructor);
+ state->child->io = talloc(state, struct child_io_fds);
+ if (state->child->io == NULL) {
+ ret = ENOMEM;
+ goto fail;
+ }
+ state->child->io->read_from_child_fd = -1;
+ state->child->io->write_to_child_fd = -1;
+ talloc_set_destructor((TALLOC_CTX *) state->child->io, child_io_destructor);
/* prepare the data to pass to child */
ret = create_tgt_req_send_buffer(state,
@@ -322,7 +317,7 @@ struct tevent_req *sdap_get_tgt_send(TALLOC_CTX *mem_ctx,
}
subreq = write_pipe_send(state, ev, buf->data, buf->size,
- state->child->write_to_child_fd);
+ state->child->io->write_to_child_fd);
if (!subreq) {
ret = ENOMEM;
goto fail;
@@ -352,10 +347,10 @@ static void sdap_get_tgt_step(struct tevent_req *subreq)
return;
}
- sdap_close_fd(&state->child->write_to_child_fd);
+ sdap_close_fd(&state->child->io->write_to_child_fd);
subreq = read_pipe_send(state, state->ev,
- state->child->read_from_child_fd);
+ state->child->io->read_from_child_fd);
if (!subreq) {
tevent_req_error(req, ENOMEM);
return;
@@ -378,7 +373,7 @@ static void sdap_get_tgt_done(struct tevent_req *subreq)
return;
}
- sdap_close_fd(&state->child->read_from_child_fd);
+ sdap_close_fd(&state->child->io->read_from_child_fd);
tevent_req_done(req);
}