* @param vb as returned by xlat_frame_eval()
* @param env_pairs VPs to put into into the environment. May be NULL.
* @param[out] pid_p The PID of the child
- * @param[out] fd_p The stdout FD of the child
+ * @param[out] input_fd The stdin FD of the child
+ * @param[out] output_fd The stdout FD of the child
* @return
* - <0 on error
* - 0 on success
* would allow finer-grained control over the attributes to put into
* the environment.
*/
-int fr_exec_wait_start(REQUEST *request, fr_value_box_t *vb, VALUE_PAIR *env_pairs, pid_t *pid_p, int *fd_p)
+int fr_exec_wait_start(REQUEST *request, fr_value_box_t *vb, VALUE_PAIR *env_pairs, pid_t *pid_p, int *input_fd, int *output_fd)
{
int argc;
char **envp;
char **argv;
pid_t pid;
fr_value_box_t *first;
+ int to_child[2] = {-1, -1};
int from_child[2] = {-1, -1};
/*
for (i = 0; i < argc; i++) RDEBUG3("arg[%d] %s", i, argv[i]);
}
- if (fd_p) {
+ if (input_fd) {
+ if (pipe(to_child) < 0) {
+ fr_strerror_printf("Failed opening pipe to read to child - %s", fr_strerror());
+ return -1;
+ }
+ }
+
+ if (output_fd) {
if (pipe(from_child) < 0) {
+ if (input_fd) {
+ close(to_child[0]);
+ close(to_child[1]);
+ }
fr_strerror_printf("Failed opening pipe to read from child - %s", fr_strerror());
return -1;
}
* The child never returns from calling fr_exec_child();
*/
if (pid == 0) {
- int unused[2] = {-1, -1};
-
- fr_exec_child(request, argv, envp, true, NULL, fd_p, unused, from_child);
+ fr_exec_child(request, argv, envp, true, input_fd, output_fd, to_child, from_child);
}
/*
if (pid < 0) {
ERROR("Couldn't fork %s: %s", argv[0], fr_syserror(errno));
- if (fd_p) {
+ if (input_fd) {
+ close(to_child[0]);
+ close(to_child[1]);
+ }
+ if (output_fd) {
close(from_child[0]);
close(from_child[1]);
}
*/
*pid_p = pid;
- if (fd_p) {
- *fd_p = from_child[0];
- fr_nonblock(*fd_p);
+ if (input_fd) {
+ *input_fd = to_child[1];
+ close(from_child[0]);
+ }
+
+ if (output_fd) {
+ *output_fd = from_child[0];
+ fr_nonblock(*output_fd);
close(from_child[1]);
}
int fr_exec_nowait(REQUEST *request, fr_value_box_t *vb, VALUE_PAIR *env_pairs);
-int fr_exec_wait_start(REQUEST *request, fr_value_box_t *vb, VALUE_PAIR *env_pairs, pid_t *pid_p, int *fd_p);
+int fr_exec_wait_start(REQUEST *request, fr_value_box_t *vb, VALUE_PAIR *env_pairs, pid_t *pid_p, int *input_fd, int *output_fd);
void fr_exec_waitpid(pid_t pid);
state->fd = -1;
if (state->out) fd_p = &state->fd;
- if (fr_exec_wait_start(request, state->box, NULL, &pid, fd_p) < 0) {
+ if (fr_exec_wait_start(request, state->box, NULL, &pid, NULL, fd_p) < 0) {
REDEBUG("Failed executing program - %s", fr_strerror());
fail:
*presult = RLM_MODULE_FAIL;