libifupdown: execute: add lif_maybe_try_executor()
This commit is contained in:
parent
4a5a37a620
commit
96112d5dc9
3 changed files with 21 additions and 1 deletions
|
@ -28,7 +28,9 @@ struct match_options {
|
|||
};
|
||||
|
||||
static bool up;
|
||||
static struct lif_execute_opts exec_opts = {};
|
||||
static struct lif_execute_opts exec_opts = {
|
||||
.executor_path = EXECUTOR_PATH,
|
||||
};
|
||||
|
||||
void
|
||||
ifupdown_usage(void)
|
||||
|
|
|
@ -73,3 +73,19 @@ lif_file_is_executable(const char *path)
|
|||
|
||||
return access(path, X_OK);
|
||||
}
|
||||
|
||||
bool
|
||||
lif_maybe_run_executor(const struct lif_execute_opts *opts, char *const envp[], const char *executor)
|
||||
{
|
||||
if (opts->verbose)
|
||||
fprintf(stderr, "ifupdown: attempting to run %s executor\n", executor);
|
||||
|
||||
char pathbuf[4096];
|
||||
|
||||
snprintf(pathbuf, sizeof pathbuf, "%s/%s", opts->executor_path, executor);
|
||||
|
||||
if (!lif_file_is_executable(pathbuf))
|
||||
return true;
|
||||
|
||||
return lif_execute_fmt(opts, envp, "%s", pathbuf);
|
||||
}
|
||||
|
|
|
@ -22,9 +22,11 @@
|
|||
struct lif_execute_opts {
|
||||
bool verbose;
|
||||
bool mock;
|
||||
const char *executor_path;
|
||||
};
|
||||
|
||||
extern bool lif_execute_fmt(const struct lif_execute_opts *opts, 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);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue