From 61ed18db2c620bc1ce47ab7dd01a5e610479d685 Mon Sep 17 00:00:00 2001 From: Maximilian Wilhelm Date: Thu, 27 Aug 2020 01:15:51 +0200 Subject: [PATCH 1/2] lifecycle: Check if script dir exist before executing run-parts. Signed-off-by: Maximilian Wilhelm --- libifupdown/lifecycle.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/libifupdown/lifecycle.c b/libifupdown/lifecycle.c index 6db91d6..b6597c9 100644 --- a/libifupdown/lifecycle.c +++ b/libifupdown/lifecycle.c @@ -15,6 +15,9 @@ #include #include +#include +#include +#include #include "libifupdown/environment.h" #include "libifupdown/execute.h" @@ -237,8 +240,17 @@ lif_lifecycle_run_phase(const struct lif_execute_opts *opts, struct lif_interfac if (!handle_commands_for_phase(opts, envp, iface, phase)) goto handle_error; + /* Check if scripts dir for this phase is present and bail out if it isn't */ + struct stat dir_stat; + char dir_path[4096]; + snprintf (dir_path, 4096, "/etc/network/if-%s.d", phase); + + if (stat (dir_path, &dir_stat) != 0 || S_ISDIR (dir_stat.st_mode) == 0) { + goto handle_error; + } + /* we should do error handling here, but ifupdown1 doesn't */ - lif_execute_fmt(opts, envp, "/bin/run-parts /etc/network/if-%s.d", phase); + lif_execute_fmt(opts, envp, "/bin/run-parts %s", dir_path); lif_environment_free(&envp); return true; From 570679c5bff2915b982736b1bc9ac862a0afb033 Mon Sep 17 00:00:00 2001 From: Maximilian Wilhelm Date: Thu, 27 Aug 2020 12:10:12 +0200 Subject: [PATCH 2/2] lifecycle: Make sure to return true when script dir doesn't exist. Signed-off-by: Maximilian Wilhelm --- libifupdown/lifecycle.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libifupdown/lifecycle.c b/libifupdown/lifecycle.c index b6597c9..359f533 100644 --- a/libifupdown/lifecycle.c +++ b/libifupdown/lifecycle.c @@ -246,12 +246,13 @@ lif_lifecycle_run_phase(const struct lif_execute_opts *opts, struct lif_interfac snprintf (dir_path, 4096, "/etc/network/if-%s.d", phase); if (stat (dir_path, &dir_stat) != 0 || S_ISDIR (dir_stat.st_mode) == 0) { - goto handle_error; + goto out_free; } /* we should do error handling here, but ifupdown1 doesn't */ lif_execute_fmt(opts, envp, "/bin/run-parts %s", dir_path); +out_free: lif_environment_free(&envp); return true;