2005-09-20 13:26:39 +00:00
|
|
|
/** \file exec.h
|
2012-11-18 10:23:22 +00:00
|
|
|
Prototypes for functions for executing a program
|
2005-09-20 13:26:39 +00:00
|
|
|
*/
|
|
|
|
|
2005-10-04 15:11:39 +00:00
|
|
|
#ifndef FISH_EXEC_H
|
2005-10-24 15:26:25 +00:00
|
|
|
/**
|
|
|
|
Header guard
|
|
|
|
*/
|
2005-10-04 15:11:39 +00:00
|
|
|
#define FISH_EXEC_H
|
|
|
|
|
|
|
|
#include <wchar.h>
|
2011-12-27 03:18:46 +00:00
|
|
|
#include <vector>
|
2005-10-04 15:11:39 +00:00
|
|
|
|
|
|
|
#include "proc.h"
|
|
|
|
#include "util.h"
|
2011-12-27 03:18:46 +00:00
|
|
|
#include "common.h"
|
2005-10-04 15:11:39 +00:00
|
|
|
|
2005-10-08 11:20:51 +00:00
|
|
|
/**
|
|
|
|
pipe redirection error message
|
|
|
|
*/
|
2006-01-04 12:51:02 +00:00
|
|
|
#define PIPE_ERROR _(L"An error occurred while setting up pipe")
|
2005-10-08 11:20:51 +00:00
|
|
|
|
2005-09-20 13:26:39 +00:00
|
|
|
/**
|
2012-11-18 10:23:22 +00:00
|
|
|
Execute the processes specified by j.
|
2005-09-20 13:26:39 +00:00
|
|
|
|
|
|
|
I've put a fair bit of work into making builtins behave like other
|
|
|
|
programs as far as pipes are concerned. Unlike i.e. bash, builtins
|
|
|
|
can pipe to other builtins with arbitrary amounts of data, and so
|
|
|
|
on. To do this, after a builtin is run in the real process, it
|
|
|
|
forks and a dummy process is created, responsible for writing the
|
|
|
|
output of the builtin. This is surprisingly cheap on my computer,
|
|
|
|
probably because of the marvels of copy on write forking.
|
|
|
|
|
|
|
|
This rule is short circuted in the case where a builtin does not
|
|
|
|
output to a pipe and does in fact not output anything. The speed
|
|
|
|
improvement from this optimization is not noticable on a normal
|
|
|
|
computer/OS in regular use, but the promiscous amounts of forking
|
|
|
|
that resulted was responsible for a huge slowdown when using
|
|
|
|
Valgrind as well as when doing complex command-specific
|
|
|
|
completions.
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
2012-01-23 04:47:13 +00:00
|
|
|
class parser_t;
|
|
|
|
void exec( parser_t &parser, job_t *j );
|
2005-09-20 13:26:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Evaluate the expression cmd in a subshell, add the outputs into the
|
|
|
|
list l. On return, the status flag as returned bu \c
|
|
|
|
proc_gfet_last_status will not be changed.
|
|
|
|
|
|
|
|
\param cmd the command to execute
|
2012-02-08 07:35:41 +00:00
|
|
|
\param outputs The list to insert output into.
|
2005-09-20 13:26:39 +00:00
|
|
|
|
|
|
|
\return the status of the last job to exit, or -1 if en error was encountered.
|
|
|
|
*/
|
2012-02-08 07:35:41 +00:00
|
|
|
__warn_unused int exec_subshell(const wcstring &cmd, std::vector<wcstring> &outputs );
|
|
|
|
__warn_unused int exec_subshell(const wcstring &cmd );
|
2011-12-27 03:18:46 +00:00
|
|
|
|
2005-09-20 14:51:00 +00:00
|
|
|
|
2005-10-03 13:24:46 +00:00
|
|
|
/**
|
2012-03-09 07:21:07 +00:00
|
|
|
Loops over close until the syscall was run without being
|
|
|
|
interrupted. Then removes the fd from the open_fds list.
|
2005-10-03 13:24:46 +00:00
|
|
|
*/
|
2005-10-08 11:20:51 +00:00
|
|
|
void exec_close( int fd );
|
2005-09-20 13:26:39 +00:00
|
|
|
|
2005-10-03 13:24:46 +00:00
|
|
|
/**
|
2005-10-08 11:20:51 +00:00
|
|
|
Call pipe(), and add resulting fds to open_fds, the list of opend
|
|
|
|
file descriptors for pipes.
|
2005-10-03 13:24:46 +00:00
|
|
|
*/
|
2005-10-08 11:20:51 +00:00
|
|
|
int exec_pipe( int fd[2]);
|
2005-10-04 15:11:39 +00:00
|
|
|
|
2012-02-28 23:11:46 +00:00
|
|
|
/* Close all fds in open_fds. This is called from postfork.cpp */
|
2012-08-15 07:57:56 +00:00
|
|
|
void close_unused_internal_pipes( const io_chain_t &io );
|
|
|
|
|
|
|
|
/* Gets all unused internal pipes into fds */
|
|
|
|
void get_unused_internal_pipes(std::vector<int> &fds, const io_chain_t &io);
|
|
|
|
|
|
|
|
/** Gets the interpreter for a given command */
|
|
|
|
char *get_interpreter( const char *command, char *interpreter, size_t buff_size );
|
2012-02-28 23:11:46 +00:00
|
|
|
|
2005-10-04 15:11:39 +00:00
|
|
|
#endif
|