execute: note the phase each executor is being invoked in

This commit is contained in:
Ariadne Conill 2020-08-26 02:06:36 -06:00
parent b30f84fdbd
commit 4d64176ea3
3 changed files with 15 additions and 15 deletions

View file

@ -140,10 +140,10 @@ lif_file_is_executable(const char *path)
}
bool
lif_maybe_run_executor(const struct lif_execute_opts *opts, char *const envp[], const char *executor)
lif_maybe_run_executor(const struct lif_execute_opts *opts, char *const envp[], const char *executor, const char *phase)
{
if (opts->verbose)
fprintf(stderr, "ifupdown: attempting to run %s executor\n", executor);
fprintf(stderr, "ifupdown: attempting to run %s executor for phase %s\n", executor, phase);
char pathbuf[4096];
@ -156,10 +156,10 @@ lif_maybe_run_executor(const struct lif_execute_opts *opts, char *const envp[],
}
bool
lif_maybe_run_executor_with_result(const struct lif_execute_opts *opts, char *const envp[], const char *executor, char *buf, size_t bufsize)
lif_maybe_run_executor_with_result(const struct lif_execute_opts *opts, char *const envp[], const char *executor, char *buf, size_t bufsize, const char *phase)
{
if (opts->verbose)
fprintf(stderr, "ifupdown: attempting to run %s executor\n", executor);
fprintf(stderr, "ifupdown: attempting to run %s executor for phase %s\n", executor, phase);
char pathbuf[4096];

View file

@ -31,7 +31,7 @@ struct lif_execute_opts {
extern bool lif_execute_fmt(const struct lif_execute_opts *opts, char *const envp[], const char *fmt, ...);
extern bool lif_execute_fmt_with_result(const struct lif_execute_opts *opts, char *buf, size_t bufsize, char *const envp[], const char *fmt, ...);
extern bool lif_file_is_executable(const char *path);
extern bool lif_maybe_run_executor(const struct lif_execute_opts *opts, char *const envp[], const char *executor);
extern bool lif_maybe_run_executor_with_result(const struct lif_execute_opts *opts, char *const envp[], const char *executor, char *buf, size_t bufsize);
extern bool lif_maybe_run_executor(const struct lif_execute_opts *opts, char *const envp[], const char *executor, const char *phase);
extern bool lif_maybe_run_executor_with_result(const struct lif_execute_opts *opts, char *const envp[], const char *executor, char *buf, size_t bufsize, const char *phase);
#endif

View file

@ -44,39 +44,39 @@ handle_commands_for_phase(const struct lif_execute_opts *opts, char *const envp[
}
static inline bool
handle_single_executor_for_phase(const struct lif_dict_entry *entry, const struct lif_execute_opts *opts, char *const envp[])
handle_single_executor_for_phase(const struct lif_dict_entry *entry, const struct lif_execute_opts *opts, char *const envp[], const char *phase)
{
if (strcmp(entry->key, "use"))
return true;
const char *cmd = entry->data;
if (!lif_maybe_run_executor(opts, envp, cmd))
if (!lif_maybe_run_executor(opts, envp, cmd, phase))
return false;
return true;
}
static bool
handle_executors_for_phase(const struct lif_execute_opts *opts, char *const envp[], struct lif_interface *iface, bool up)
handle_executors_for_phase(const struct lif_execute_opts *opts, char *const envp[], struct lif_interface *iface, bool up, const char *phase)
{
struct lif_node *iter;
if (up)
{
LIF_DICT_FOREACH(iter, &iface->vars)
handle_single_executor_for_phase(iter->data, opts, envp);
handle_single_executor_for_phase(iter->data, opts, envp, phase);
}
else
{
LIF_DICT_FOREACH_REVERSE(iter, &iface->vars)
handle_single_executor_for_phase(iter->data, opts, envp);
handle_single_executor_for_phase(iter->data, opts, envp, phase);
}
return true;
}
static bool
query_dependents_from_executors(const struct lif_execute_opts *opts, char *const envp[], struct lif_interface *iface, char *buf, size_t bufsize)
query_dependents_from_executors(const struct lif_execute_opts *opts, char *const envp[], struct lif_interface *iface, char *buf, size_t bufsize, const char *phase)
{
struct lif_node *iter;
@ -94,7 +94,7 @@ query_dependents_from_executors(const struct lif_execute_opts *opts, char *const
continue;
const char *cmd = entry->data;
if (!lif_maybe_run_executor_with_result(&exec_opts, envp, cmd, resbuf, sizeof resbuf))
if (!lif_maybe_run_executor_with_result(&exec_opts, envp, cmd, resbuf, sizeof resbuf, phase))
return false;
if (!*resbuf)
@ -196,7 +196,7 @@ lif_lifecycle_query_dependents(const struct lif_execute_opts *opts, struct lif_i
if (entry != NULL)
strlcpy(deps, entry->data, sizeof deps);
if (!query_dependents_from_executors(opts, envp, iface, deps, sizeof deps))
if (!query_dependents_from_executors(opts, envp, iface, deps, sizeof deps, "depend"))
return false;
char *p = deps;
@ -231,7 +231,7 @@ lif_lifecycle_run_phase(const struct lif_execute_opts *opts, struct lif_interfac
build_environment(&envp, opts, iface, lifname, phase, up ? "start" : "stop");
if (!handle_executors_for_phase(opts, envp, iface, up))
if (!handle_executors_for_phase(opts, envp, iface, up, phase))
goto handle_error;
if (!handle_commands_for_phase(opts, envp, iface, phase))