lifecycle: Check if script dir exist before executing run-parts.

Signed-off-by: Maximilian Wilhelm <max@sdn.clinic>
This commit is contained in:
Maximilian Wilhelm 2020-08-27 01:15:51 +02:00
parent 1f21d2bb45
commit 61ed18db2c

View file

@ -15,6 +15,9 @@
#include <ctype.h> #include <ctype.h>
#include <string.h> #include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "libifupdown/environment.h" #include "libifupdown/environment.h"
#include "libifupdown/execute.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)) if (!handle_commands_for_phase(opts, envp, iface, phase))
goto handle_error; 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 */ /* 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); lif_environment_free(&envp);
return true; return true;