diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-08-23 22:10:04 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-08-23 22:10:04 +0200 |
commit | a12af2d9f384c7c80dbe419dceab666d53f4642d (patch) | |
tree | c759b773d2f5039baed40fc233b63099386deefb /shell/ash.c | |
parent | bd73f1d85ac180ff30d5198d37d49b33033e44a8 (diff) | |
download | busybox-w32-a12af2d9f384c7c80dbe419dceab666d53f4642d.tar.gz busybox-w32-a12af2d9f384c7c80dbe419dceab666d53f4642d.tar.bz2 busybox-w32-a12af2d9f384c7c80dbe419dceab666d53f4642d.zip |
ash: make "jobs -l" more similar to bash. By Earl Chew. Fixes bug 481
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/ash.c')
-rw-r--r-- | shell/ash.c | 56 |
1 files changed, 31 insertions, 25 deletions
diff --git a/shell/ash.c b/shell/ash.c index 077f5e5fc..1ec6c96c3 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -3240,9 +3240,9 @@ unaliascmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
3240 | #define FORK_NOJOB 2 | 3240 | #define FORK_NOJOB 2 |
3241 | 3241 | ||
3242 | /* mode flags for showjob(s) */ | 3242 | /* mode flags for showjob(s) */ |
3243 | #define SHOW_PGID 0x01 /* only show pgid - for jobs -p */ | 3243 | #define SHOW_ONLY_PGID 0x01 /* show only pgid (jobs -p) */ |
3244 | #define SHOW_PID 0x04 /* include process pid */ | 3244 | #define SHOW_PIDS 0x02 /* show individual pids, not just one line per job */ |
3245 | #define SHOW_CHANGED 0x08 /* only jobs whose state has changed */ | 3245 | #define SHOW_CHANGED 0x04 /* only jobs whose state has changed */ |
3246 | 3246 | ||
3247 | /* | 3247 | /* |
3248 | * A job structure contains information about a job. A job is either a | 3248 | * A job structure contains information about a job. A job is either a |
@@ -3250,7 +3250,6 @@ unaliascmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
3250 | * latter case, pidlist will be non-NULL, and will point to a -1 terminated | 3250 | * latter case, pidlist will be non-NULL, and will point to a -1 terminated |
3251 | * array of pids. | 3251 | * array of pids. |
3252 | */ | 3252 | */ |
3253 | |||
3254 | struct procstat { | 3253 | struct procstat { |
3255 | pid_t pid; /* process id */ | 3254 | pid_t pid; /* process id */ |
3256 | int status; /* last process status from wait() */ | 3255 | int status; /* last process status from wait() */ |
@@ -3935,7 +3934,7 @@ showjob(FILE *out, struct job *jp, int mode) | |||
3935 | 3934 | ||
3936 | ps = jp->ps; | 3935 | ps = jp->ps; |
3937 | 3936 | ||
3938 | if (mode & SHOW_PGID) { | 3937 | if (mode & SHOW_ONLY_PGID) { /* jobs -p */ |
3939 | /* just output process (group) id of pipeline */ | 3938 | /* just output process (group) id of pipeline */ |
3940 | fprintf(out, "%d\n", ps->pid); | 3939 | fprintf(out, "%d\n", ps->pid); |
3941 | return; | 3940 | return; |
@@ -3945,11 +3944,11 @@ showjob(FILE *out, struct job *jp, int mode) | |||
3945 | indent_col = col; | 3944 | indent_col = col; |
3946 | 3945 | ||
3947 | if (jp == curjob) | 3946 | if (jp == curjob) |
3948 | s[col - 2] = '+'; | 3947 | s[col - 3] = '+'; |
3949 | else if (curjob && jp == curjob->prev_job) | 3948 | else if (curjob && jp == curjob->prev_job) |
3950 | s[col - 2] = '-'; | 3949 | s[col - 3] = '-'; |
3951 | 3950 | ||
3952 | if (mode & SHOW_PID) | 3951 | if (mode & SHOW_PIDS) |
3953 | col += fmtstr(s + col, 16, "%d ", ps->pid); | 3952 | col += fmtstr(s + col, 16, "%d ", ps->pid); |
3954 | 3953 | ||
3955 | psend = ps + jp->nprocs; | 3954 | psend = ps + jp->nprocs; |
@@ -3963,25 +3962,32 @@ showjob(FILE *out, struct job *jp, int mode) | |||
3963 | status = jp->stopstatus; | 3962 | status = jp->stopstatus; |
3964 | col += sprint_status(s + col, status, 0); | 3963 | col += sprint_status(s + col, status, 0); |
3965 | } | 3964 | } |
3965 | /* By now, "[JOBID]* [maybe PID] STATUS" is printed */ | ||
3966 | 3966 | ||
3967 | /* This loop either prints "<cmd1> | <cmd2> | <cmd3>" line | ||
3968 | * or prints several "PID | <cmdN>" lines, | ||
3969 | * depending on SHOW_PIDS bit. | ||
3970 | * We do not print status of individual processes | ||
3971 | * between PID and <cmdN>. bash does it, but not very well: | ||
3972 | * first line shows overall job status, not process status, | ||
3973 | * making it impossible to know 1st process status. | ||
3974 | */ | ||
3967 | goto start; | 3975 | goto start; |
3968 | 3976 | while (1) { | |
3969 | do { | ||
3970 | /* for each process */ | 3977 | /* for each process */ |
3971 | col = fmtstr(s, 48, " |\n%*c%d ", indent_col, ' ', ps->pid) - 3; | 3978 | s[0] = '\0'; |
3979 | col = 33; | ||
3980 | if (mode & SHOW_PIDS) | ||
3981 | col = fmtstr(s, 48, "\n%*c%d ", indent_col, ' ', ps->pid) - 1; | ||
3972 | start: | 3982 | start: |
3973 | fprintf(out, "%s%*c%s", | 3983 | fprintf(out, "%s%*c", s, 33 - col >= 0 ? 33 - col : 0, ' '); |
3974 | s, 33 - col >= 0 ? 33 - col : 0, ' ', ps->cmd | 3984 | if (ps != jp->ps) |
3975 | ); | 3985 | fprintf(out, "| "); |
3976 | if (!(mode & SHOW_PID)) { | 3986 | fprintf(out, "%s", ps->cmd); |
3977 | showpipe(jp, out); | 3987 | if (++ps == psend) |
3978 | break; | 3988 | break; |
3979 | } | 3989 | } |
3980 | if (++ps == psend) { | 3990 | outcslow('\n', out); |
3981 | outcslow('\n', out); | ||
3982 | break; | ||
3983 | } | ||
3984 | } while (1); | ||
3985 | 3991 | ||
3986 | jp->changed = 0; | 3992 | jp->changed = 0; |
3987 | 3993 | ||
@@ -4021,15 +4027,15 @@ jobscmd(int argc UNUSED_PARAM, char **argv) | |||
4021 | mode = 0; | 4027 | mode = 0; |
4022 | while ((m = nextopt("lp"))) { | 4028 | while ((m = nextopt("lp"))) { |
4023 | if (m == 'l') | 4029 | if (m == 'l') |
4024 | mode = SHOW_PID; | 4030 | mode |= SHOW_PIDS; |
4025 | else | 4031 | else |
4026 | mode = SHOW_PGID; | 4032 | mode |= SHOW_ONLY_PGID; |
4027 | } | 4033 | } |
4028 | 4034 | ||
4029 | argv = argptr; | 4035 | argv = argptr; |
4030 | if (*argv) { | 4036 | if (*argv) { |
4031 | do | 4037 | do |
4032 | showjob(stdout, getjob(*argv,0), mode); | 4038 | showjob(stdout, getjob(*argv, 0), mode); |
4033 | while (*++argv); | 4039 | while (*++argv); |
4034 | } else | 4040 | } else |
4035 | showjobs(stdout, mode); | 4041 | showjobs(stdout, mode); |