mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 21:03:12 +00:00
Make is_input a member of io_pipe_t
This commit is contained in:
parent
a63c0311bb
commit
57ef5289fe
4 changed files with 34 additions and 34 deletions
36
exec.cpp
36
exec.cpp
|
@ -571,20 +571,24 @@ void exec(parser_t &parser, job_t *j)
|
||||||
{
|
{
|
||||||
shared_ptr<io_data_t> &io = j->io.at(idx);
|
shared_ptr<io_data_t> &io = j->io.at(idx);
|
||||||
|
|
||||||
if ((io->io_mode == IO_BUFFER) && io->is_input)
|
if ((io->io_mode == IO_BUFFER))
|
||||||
{
|
{
|
||||||
/*
|
CAST_INIT(io_buffer_t *, io_buffer, io.get());
|
||||||
Input redirection - create a new gobetween process to take
|
if (io_buffer->is_input)
|
||||||
care of buffering, save the redirection in input_redirect
|
{
|
||||||
*/
|
/*
|
||||||
process_t *fake = new process_t();
|
Input redirection - create a new gobetween process to take
|
||||||
fake->type = INTERNAL_BUFFER;
|
care of buffering, save the redirection in input_redirect
|
||||||
fake->pipe_write_fd = 1;
|
*/
|
||||||
j->first_process->pipe_read_fd = io->fd;
|
process_t *fake = new process_t();
|
||||||
fake->next = j->first_process;
|
fake->type = INTERNAL_BUFFER;
|
||||||
j->first_process = fake;
|
fake->pipe_write_fd = 1;
|
||||||
input_redirect = static_cast<const io_buffer_t *>(io.get());
|
j->first_process->pipe_read_fd = io->fd;
|
||||||
break;
|
fake->next = j->first_process;
|
||||||
|
j->first_process = fake;
|
||||||
|
input_redirect = io_buffer;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -615,12 +619,10 @@ void exec(parser_t &parser, job_t *j)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
shared_ptr<io_pipe_t> pipe_read(new io_pipe_t(0));
|
shared_ptr<io_pipe_t> pipe_read(new io_pipe_t(0, true));
|
||||||
pipe_read->is_input = 1;
|
|
||||||
pipe_read->pipe_fd[0] = pipe_read->pipe_fd[1] = -1;
|
pipe_read->pipe_fd[0] = pipe_read->pipe_fd[1] = -1;
|
||||||
|
|
||||||
shared_ptr<io_pipe_t> pipe_write(new io_pipe_t(1));
|
shared_ptr<io_pipe_t> pipe_write(new io_pipe_t(1, false));
|
||||||
pipe_write->is_input = 0;
|
|
||||||
pipe_write->pipe_fd[0] = pipe_write->pipe_fd[1] = -1;
|
pipe_write->pipe_fd[0] = pipe_write->pipe_fd[1] = -1;
|
||||||
|
|
||||||
j->io.push_back(pipe_write);
|
j->io.push_back(pipe_write);
|
||||||
|
|
11
io.cpp
11
io.cpp
|
@ -72,12 +72,14 @@ void io_file_t::print() const
|
||||||
|
|
||||||
void io_pipe_t::print() const
|
void io_pipe_t::print() const
|
||||||
{
|
{
|
||||||
fprintf(stderr, "pipe {%d, %d}\n", pipe_fd[0], pipe_fd[1]);
|
fprintf(stderr, "pipe {%d, %d} (input: %s)\n", pipe_fd[0], pipe_fd[1],
|
||||||
|
is_input ? "yes" : "no");
|
||||||
}
|
}
|
||||||
|
|
||||||
void io_buffer_t::print() const
|
void io_buffer_t::print() const
|
||||||
{
|
{
|
||||||
fprintf(stderr, "buffer %p (size %lu)\n", out_buffer_ptr(), out_buffer_size());
|
fprintf(stderr, "buffer %p (input: %s, size %lu)\n", out_buffer_ptr(),
|
||||||
|
is_input ? "yes" : "no", out_buffer_size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void io_buffer_t::read()
|
void io_buffer_t::read()
|
||||||
|
@ -132,8 +134,7 @@ void io_buffer_t::read()
|
||||||
io_buffer_t *io_buffer_t::create(bool is_input)
|
io_buffer_t *io_buffer_t::create(bool is_input)
|
||||||
{
|
{
|
||||||
bool success = true;
|
bool success = true;
|
||||||
io_buffer_t *buffer_redirect = new io_buffer_t(is_input ? 0 : 1);
|
io_buffer_t *buffer_redirect = new io_buffer_t(is_input ? 0 : 1, is_input);
|
||||||
buffer_redirect->is_input = is_input ? true : false;
|
|
||||||
|
|
||||||
if (exec_pipe(buffer_redirect->pipe_fd) == -1)
|
if (exec_pipe(buffer_redirect->pipe_fd) == -1)
|
||||||
{
|
{
|
||||||
|
@ -221,7 +222,7 @@ void io_print(const io_chain_t &chain)
|
||||||
for (size_t i=0; i < chain.size(); i++)
|
for (size_t i=0; i < chain.size(); i++)
|
||||||
{
|
{
|
||||||
const shared_ptr<const io_data_t> &io = chain.at(i);
|
const shared_ptr<const io_data_t> &io = chain.at(i);
|
||||||
fprintf(stderr, "\t%lu: fd:%d, input:%s, ", (unsigned long)i, io->fd, io->is_input ? "yes" : "no");
|
fprintf(stderr, "\t%lu: fd:%d, ", (unsigned long)i, io->fd);
|
||||||
io->print();
|
io->print();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
17
io.h
17
io.h
|
@ -24,8 +24,7 @@ private:
|
||||||
protected:
|
protected:
|
||||||
io_data_t(io_mode_t m, int f) :
|
io_data_t(io_mode_t m, int f) :
|
||||||
io_mode(m),
|
io_mode(m),
|
||||||
fd(f),
|
fd(f)
|
||||||
is_input(0)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,10 +35,6 @@ public:
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
virtual void print() const = 0;
|
virtual void print() const = 0;
|
||||||
|
|
||||||
/** Set to true if this is an input io redirection */
|
|
||||||
bool is_input;
|
|
||||||
|
|
||||||
virtual ~io_data_t() = 0;
|
virtual ~io_data_t() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -106,12 +101,14 @@ class io_pipe_t : public io_data_t
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
int pipe_fd[2];
|
int pipe_fd[2];
|
||||||
|
bool is_input;
|
||||||
|
|
||||||
virtual void print() const;
|
virtual void print() const;
|
||||||
|
|
||||||
io_pipe_t(int f):
|
io_pipe_t(int f, bool i):
|
||||||
io_data_t(IO_PIPE, f),
|
io_data_t(IO_PIPE, f),
|
||||||
pipe_fd()
|
pipe_fd(),
|
||||||
|
is_input(i)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -122,8 +119,8 @@ private:
|
||||||
/** buffer to save output in */
|
/** buffer to save output in */
|
||||||
std::vector<char> *out_buffer;
|
std::vector<char> *out_buffer;
|
||||||
|
|
||||||
io_buffer_t(int f):
|
io_buffer_t(int f, bool i):
|
||||||
io_pipe_t(f),
|
io_pipe_t(f, i),
|
||||||
out_buffer(new std::vector<char>)
|
out_buffer(new std::vector<char>)
|
||||||
{
|
{
|
||||||
io_mode = IO_BUFFER;
|
io_mode = IO_BUFFER;
|
||||||
|
|
|
@ -248,7 +248,7 @@ static int handle_child_io(io_chain_t &io_chain)
|
||||||
{
|
{
|
||||||
CAST_INIT(io_pipe_t *, io_pipe, io);
|
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). */
|
/* 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);
|
unsigned int write_pipe_idx = (io_pipe->is_input ? 0 : 1);
|
||||||
/*
|
/*
|
||||||
debug( 0,
|
debug( 0,
|
||||||
L"%ls %ls on fd %d (%d %d)",
|
L"%ls %ls on fd %d (%d %d)",
|
||||||
|
@ -488,7 +488,7 @@ bool fork_actions_make_spawn_properties(posix_spawnattr_t *attr, posix_spawn_fil
|
||||||
case IO_PIPE:
|
case IO_PIPE:
|
||||||
{
|
{
|
||||||
CAST_INIT(const io_pipe_t *, io_pipe, io.get());
|
CAST_INIT(const io_pipe_t *, io_pipe, io.get());
|
||||||
unsigned int write_pipe_idx = (io->is_input ? 0 : 1);
|
unsigned int write_pipe_idx = (io_pipe->is_input ? 0 : 1);
|
||||||
int from_fd = io_pipe->pipe_fd[write_pipe_idx];
|
int from_fd = io_pipe->pipe_fd[write_pipe_idx];
|
||||||
int to_fd = io->fd;
|
int to_fd = io->fd;
|
||||||
if (! err)
|
if (! err)
|
||||||
|
|
Loading…
Reference in a new issue