Support disabling pipe and redirect support
This commit is contained in:
parent
a0e4c3f119
commit
ff9ad47d79
49
shell/lash.c
49
shell/lash.c
@ -56,14 +56,18 @@
|
|||||||
#include <glob.h>
|
#include <glob.h>
|
||||||
#define expand_t glob_t
|
#define expand_t glob_t
|
||||||
|
|
||||||
|
/* Always enable for the moment... */
|
||||||
|
#define CONFIG_LASH_PIPE_N_REDIRECTS
|
||||||
|
|
||||||
static const int MAX_READ = 128; /* size of input buffer for `read' builtin */
|
static const int MAX_READ = 128; /* size of input buffer for `read' builtin */
|
||||||
#define JOB_STATUS_FORMAT "[%d] %-22s %.40s\n"
|
#define JOB_STATUS_FORMAT "[%d] %-22s %.40s\n"
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef CONFIG_LASH_PIPE_N_REDIRECTS
|
||||||
enum redir_type { REDIRECT_INPUT, REDIRECT_OVERWRITE,
|
enum redir_type { REDIRECT_INPUT, REDIRECT_OVERWRITE,
|
||||||
REDIRECT_APPEND
|
REDIRECT_APPEND
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
static const unsigned int DEFAULT_CONTEXT=0x1;
|
static const unsigned int DEFAULT_CONTEXT=0x1;
|
||||||
static const unsigned int IF_TRUE_CONTEXT=0x2;
|
static const unsigned int IF_TRUE_CONTEXT=0x2;
|
||||||
@ -71,25 +75,28 @@ static const unsigned int IF_FALSE_CONTEXT=0x4;
|
|||||||
static const unsigned int THEN_EXP_CONTEXT=0x8;
|
static const unsigned int THEN_EXP_CONTEXT=0x8;
|
||||||
static const unsigned int ELSE_EXP_CONTEXT=0x10;
|
static const unsigned int ELSE_EXP_CONTEXT=0x10;
|
||||||
|
|
||||||
|
#ifdef CONFIG_LASH_PIPE_N_REDIRECTS
|
||||||
struct jobset {
|
|
||||||
struct job *head; /* head of list of running jobs */
|
|
||||||
struct job *fg; /* current foreground job */
|
|
||||||
};
|
|
||||||
|
|
||||||
struct redir_struct {
|
struct redir_struct {
|
||||||
enum redir_type type; /* type of redirection */
|
enum redir_type type; /* type of redirection */
|
||||||
int fd; /* file descriptor being redirected */
|
int fd; /* file descriptor being redirected */
|
||||||
char *filename; /* file to redirect fd to */
|
char *filename; /* file to redirect fd to */
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
struct child_prog {
|
struct child_prog {
|
||||||
pid_t pid; /* 0 if exited */
|
pid_t pid; /* 0 if exited */
|
||||||
char **argv; /* program name and arguments */
|
char **argv; /* program name and arguments */
|
||||||
int num_redirects; /* elements in redirection array */
|
int num_redirects; /* elements in redirection array */
|
||||||
struct redir_struct *redirects; /* I/O redirects */
|
|
||||||
int is_stopped; /* is the program currently running? */
|
int is_stopped; /* is the program currently running? */
|
||||||
struct job *family; /* pointer back to the child's parent job */
|
struct job *family; /* pointer back to the child's parent job */
|
||||||
|
#ifdef CONFIG_LASH_PIPE_N_REDIRECTS
|
||||||
|
struct redir_struct *redirects; /* I/O redirects */
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
struct jobset {
|
||||||
|
struct job *head; /* head of list of running jobs */
|
||||||
|
struct job *fg; /* current foreground job */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct job {
|
struct job {
|
||||||
@ -514,8 +521,10 @@ static void free_job(struct job *cmd)
|
|||||||
|
|
||||||
for (i = 0; i < cmd->num_progs; i++) {
|
for (i = 0; i < cmd->num_progs; i++) {
|
||||||
free(cmd->progs[i].argv);
|
free(cmd->progs[i].argv);
|
||||||
|
#ifdef CONFIG_LASH_PIPE_N_REDIRECTS
|
||||||
if (cmd->progs[i].redirects)
|
if (cmd->progs[i].redirects)
|
||||||
free(cmd->progs[i].redirects);
|
free(cmd->progs[i].redirects);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
free(cmd->progs);
|
free(cmd->progs);
|
||||||
free(cmd->text);
|
free(cmd->text);
|
||||||
@ -601,6 +610,7 @@ static void checkjobs(struct jobset *j_list)
|
|||||||
bb_perror_msg("waitpid");
|
bb_perror_msg("waitpid");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef CONFIG_LASH_PIPE_N_REDIRECTS
|
||||||
/* squirrel != NULL means we squirrel away copies of stdin, stdout,
|
/* squirrel != NULL means we squirrel away copies of stdin, stdout,
|
||||||
* and stderr if they are redirected. */
|
* and stderr if they are redirected. */
|
||||||
static int setup_redirects(struct child_prog *prog, int squirrel[])
|
static int setup_redirects(struct child_prog *prog, int squirrel[])
|
||||||
@ -656,6 +666,15 @@ static void restore_redirects(int squirrel[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
static inline int setup_redirects(struct child_prog *prog, int squirrel[])
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
static inline void restore_redirects(int squirrel[])
|
||||||
|
{
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static inline void cmdedit_set_initial_prompt(void)
|
static inline void cmdedit_set_initial_prompt(void)
|
||||||
{
|
{
|
||||||
@ -953,14 +972,18 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg)
|
|||||||
{
|
{
|
||||||
char *command;
|
char *command;
|
||||||
char *return_command = NULL;
|
char *return_command = NULL;
|
||||||
char *src, *buf, *chptr;
|
char *src, *buf;
|
||||||
int argc_l = 0;
|
int argc_l = 0;
|
||||||
int done = 0;
|
int done = 0;
|
||||||
int argv_alloced;
|
int argv_alloced;
|
||||||
int i, saw_quote = 0;
|
int saw_quote = 0;
|
||||||
char quote = '\0';
|
char quote = '\0';
|
||||||
int count;
|
int count;
|
||||||
struct child_prog *prog;
|
struct child_prog *prog;
|
||||||
|
#ifdef CONFIG_LASH_PIPE_N_REDIRECTS
|
||||||
|
int i;
|
||||||
|
char *chptr;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* skip leading white space */
|
/* skip leading white space */
|
||||||
while (**command_ptr && isspace(**command_ptr))
|
while (**command_ptr && isspace(**command_ptr))
|
||||||
@ -988,9 +1011,11 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg)
|
|||||||
|
|
||||||
prog = job->progs;
|
prog = job->progs;
|
||||||
prog->num_redirects = 0;
|
prog->num_redirects = 0;
|
||||||
prog->redirects = NULL;
|
|
||||||
prog->is_stopped = 0;
|
prog->is_stopped = 0;
|
||||||
prog->family = job;
|
prog->family = job;
|
||||||
|
#ifdef CONFIG_LASH_PIPE_N_REDIRECTS
|
||||||
|
prog->redirects = NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
argv_alloced = 5;
|
argv_alloced = 5;
|
||||||
prog->argv = xmalloc(sizeof(*prog->argv) * argv_alloced);
|
prog->argv = xmalloc(sizeof(*prog->argv) * argv_alloced);
|
||||||
@ -1046,6 +1071,7 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg)
|
|||||||
done = 1;
|
done = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
#ifdef CONFIG_LASH_PIPE_N_REDIRECTS
|
||||||
case '>': /* redirects */
|
case '>': /* redirects */
|
||||||
case '<':
|
case '<':
|
||||||
i = prog->num_redirects++;
|
i = prog->num_redirects++;
|
||||||
@ -1143,6 +1169,7 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg)
|
|||||||
src--; /* we'll ++ it at the end of the loop */
|
src--; /* we'll ++ it at the end of the loop */
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
case '&': /* background */
|
case '&': /* background */
|
||||||
*inbg = 1;
|
*inbg = 1;
|
||||||
@ -1336,8 +1363,8 @@ static int run_command(struct job *newjob, int inbg, int outpipe[2])
|
|||||||
if (newjob->num_progs == 1) {
|
if (newjob->num_progs == 1) {
|
||||||
for (x = bltins; x->cmd; x++) {
|
for (x = bltins; x->cmd; x++) {
|
||||||
if (strcmp(child->argv[0], x->cmd) == 0 ) {
|
if (strcmp(child->argv[0], x->cmd) == 0 ) {
|
||||||
int squirrel[] = {-1, -1, -1};
|
|
||||||
int rcode;
|
int rcode;
|
||||||
|
int squirrel[] = {-1, -1, -1};
|
||||||
setup_redirects(child, squirrel);
|
setup_redirects(child, squirrel);
|
||||||
rcode = x->function(child);
|
rcode = x->function(child);
|
||||||
restore_redirects(squirrel);
|
restore_redirects(squirrel);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user