mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-17 02:41:15 -03:00
Fix up --on-job-exit caller
The `function --on-job-exit caller` feature allows a command substitution to observe when the parent job exits. This has never worked very well - in particular it is based on job IDs, so a function that observes this will run multiple times. Implement it properly. Do this by having a not-recycled "internal job id". This is only used by psub, but ensure it works properly none-the-less.
This commit is contained in:
@@ -103,17 +103,15 @@ static int parse_cmd_opts(function_cmd_opts_t &opts, int *optind, //!OCLINT(hig
|
||||
event_description_t e(event_type_t::any);
|
||||
|
||||
if ((opt == 'j') && (wcscasecmp(w.woptarg, L"caller") == 0)) {
|
||||
job_id_t job_id = -1;
|
||||
if (parser.libdata().is_subshell) {
|
||||
job_id = parser.libdata().caller_job_id;
|
||||
}
|
||||
if (job_id == -1) {
|
||||
internal_job_id_t caller_id =
|
||||
parser.libdata().is_subshell ? parser.libdata().caller_id : 0;
|
||||
if (caller_id == 0) {
|
||||
streams.err.append_format(
|
||||
_(L"%ls: Cannot find calling job for event handler"), cmd);
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
e.type = event_type_t::caller_exit;
|
||||
e.param1.job_id = job_id;
|
||||
e.param1.caller_id = caller_id;
|
||||
} else if ((opt == 'p') && (wcscasecmp(w.woptarg, L"%self") == 0)) {
|
||||
e.type = event_type_t::exit;
|
||||
e.param1.pid = getpid();
|
||||
|
||||
Reference in New Issue
Block a user