execute: note the phase each executor is being invoked in
This commit is contained in:
parent
b30f84fdbd
commit
4d64176ea3
3 changed files with 15 additions and 15 deletions
|
@ -140,10 +140,10 @@ lif_file_is_executable(const char *path)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
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)
|
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];
|
char pathbuf[4096];
|
||||||
|
|
||||||
|
@ -156,10 +156,10 @@ lif_maybe_run_executor(const struct lif_execute_opts *opts, char *const envp[],
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
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)
|
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];
|
char pathbuf[4096];
|
||||||
|
|
||||||
|
|
|
@ -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(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_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_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(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);
|
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
|
#endif
|
||||||
|
|
|
@ -44,39 +44,39 @@ handle_commands_for_phase(const struct lif_execute_opts *opts, char *const envp[
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool
|
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"))
|
if (strcmp(entry->key, "use"))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
const char *cmd = entry->data;
|
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 false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
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;
|
struct lif_node *iter;
|
||||||
|
|
||||||
if (up)
|
if (up)
|
||||||
{
|
{
|
||||||
LIF_DICT_FOREACH(iter, &iface->vars)
|
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
|
else
|
||||||
{
|
{
|
||||||
LIF_DICT_FOREACH_REVERSE(iter, &iface->vars)
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
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;
|
struct lif_node *iter;
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ query_dependents_from_executors(const struct lif_execute_opts *opts, char *const
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const char *cmd = entry->data;
|
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;
|
return false;
|
||||||
|
|
||||||
if (!*resbuf)
|
if (!*resbuf)
|
||||||
|
@ -196,7 +196,7 @@ lif_lifecycle_query_dependents(const struct lif_execute_opts *opts, struct lif_i
|
||||||
if (entry != NULL)
|
if (entry != NULL)
|
||||||
strlcpy(deps, entry->data, sizeof deps);
|
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;
|
return false;
|
||||||
|
|
||||||
char *p = deps;
|
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");
|
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;
|
goto handle_error;
|
||||||
|
|
||||||
if (!handle_commands_for_phase(opts, envp, iface, phase))
|
if (!handle_commands_for_phase(opts, envp, iface, phase))
|
||||||
|
|
Loading…
Reference in a new issue