2005-09-20 21:26:39 +08:00
|
|
|
/** \file exec.h
|
2012-11-18 18:23:22 +08:00
|
|
|
Prototypes for functions for executing a program
|
2005-09-20 21:26:39 +08:00
|
|
|
*/
|
|
|
|
|
2005-10-04 23:11:39 +08:00
|
|
|
#ifndef FISH_EXEC_H
|
|
|
|
#define FISH_EXEC_H
|
|
|
|
|
2015-07-25 23:14:25 +08:00
|
|
|
#include <stddef.h>
|
2011-12-27 11:18:46 +08:00
|
|
|
#include <vector>
|
2016-04-21 14:00:54 +08:00
|
|
|
#include <stdbool.h>
|
2005-10-04 23:11:39 +08:00
|
|
|
|
2011-12-27 11:18:46 +08:00
|
|
|
#include "common.h"
|
2005-10-04 23:11:39 +08:00
|
|
|
|
2005-10-08 19:20:51 +08:00
|
|
|
/**
|
|
|
|
pipe redirection error message
|
|
|
|
*/
|
2006-01-04 20:51:02 +08:00
|
|
|
#define PIPE_ERROR _(L"An error occurred while setting up pipe")
|
2005-10-08 19:20:51 +08:00
|
|
|
|
2005-09-20 21:26:39 +08:00
|
|
|
/**
|
2012-11-18 18:23:22 +08:00
|
|
|
Execute the processes specified by j.
|
2005-09-20 21:26:39 +08: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.
|
|
|
|
|
2013-01-24 19:17:55 +08:00
|
|
|
This rule is short circuited in the case where a builtin does not
|
2005-09-20 21:26:39 +08:00
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
2015-07-25 23:14:25 +08:00
|
|
|
class job_t;
|
2012-01-23 12:47:13 +08:00
|
|
|
class parser_t;
|
Big fat refactoring of how redirections work. In fish 1.x and 2.0.0, the redirections for a process were flattened into a big list associated with the job, so there was no way to tell which redirections applied to each process. Each process therefore got all the redirections associated with the job. See https://github.com/fish-shell/fish-shell/issues/877 for how this could manifest.
With this change, jobs only track their block-level redirections. Process level redirections are correctly associated with the process, and at exec time we stitch them together (block, pipe, and process redirects).
This fixes the weird issues where redirects bleed across pipelines (like #877), and also allows us to play with the order in which redirections are applied, since the final list is constructed right before it's needed. This lets us put pipes after block level redirections but before process level redirections, so that a 2>&1-type redirection gets picked up after the pipe, i.e. it should fix https://github.com/fish-shell/fish-shell/issues/110
This is a significant change. The tests all pass. Cross your fingers.
2013-08-20 07:16:41 +08:00
|
|
|
void exec_job(parser_t &parser, job_t *j);
|
2005-09-20 21:26:39 +08: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 15:35:41 +08:00
|
|
|
\param outputs The list to insert output into.
|
2005-09-20 21:26:39 +08:00
|
|
|
|
|
|
|
\return the status of the last job to exit, or -1 if en error was encountered.
|
|
|
|
*/
|
2013-02-06 08:11:46 +08:00
|
|
|
int exec_subshell(const wcstring &cmd, std::vector<wcstring> &outputs, bool preserve_exit_status);
|
|
|
|
int exec_subshell(const wcstring &cmd, bool preserve_exit_status);
|
2011-12-27 11:18:46 +08:00
|
|
|
|
2005-09-20 22:51:00 +08:00
|
|
|
|
2005-10-03 21:24:46 +08:00
|
|
|
/**
|
2012-03-09 15:21:07 +08:00
|
|
|
Loops over close until the syscall was run without being
|
2015-01-08 10:07:06 +08:00
|
|
|
interrupted.
|
2005-10-03 21:24:46 +08:00
|
|
|
*/
|
2012-11-19 08:30:30 +08:00
|
|
|
void exec_close(int fd);
|
2005-09-20 21:26:39 +08:00
|
|
|
|
2005-10-03 21:24:46 +08:00
|
|
|
/**
|
2015-01-08 10:07:06 +08:00
|
|
|
Call pipe(), and add resulting fds to open_fds, the list of opened
|
|
|
|
file descriptors for pipes. The pipes are marked CLO_EXEC.
|
2005-10-03 21:24:46 +08:00
|
|
|
*/
|
2012-11-19 08:30:30 +08:00
|
|
|
int exec_pipe(int fd[2]);
|
2005-10-04 23:11:39 +08:00
|
|
|
|
2012-08-15 15:57:56 +08:00
|
|
|
/** Gets the interpreter for a given command */
|
2012-11-19 08:30:30 +08:00
|
|
|
char *get_interpreter(const char *command, char *interpreter, size_t buff_size);
|
2012-02-29 07:11:46 +08:00
|
|
|
|
2005-10-04 23:11:39 +08:00
|
|
|
#endif
|