diff options
author | Ron Yorston <rmy@pobox.com> | 2021-09-26 08:50:00 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2021-09-26 08:50:00 +0100 |
commit | 1403d81c4ad4531187644005fa73789d0f7cb606 (patch) | |
tree | f42f4d5b80a0194e000501419c80ced811695e22 /shell | |
parent | 010abea6f548a367d0d89998aa6c38a45d756c0d (diff) | |
download | busybox-w32-1403d81c4ad4531187644005fa73789d0f7cb606.tar.gz busybox-w32-1403d81c4ad4531187644005fa73789d0f7cb606.tar.bz2 busybox-w32-1403d81c4ad4531187644005fa73789d0f7cb606.zip |
ash: associate command names with jobs
Reporting of background jobs is more useful if the commands
associated with the jobs are displayed.
Also, allow the kill builtin to kill jobs by matching their
command names. This was previously disabled by commit f67224cb2
(ash: restrict valid job ids).
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ash.c | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/shell/ash.c b/shell/ash.c index 6be99864f..9f60b4350 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -421,7 +421,7 @@ static void forkshell_init(const char *idstr); | |||
421 | static void *sticky_mem_start, *sticky_mem_end; | 421 | static void *sticky_mem_start, *sticky_mem_end; |
422 | static void sticky_free(void *p); | 422 | static void sticky_free(void *p); |
423 | # define free(p) sticky_free(p) | 423 | # define free(p) sticky_free(p) |
424 | #if !JOBS | 424 | #if !JOBS && !JOBS_WIN32 |
425 | #define spawn_forkshell(fs, jp, n, mode) spawn_forkshell(fs, jp, mode) | 425 | #define spawn_forkshell(fs, jp, n, mode) spawn_forkshell(fs, jp, mode) |
426 | #endif | 426 | #endif |
427 | static void spawn_forkshell(struct forkshell *fs, struct job *jp, | 427 | static void spawn_forkshell(struct forkshell *fs, struct job *jp, |
@@ -4086,9 +4086,10 @@ unaliascmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
4086 | struct procstat { | 4086 | struct procstat { |
4087 | pid_t ps_pid; /* process id */ | 4087 | pid_t ps_pid; /* process id */ |
4088 | int ps_status; /* last process status from wait() */ | 4088 | int ps_status; /* last process status from wait() */ |
4089 | #if !ENABLE_PLATFORM_MINGW32 | 4089 | #if ENABLE_PLATFORM_POSIX || JOBS_WIN32 |
4090 | char *ps_cmd; /* text of command being run */ | 4090 | char *ps_cmd; /* text of command being run */ |
4091 | #else | 4091 | #endif |
4092 | #if ENABLE_PLATFORM_MINGW32 | ||
4092 | HANDLE ps_proc; | 4093 | HANDLE ps_proc; |
4093 | #endif | 4094 | #endif |
4094 | }; | 4095 | }; |
@@ -4435,14 +4436,14 @@ static struct job * | |||
4435 | getjob(const char *name, int getctl) | 4436 | getjob(const char *name, int getctl) |
4436 | { | 4437 | { |
4437 | struct job *jp; | 4438 | struct job *jp; |
4438 | #if !ENABLE_PLATFORM_MINGW32 | 4439 | #if ENABLE_PLATFORM_POSIX || JOBS_WIN32 |
4439 | struct job *found; | 4440 | struct job *found; |
4440 | #endif | 4441 | #endif |
4441 | const char *err_msg = "%s: no such job"; | 4442 | const char *err_msg = "%s: no such job"; |
4442 | unsigned num; | 4443 | unsigned num; |
4443 | int c; | 4444 | int c; |
4444 | const char *p; | 4445 | const char *p; |
4445 | #if !ENABLE_PLATFORM_MINGW32 | 4446 | #if ENABLE_PLATFORM_POSIX || JOBS_WIN32 |
4446 | char *(*match)(const char *, const char *); | 4447 | char *(*match)(const char *, const char *); |
4447 | #endif | 4448 | #endif |
4448 | 4449 | ||
@@ -4485,7 +4486,7 @@ getjob(const char *name, int getctl) | |||
4485 | } | 4486 | } |
4486 | } | 4487 | } |
4487 | 4488 | ||
4488 | #if !ENABLE_PLATFORM_MINGW32 | 4489 | #if ENABLE_PLATFORM_POSIX || JOBS_WIN32 |
4489 | match = prefix; | 4490 | match = prefix; |
4490 | if (*p == '?') { | 4491 | if (*p == '?') { |
4491 | match = strstr; | 4492 | match = strstr; |
@@ -4526,13 +4527,13 @@ getjob(const char *name, int getctl) | |||
4526 | static void | 4527 | static void |
4527 | freejob(struct job *jp) | 4528 | freejob(struct job *jp) |
4528 | { | 4529 | { |
4529 | #if !ENABLE_PLATFORM_MINGW32 | 4530 | #if ENABLE_PLATFORM_POSIX || JOBS_WIN32 |
4530 | struct procstat *ps; | 4531 | struct procstat *ps; |
4531 | int i; | 4532 | int i; |
4532 | #endif | 4533 | #endif |
4533 | 4534 | ||
4534 | INT_OFF; | 4535 | INT_OFF; |
4535 | #if !ENABLE_PLATFORM_MINGW32 | 4536 | #if ENABLE_PLATFORM_POSIX || JOBS_WIN32 |
4536 | for (i = jp->nprocs, ps = jp->ps; --i >= 0; ps++) { | 4537 | for (i = jp->nprocs, ps = jp->ps; --i >= 0; ps++) { |
4537 | if (ps->ps_cmd != nullstr) | 4538 | if (ps->ps_cmd != nullstr) |
4538 | free(ps->ps_cmd); | 4539 | free(ps->ps_cmd); |
@@ -5132,7 +5133,7 @@ showjob(struct job *jp, int mode) | |||
5132 | if (mode & SHOW_PIDS) | 5133 | if (mode & SHOW_PIDS) |
5133 | col = fmtstr(s, 48, "\n%*c%d ", indent_col, ' ', ps->ps_pid) - 1; | 5134 | col = fmtstr(s, 48, "\n%*c%d ", indent_col, ' ', ps->ps_pid) - 1; |
5134 | start: | 5135 | start: |
5135 | #if !ENABLE_PLATFORM_MINGW32 | 5136 | #if ENABLE_PLATFORM_POSIX || JOBS_WIN32 |
5136 | fprintf(out, "%s%*c%s%s", | 5137 | fprintf(out, "%s%*c%s%s", |
5137 | s, | 5138 | s, |
5138 | 33 - col >= 0 ? 33 - col : 0, ' ', | 5139 | 33 - col >= 0 ? 33 - col : 0, ' ', |
@@ -5424,7 +5425,7 @@ makejob(/*union node *node,*/ int nprocs) | |||
5424 | return jp; | 5425 | return jp; |
5425 | } | 5426 | } |
5426 | 5427 | ||
5427 | #if JOBS | 5428 | #if JOBS || JOBS_WIN32 |
5428 | /* | 5429 | /* |
5429 | * Return a string identifying a command (to be printed by the | 5430 | * Return a string identifying a command (to be printed by the |
5430 | * jobs command). | 5431 | * jobs command). |
@@ -5895,7 +5896,7 @@ forkchild(struct job *jp, union node *n, int mode) | |||
5895 | #endif | 5896 | #endif |
5896 | 5897 | ||
5897 | /* Called after fork(), in parent */ | 5898 | /* Called after fork(), in parent */ |
5898 | #if !JOBS | 5899 | #if !JOBS && !JOBS_WIN32 |
5899 | #define forkparent(jp, n, mode, pid) forkparent(jp, mode, pid) | 5900 | #define forkparent(jp, n, mode, pid) forkparent(jp, mode, pid) |
5900 | #endif | 5901 | #endif |
5901 | static void | 5902 | static void |
@@ -5931,12 +5932,13 @@ forkparent(struct job *jp, union node *n, int mode, HANDLE proc) | |||
5931 | struct procstat *ps = &jp->ps[jp->nprocs++]; | 5932 | struct procstat *ps = &jp->ps[jp->nprocs++]; |
5932 | ps->ps_pid = pid; | 5933 | ps->ps_pid = pid; |
5933 | ps->ps_status = -1; | 5934 | ps->ps_status = -1; |
5934 | #if !ENABLE_PLATFORM_MINGW32 | 5935 | #if ENABLE_PLATFORM_POSIX || JOBS_WIN32 |
5935 | ps->ps_cmd = nullstr; | 5936 | ps->ps_cmd = nullstr; |
5936 | #else | 5937 | #endif |
5938 | #if ENABLE_PLATFORM_MINGW32 | ||
5937 | ps->ps_proc = proc; | 5939 | ps->ps_proc = proc; |
5938 | #endif | 5940 | #endif |
5939 | #if JOBS | 5941 | #if JOBS || JOBS_WIN32 |
5940 | if (doing_jobctl && n) | 5942 | if (doing_jobctl && n) |
5941 | ps->ps_cmd = commandtext(n); | 5943 | ps->ps_cmd = commandtext(n); |
5942 | #endif | 5944 | #endif |