mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-23 04:51:16 -03:00
Split out io_pipe_t, let io_buffer_t inherit it
This commit is contained in:
33
postfork.cpp
33
postfork.cpp
@@ -117,15 +117,16 @@ static void free_redirected_fds_from_pipes(io_chain_t &io_chain)
|
||||
for (size_t j = 0; j < max; j++)
|
||||
{
|
||||
/* We're only interested in pipes */
|
||||
io_data_t *possible_conflict = io_chain.at(j).get();
|
||||
if (possible_conflict->io_mode != IO_PIPE && possible_conflict->io_mode != IO_BUFFER)
|
||||
io_data_t *io = io_chain.at(j).get();
|
||||
if (io->io_mode != IO_PIPE && io->io_mode != IO_BUFFER)
|
||||
continue;
|
||||
|
||||
CAST_INIT(io_pipe_t *, possible_conflict, io);
|
||||
/* If the pipe is a conflict, dup it to some other value */
|
||||
for (int k=0; k<2; k++)
|
||||
{
|
||||
/* If it's not a conflict, we don't care */
|
||||
if (possible_conflict->param1.pipe_fd[k] != fd_to_free)
|
||||
if (possible_conflict->pipe_fd[k] != fd_to_free)
|
||||
continue;
|
||||
|
||||
/* Repeat until we have a replacement fd */
|
||||
@@ -140,7 +141,7 @@ static void free_redirected_fds_from_pipes(io_chain_t &io_chain)
|
||||
FATAL_EXIT();
|
||||
}
|
||||
}
|
||||
possible_conflict->param1.pipe_fd[k] = replacement_fd;
|
||||
possible_conflict->pipe_fd[k] = replacement_fd;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -245,6 +246,7 @@ static int handle_child_io(io_chain_t &io_chain)
|
||||
case IO_BUFFER:
|
||||
case IO_PIPE:
|
||||
{
|
||||
CAST_INIT(io_pipe_t *, io_pipe, io);
|
||||
/* If write_pipe_idx is 0, it means we're connecting to the read end (first pipe fd). If it's 1, we're connecting to the write end (second pipe fd). */
|
||||
unsigned int write_pipe_idx = (io->is_input ? 0 : 1);
|
||||
/*
|
||||
@@ -253,20 +255,20 @@ static int handle_child_io(io_chain_t &io_chain)
|
||||
write_pipe?L"write":L"read",
|
||||
(io->io_mode == IO_BUFFER)?L"buffer":L"pipe",
|
||||
io->fd,
|
||||
io->param1.pipe_fd[0],
|
||||
io->param1.pipe_fd[1]);
|
||||
io->pipe_fd[0],
|
||||
io->pipe_fd[1]);
|
||||
*/
|
||||
if (dup2(io->param1.pipe_fd[write_pipe_idx], io->fd) != io->fd)
|
||||
if (dup2(io_pipe->pipe_fd[write_pipe_idx], io->fd) != io->fd)
|
||||
{
|
||||
debug_safe(1, LOCAL_PIPE_ERROR);
|
||||
safe_perror("dup2");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (io->param1.pipe_fd[0] >= 0)
|
||||
exec_close(io->param1.pipe_fd[0]);
|
||||
if (io->param1.pipe_fd[1] >= 0)
|
||||
exec_close(io->param1.pipe_fd[1]);
|
||||
if (io_pipe->pipe_fd[0] >= 0)
|
||||
exec_close(io_pipe->pipe_fd[0]);
|
||||
if (io_pipe->pipe_fd[1] >= 0)
|
||||
exec_close(io_pipe->pipe_fd[1]);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -485,8 +487,9 @@ bool fork_actions_make_spawn_properties(posix_spawnattr_t *attr, posix_spawn_fil
|
||||
case IO_BUFFER:
|
||||
case IO_PIPE:
|
||||
{
|
||||
CAST_INIT(const io_pipe_t *, io_pipe, io.get());
|
||||
unsigned int write_pipe_idx = (io->is_input ? 0 : 1);
|
||||
int from_fd = io->param1.pipe_fd[write_pipe_idx];
|
||||
int from_fd = io_pipe->pipe_fd[write_pipe_idx];
|
||||
int to_fd = io->fd;
|
||||
if (! err)
|
||||
err = posix_spawn_file_actions_adddup2(actions, from_fd, to_fd);
|
||||
@@ -495,14 +498,14 @@ bool fork_actions_make_spawn_properties(posix_spawnattr_t *attr, posix_spawn_fil
|
||||
if (write_pipe_idx > 0)
|
||||
{
|
||||
if (! err)
|
||||
err = posix_spawn_file_actions_addclose(actions, io->param1.pipe_fd[0]);
|
||||
err = posix_spawn_file_actions_addclose(actions, io_pipe->pipe_fd[0]);
|
||||
if (! err)
|
||||
err = posix_spawn_file_actions_addclose(actions, io->param1.pipe_fd[1]);
|
||||
err = posix_spawn_file_actions_addclose(actions, io_pipe->pipe_fd[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (! err)
|
||||
err = posix_spawn_file_actions_addclose(actions, io->param1.pipe_fd[0]);
|
||||
err = posix_spawn_file_actions_addclose(actions, io_pipe->pipe_fd[0]);
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user