Fix fg bug

-Erik
This commit is contained in:
Erik Andersen 2000-03-16 08:12:48 +00:00
parent 13456d1fcd
commit 161220c498
3 changed files with 1983 additions and 1965 deletions

18
lash.c
View File

@ -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";

18
sh.c
View File

@ -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";

View File

@ -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";