mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 21:33:09 +00:00
REmoved al_list from exec.cpp
This commit is contained in:
parent
b6bc4381fb
commit
d3311c81e5
1 changed files with 16 additions and 41 deletions
49
exec.cpp
49
exec.cpp
|
@ -24,6 +24,7 @@
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <deque>
|
||||||
|
|
||||||
#ifdef HAVE_SIGINFO_H
|
#ifdef HAVE_SIGINFO_H
|
||||||
#include <siginfo.h>
|
#include <siginfo.h>
|
||||||
|
@ -94,7 +95,7 @@
|
||||||
many situations in order to make sure that stray fds aren't lying
|
many situations in order to make sure that stray fds aren't lying
|
||||||
around.
|
around.
|
||||||
*/
|
*/
|
||||||
static array_list_t *open_fds=0;
|
static std::vector<int> open_fds;
|
||||||
|
|
||||||
static int set_child_group( job_t *j, process_t *p, int print_errors );
|
static int set_child_group( job_t *j, process_t *p, int print_errors );
|
||||||
|
|
||||||
|
@ -112,8 +113,6 @@ static void exec_write_and_exit( int fd, char *buff, size_t count, int status )
|
||||||
|
|
||||||
void exec_close( int fd )
|
void exec_close( int fd )
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
|
|
||||||
if( fd < 0 )
|
if( fd < 0 )
|
||||||
{
|
{
|
||||||
debug( 0, L"Called close on invalid file descriptor " );
|
debug( 0, L"Called close on invalid file descriptor " );
|
||||||
|
@ -130,22 +129,8 @@ void exec_close( int fd )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( open_fds )
|
/* Maybe remove this form our set of open fds */
|
||||||
{
|
open_fds.erase(remove(open_fds.begin(), open_fds.end(), fd), open_fds.end());
|
||||||
for( i=0; i<al_get_count( open_fds ); i++ )
|
|
||||||
{
|
|
||||||
int n = (int)al_get_long( open_fds, i );
|
|
||||||
if( n == fd )
|
|
||||||
{
|
|
||||||
al_set_long( open_fds,
|
|
||||||
i,
|
|
||||||
al_get_long( open_fds, al_get_count( open_fds ) -1 ) );
|
|
||||||
al_truncate( open_fds,
|
|
||||||
al_get_count( open_fds ) -1 );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int exec_pipe( int fd[2])
|
int exec_pipe( int fd[2])
|
||||||
|
@ -163,13 +148,8 @@ int exec_pipe( int fd[2])
|
||||||
|
|
||||||
debug( 4, L"Created pipe using fds %d and %d", fd[0], fd[1]);
|
debug( 4, L"Created pipe using fds %d and %d", fd[0], fd[1]);
|
||||||
|
|
||||||
if( open_fds == 0 )
|
open_fds.push_back(fd[0]);
|
||||||
{
|
open_fds.push_back(fd[1]);
|
||||||
open_fds = al_halloc( global_context );
|
|
||||||
}
|
|
||||||
|
|
||||||
al_push_long( open_fds, (long)fd[0] );
|
|
||||||
al_push_long( open_fds, (long)fd[1] );
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -208,21 +188,16 @@ static int use_fd_in_pipe( int fd, io_data_t *io )
|
||||||
*/
|
*/
|
||||||
static void close_unused_internal_pipes( io_data_t *io )
|
static void close_unused_internal_pipes( io_data_t *io )
|
||||||
{
|
{
|
||||||
int i=0;
|
/* A call to exec_close will modify open_fds, so be careful how we walk */
|
||||||
|
for (size_t i=0; i < open_fds.size(); i++) {
|
||||||
if( open_fds )
|
int fd = open_fds.at(i);
|
||||||
|
if( !use_fd_in_pipe( fd, io) )
|
||||||
{
|
{
|
||||||
for( ;i<al_get_count( open_fds ); i++ )
|
debug( 4, L"Close fd %d, used in other context", fd );
|
||||||
{
|
exec_close( fd );
|
||||||
int n = (long)al_get_long( open_fds, i );
|
|
||||||
if( !use_fd_in_pipe( n, io) )
|
|
||||||
{
|
|
||||||
debug( 4, L"Close fd %d, used in other context", n );
|
|
||||||
exec_close( n );
|
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue