Rename event_type_t::job_exit to event_type_t::caller_exit

"job_exit" events, despite their name, can only be created via
the '--on-job-exit caller' misfeature of function. Rename it to make it
clear that this event type is specifically for caller-exit.
This commit is contained in:
ridiculousfish 2020-02-08 16:08:26 -08:00
parent 91df645c62
commit 93fc0d06d4
5 changed files with 18 additions and 30 deletions

View File

@ -100,29 +100,25 @@ static int parse_cmd_opts(function_cmd_opts_t &opts, int *optind, //!OCLINT(hig
}
case 'j':
case 'p': {
pid_t pid;
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) {
streams.err.append_format(
_(L"%ls: Cannot find calling job for event handler"), cmd);
return STATUS_INVALID_ARGS;
}
e.type = event_type_t::job_exit;
e.type = event_type_t::caller_exit;
e.param1.job_id = job_id;
} else if ((opt == 'p') && (wcscasecmp(w.woptarg, L"%self") == 0)) {
pid = getpid();
e.type = event_type_t::exit;
e.param1.pid = pid;
e.param1.pid = getpid();
} else {
pid = fish_wcstoi(w.woptarg);
pid_t pid = fish_wcstoi(w.woptarg);
if (errno || pid < 0) {
streams.err.append_format(_(L"%ls: Invalid process id '%ls'"), cmd,
w.woptarg);

View File

@ -130,7 +130,7 @@ static int parse_cmd_opts(functions_cmd_opts_t &opts, int *optind, //!OCLINT(hi
}
/// Return a definition of the specified function. Used by the functions builtin.
static wcstring functions_def(const parser_t &parser, const wcstring &name) {
static wcstring functions_def(const wcstring &name) {
assert(!name.empty() && "Empty name");
wcstring out;
wcstring desc, def;
@ -183,9 +183,8 @@ static wcstring functions_def(const parser_t &parser, const wcstring &name) {
append_format(out, L" --on-job-exit %d", -d.param1.pid);
break;
}
case event_type_t::job_exit: {
const job_t *j = parser.job_get(d.param1.job_id);
if (j) append_format(out, L" --on-job-exit %d", j->pgid);
case event_type_t::caller_exit: {
append_format(out, L" --on-job-exit caller");
break;
}
case event_type_t::generic: {
@ -435,7 +434,7 @@ int builtin_functions(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
if (i != optind) streams.out.append(L"\n");
const wchar_t *funcname = argv[optind];
report_function_metadata(funcname, opts.verbose, streams, parser, true);
wcstring def = functions_def(parser, funcname);
wcstring def = functions_def(funcname);
if (!streams.out_is_redirected && isatty(STDOUT_FILENO)) {
std::vector<highlight_spec_t> colors;

View File

@ -113,7 +113,7 @@ static bool handler_matches(const event_handler_t &classv, const event_t &instan
if (classv.desc.param1.pid == EVENT_ANY_PID) return true;
return classv.desc.param1.pid == instance.desc.param1.pid;
}
case event_type_t::job_exit: {
case event_type_t::caller_exit: {
return classv.desc.param1.job_id == instance.desc.param1.job_id;
}
case event_type_t::generic: {
@ -167,15 +167,8 @@ wcstring event_get_desc(const parser_t &parser, const event_t &evt) {
DIE("Unreachable");
}
case event_type_t::job_exit: {
const job_t *j = parser.job_get(ed.param1.job_id);
if (j) {
return format_string(_(L"exit handler for job %d, '%ls'"), j->job_id(),
j->command_wcstr());
} else {
return format_string(_(L"exit handler for job with job id %d"), ed.param1.job_id);
}
break;
case event_type_t::caller_exit: {
return _(L"exit handler for command substitution caller");
}
case event_type_t::generic: {
@ -349,7 +342,7 @@ struct event_type_name_t {
static const event_type_name_t events_mapping[] = {{event_type_t::signal, L"signal"},
{event_type_t::variable, L"variable"},
{event_type_t::exit, L"exit"},
{event_type_t::job_exit, L"job-id"},
{event_type_t::caller_exit, L"caller-exit"},
{event_type_t::generic, L"generic"}};
maybe_t<event_type_t> event_type_for_name(const wcstring &name) {
@ -384,7 +377,7 @@ void event_print(io_streams_t &streams, maybe_t<event_type_t> type_filter) {
return d1.signal < d2.signal;
case event_type_t::exit:
return d1.param1.pid < d2.param1.pid;
case event_type_t::job_exit:
case event_type_t::caller_exit:
return d1.param1.job_id < d2.param1.job_id;
case event_type_t::variable:
case event_type_t::any:
@ -412,9 +405,9 @@ void event_print(io_streams_t &streams, maybe_t<event_type_t> type_filter) {
evt->function_name.c_str());
break;
case event_type_t::exit:
case event_type_t::job_exit:
streams.out.append_format(L"%d %ls\n", evt->desc.param1,
evt->function_name.c_str());
break;
case event_type_t::caller_exit:
streams.out.append_format(L"caller-exit %ls\n", evt->function_name.c_str());
break;
case event_type_t::variable:
case event_type_t::generic:

View File

@ -29,8 +29,8 @@ enum class event_type_t {
variable,
/// An event triggered by a job or process exit.
exit,
/// An event triggered by a job exit.
job_exit,
/// An event triggered by a job exit, triggering the 'caller'-style events only.
caller_exit,
/// A generic event.
generic,
};

View File

@ -616,7 +616,7 @@ static bool process_clean_after_marking(parser_t &parser, bool allow_interactive
proc_create_event(L"JOB_EXIT", event_type_t::exit, -j->pgid, 0));
}
exit_events.push_back(
proc_create_event(L"JOB_EXIT", event_type_t::job_exit, j->job_id(), 0));
proc_create_event(L"JOB_EXIT", event_type_t::caller_exit, j->job_id(), 0));
}
}