Minor cleanup of redirection functions

This commit is contained in:
ridiculousfish 2014-04-11 09:50:12 -07:00
parent f2a507c4a7
commit ec6dee8bd1
4 changed files with 8 additions and 18 deletions

View file

@ -1185,7 +1185,7 @@ void exec_job(parser_t &parser, job_t *j)
// Here we must have a non-NULL block_output_io_buffer // Here we must have a non-NULL block_output_io_buffer
assert(block_output_io_buffer.get() != NULL); assert(block_output_io_buffer.get() != NULL);
io_remove(process_net_io_chain, block_output_io_buffer); process_net_io_chain.remove(block_output_io_buffer);
block_output_io_buffer->read(); block_output_io_buffer->read();

6
io.cpp
View file

@ -210,11 +210,6 @@ void io_chain_t::append(const io_chain_t &chain)
this->insert(this->end(), chain.begin(), chain.end()); this->insert(this->end(), chain.begin(), chain.end());
} }
void io_remove(io_chain_t &list, const shared_ptr<const io_data_t> &element)
{
list.remove(element);
}
void io_print(const io_chain_t &chain) void io_print(const io_chain_t &chain)
{ {
if (chain.empty()) if (chain.empty())
@ -288,3 +283,4 @@ io_chain_t::io_chain_t(const shared_ptr<io_data_t> &data) :
io_chain_t::io_chain_t() : std::vector<shared_ptr<io_data_t> >() io_chain_t::io_chain_t() : std::vector<shared_ptr<io_data_t> >()
{ {
} }

10
io.h
View file

@ -63,8 +63,9 @@ public:
class io_fd_t : public io_data_t class io_fd_t : public io_data_t
{ {
public: public:
/** fd to redirect specified fd to */ /** fd to redirect specified fd to. For example, in 2>&1, old_fd is 1, and io_data_t::fd is 2 */
const int old_fd; const int old_fd;
/** Whether to close old_fd */ /** Whether to close old_fd */
const bool close_old; const bool close_old;
@ -195,13 +196,6 @@ public:
shared_ptr<io_data_t> get_io_for_fd(int fd); shared_ptr<io_data_t> get_io_for_fd(int fd);
}; };
/**
Remove the specified io redirection from the chain
*/
void io_remove(io_chain_t &list, const shared_ptr<const io_data_t> &element);
/** Destroys an io_chain */
void io_chain_destroy(io_chain_t &chain);
/** /**
Return the last io redirection in the chain for the specified file descriptor. Return the last io redirection in the chain for the specified file descriptor.

View file

@ -173,10 +173,10 @@ static int handle_child_io(const io_chain_t &io_chain)
free_redirected_fds_from_pipes(io_chain); free_redirected_fds_from_pipes(io_chain);
for (size_t idx = 0; idx < io_chain.size(); idx++) for (size_t idx = 0; idx < io_chain.size(); idx++)
{ {
io_data_t *io = io_chain.at(idx).get(); const io_data_t *io = io_chain.at(idx).get();
int tmp; int tmp;
if (io->io_mode == IO_FD && io->fd == static_cast<io_fd_t*>(io)->old_fd) if (io->io_mode == IO_FD && io->fd == static_cast<const io_fd_t*>(io)->old_fd)
{ {
continue; continue;
} }
@ -197,7 +197,7 @@ static int handle_child_io(const io_chain_t &io_chain)
case IO_FILE: case IO_FILE:
{ {
// Here we definitely do not want to set CLO_EXEC because our child needs access // Here we definitely do not want to set CLO_EXEC because our child needs access
CAST_INIT(io_file_t *, io_file, io); CAST_INIT(const io_file_t *, io_file, io);
if ((tmp=open(io_file->filename_cstr, if ((tmp=open(io_file->filename_cstr,
io_file->flags, OPEN_MASK))==-1) io_file->flags, OPEN_MASK))==-1)
{ {
@ -257,7 +257,7 @@ static int handle_child_io(const io_chain_t &io_chain)
case IO_BUFFER: case IO_BUFFER:
case IO_PIPE: case IO_PIPE:
{ {
CAST_INIT(io_pipe_t *, io_pipe, io); CAST_INIT(const 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_pipe->is_input ? 0 : 1); unsigned int write_pipe_idx = (io_pipe->is_input ? 0 : 1);
/* /*