Fix fg bug
-Erik
This commit is contained in:
parent
13456d1fcd
commit
161220c498
22
lash.c
22
lash.c
@ -47,7 +47,8 @@
|
||||
|
||||
|
||||
enum redirectionType { REDIRECT_INPUT, REDIRECT_OVERWRITE,
|
||||
REDIRECT_APPEND };
|
||||
REDIRECT_APPEND
|
||||
};
|
||||
|
||||
struct jobSet {
|
||||
struct job *head; /* head of list of running jobs */
|
||||
@ -121,6 +122,7 @@ static struct builtInCommand bltins[] = {
|
||||
{"pwd", "Print current directory", "pwd", shell_pwd},
|
||||
{"set", "Set environment variable", "set [VAR=value]", shell_set},
|
||||
{"unset", "Unset environment variable", "unset VAR", shell_unset},
|
||||
|
||||
{".", "Source-in and run commands in a file", ". filename",
|
||||
shell_source},
|
||||
{"help", "List shell built-in commands", "help", shell_help},
|
||||
@ -128,6 +130,7 @@ static struct builtInCommand bltins[] = {
|
||||
};
|
||||
|
||||
static const char shell_usage[] =
|
||||
|
||||
"sh [FILE]...\n\n" "The BusyBox command interpreter (shell).\n\n";
|
||||
|
||||
|
||||
@ -140,6 +143,7 @@ static char *prompt = "# ";
|
||||
static int shell_cd(struct job *cmd, struct jobSet *junk)
|
||||
{
|
||||
char *newdir;
|
||||
|
||||
if (!cmd->progs[0].argv[1] == 1)
|
||||
newdir = getenv("HOME");
|
||||
else
|
||||
@ -169,6 +173,7 @@ static int shell_exit(struct job *cmd, struct jobSet *junk)
|
||||
{
|
||||
if (!cmd->progs[0].argv[1] == 1)
|
||||
exit TRUE;
|
||||
|
||||
else
|
||||
exit(atoi(cmd->progs[0].argv[1]));
|
||||
}
|
||||
@ -189,15 +194,16 @@ static int shell_fg_bg(struct job *cmd, struct jobSet *jobList)
|
||||
fprintf(stderr, "%s: bad argument '%s'\n",
|
||||
cmd->progs[0].argv[0], cmd->progs[0].argv[1]);
|
||||
return FALSE;
|
||||
for (job = jobList->head; job; job = job->next) {
|
||||
if (job->jobId == jobNum) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
job = jobList->head;
|
||||
}
|
||||
|
||||
for (job = jobList->head; job; job = job->next)
|
||||
if (job->jobId == jobNum)
|
||||
break;
|
||||
|
||||
if (!job) {
|
||||
fprintf(stderr, "%s: unknown job %d\n",
|
||||
cmd->progs[0].argv[0], jobNum);
|
||||
@ -206,7 +212,6 @@ static int shell_fg_bg(struct job *cmd, struct jobSet *jobList)
|
||||
|
||||
if (*cmd->progs[0].argv[0] == 'f') {
|
||||
/* Make this job the foreground job */
|
||||
|
||||
if (tcsetpgrp(0, job->pgrp))
|
||||
perror("tcsetpgrp");
|
||||
jobList->fg = job;
|
||||
@ -242,6 +247,7 @@ static int shell_jobs(struct job *dummy, struct jobSet *jobList)
|
||||
{
|
||||
struct job *job;
|
||||
char *statusString;
|
||||
|
||||
for (job = jobList->head; job; job = job->next) {
|
||||
if (job->runningProgs == job->stoppedProgs)
|
||||
statusString = "Stopped";
|
||||
@ -848,7 +854,7 @@ static int busy_loop(FILE * input)
|
||||
int status;
|
||||
int inBg;
|
||||
|
||||
command = (char*) calloc(BUFSIZ, sizeof(char));
|
||||
command = (char *) calloc(BUFSIZ, sizeof(char));
|
||||
|
||||
/* don't pay any attention to this signal; it just confuses
|
||||
things and isn't really meant for shells anyway */
|
||||
@ -913,7 +919,7 @@ static int busy_loop(FILE * input)
|
||||
}
|
||||
}
|
||||
}
|
||||
free( command);
|
||||
free(command);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
22
sh.c
22
sh.c
@ -47,7 +47,8 @@
|
||||
|
||||
|
||||
enum redirectionType { REDIRECT_INPUT, REDIRECT_OVERWRITE,
|
||||
REDIRECT_APPEND };
|
||||
REDIRECT_APPEND
|
||||
};
|
||||
|
||||
struct jobSet {
|
||||
struct job *head; /* head of list of running jobs */
|
||||
@ -121,6 +122,7 @@ static struct builtInCommand bltins[] = {
|
||||
{"pwd", "Print current directory", "pwd", shell_pwd},
|
||||
{"set", "Set environment variable", "set [VAR=value]", shell_set},
|
||||
{"unset", "Unset environment variable", "unset VAR", shell_unset},
|
||||
|
||||
{".", "Source-in and run commands in a file", ". filename",
|
||||
shell_source},
|
||||
{"help", "List shell built-in commands", "help", shell_help},
|
||||
@ -128,6 +130,7 @@ static struct builtInCommand bltins[] = {
|
||||
};
|
||||
|
||||
static const char shell_usage[] =
|
||||
|
||||
"sh [FILE]...\n\n" "The BusyBox command interpreter (shell).\n\n";
|
||||
|
||||
|
||||
@ -140,6 +143,7 @@ static char *prompt = "# ";
|
||||
static int shell_cd(struct job *cmd, struct jobSet *junk)
|
||||
{
|
||||
char *newdir;
|
||||
|
||||
if (!cmd->progs[0].argv[1] == 1)
|
||||
newdir = getenv("HOME");
|
||||
else
|
||||
@ -169,6 +173,7 @@ static int shell_exit(struct job *cmd, struct jobSet *junk)
|
||||
{
|
||||
if (!cmd->progs[0].argv[1] == 1)
|
||||
exit TRUE;
|
||||
|
||||
else
|
||||
exit(atoi(cmd->progs[0].argv[1]));
|
||||
}
|
||||
@ -189,15 +194,16 @@ static int shell_fg_bg(struct job *cmd, struct jobSet *jobList)
|
||||
fprintf(stderr, "%s: bad argument '%s'\n",
|
||||
cmd->progs[0].argv[0], cmd->progs[0].argv[1]);
|
||||
return FALSE;
|
||||
for (job = jobList->head; job; job = job->next) {
|
||||
if (job->jobId == jobNum) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
job = jobList->head;
|
||||
}
|
||||
|
||||
for (job = jobList->head; job; job = job->next)
|
||||
if (job->jobId == jobNum)
|
||||
break;
|
||||
|
||||
if (!job) {
|
||||
fprintf(stderr, "%s: unknown job %d\n",
|
||||
cmd->progs[0].argv[0], jobNum);
|
||||
@ -206,7 +212,6 @@ static int shell_fg_bg(struct job *cmd, struct jobSet *jobList)
|
||||
|
||||
if (*cmd->progs[0].argv[0] == 'f') {
|
||||
/* Make this job the foreground job */
|
||||
|
||||
if (tcsetpgrp(0, job->pgrp))
|
||||
perror("tcsetpgrp");
|
||||
jobList->fg = job;
|
||||
@ -242,6 +247,7 @@ static int shell_jobs(struct job *dummy, struct jobSet *jobList)
|
||||
{
|
||||
struct job *job;
|
||||
char *statusString;
|
||||
|
||||
for (job = jobList->head; job; job = job->next) {
|
||||
if (job->runningProgs == job->stoppedProgs)
|
||||
statusString = "Stopped";
|
||||
@ -848,7 +854,7 @@ static int busy_loop(FILE * input)
|
||||
int status;
|
||||
int inBg;
|
||||
|
||||
command = (char*) calloc(BUFSIZ, sizeof(char));
|
||||
command = (char *) calloc(BUFSIZ, sizeof(char));
|
||||
|
||||
/* don't pay any attention to this signal; it just confuses
|
||||
things and isn't really meant for shells anyway */
|
||||
@ -913,7 +919,7 @@ static int busy_loop(FILE * input)
|
||||
}
|
||||
}
|
||||
}
|
||||
free( command);
|
||||
free(command);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
22
shell/lash.c
22
shell/lash.c
@ -47,7 +47,8 @@
|
||||
|
||||
|
||||
enum redirectionType { REDIRECT_INPUT, REDIRECT_OVERWRITE,
|
||||
REDIRECT_APPEND };
|
||||
REDIRECT_APPEND
|
||||
};
|
||||
|
||||
struct jobSet {
|
||||
struct job *head; /* head of list of running jobs */
|
||||
@ -121,6 +122,7 @@ static struct builtInCommand bltins[] = {
|
||||
{"pwd", "Print current directory", "pwd", shell_pwd},
|
||||
{"set", "Set environment variable", "set [VAR=value]", shell_set},
|
||||
{"unset", "Unset environment variable", "unset VAR", shell_unset},
|
||||
|
||||
{".", "Source-in and run commands in a file", ". filename",
|
||||
shell_source},
|
||||
{"help", "List shell built-in commands", "help", shell_help},
|
||||
@ -128,6 +130,7 @@ static struct builtInCommand bltins[] = {
|
||||
};
|
||||
|
||||
static const char shell_usage[] =
|
||||
|
||||
"sh [FILE]...\n\n" "The BusyBox command interpreter (shell).\n\n";
|
||||
|
||||
|
||||
@ -140,6 +143,7 @@ static char *prompt = "# ";
|
||||
static int shell_cd(struct job *cmd, struct jobSet *junk)
|
||||
{
|
||||
char *newdir;
|
||||
|
||||
if (!cmd->progs[0].argv[1] == 1)
|
||||
newdir = getenv("HOME");
|
||||
else
|
||||
@ -169,6 +173,7 @@ static int shell_exit(struct job *cmd, struct jobSet *junk)
|
||||
{
|
||||
if (!cmd->progs[0].argv[1] == 1)
|
||||
exit TRUE;
|
||||
|
||||
else
|
||||
exit(atoi(cmd->progs[0].argv[1]));
|
||||
}
|
||||
@ -189,15 +194,16 @@ static int shell_fg_bg(struct job *cmd, struct jobSet *jobList)
|
||||
fprintf(stderr, "%s: bad argument '%s'\n",
|
||||
cmd->progs[0].argv[0], cmd->progs[0].argv[1]);
|
||||
return FALSE;
|
||||
for (job = jobList->head; job; job = job->next) {
|
||||
if (job->jobId == jobNum) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
job = jobList->head;
|
||||
}
|
||||
|
||||
for (job = jobList->head; job; job = job->next)
|
||||
if (job->jobId == jobNum)
|
||||
break;
|
||||
|
||||
if (!job) {
|
||||
fprintf(stderr, "%s: unknown job %d\n",
|
||||
cmd->progs[0].argv[0], jobNum);
|
||||
@ -206,7 +212,6 @@ static int shell_fg_bg(struct job *cmd, struct jobSet *jobList)
|
||||
|
||||
if (*cmd->progs[0].argv[0] == 'f') {
|
||||
/* Make this job the foreground job */
|
||||
|
||||
if (tcsetpgrp(0, job->pgrp))
|
||||
perror("tcsetpgrp");
|
||||
jobList->fg = job;
|
||||
@ -242,6 +247,7 @@ static int shell_jobs(struct job *dummy, struct jobSet *jobList)
|
||||
{
|
||||
struct job *job;
|
||||
char *statusString;
|
||||
|
||||
for (job = jobList->head; job; job = job->next) {
|
||||
if (job->runningProgs == job->stoppedProgs)
|
||||
statusString = "Stopped";
|
||||
@ -848,7 +854,7 @@ static int busy_loop(FILE * input)
|
||||
int status;
|
||||
int inBg;
|
||||
|
||||
command = (char*) calloc(BUFSIZ, sizeof(char));
|
||||
command = (char *) calloc(BUFSIZ, sizeof(char));
|
||||
|
||||
/* don't pay any attention to this signal; it just confuses
|
||||
things and isn't really meant for shells anyway */
|
||||
@ -913,7 +919,7 @@ static int busy_loop(FILE * input)
|
||||
}
|
||||
}
|
||||
}
|
||||
free( command);
|
||||
free(command);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user