Merge pull request #52 from BarbarossaTM/scripts

lifecycle: Check if script dir exists before executing run-parts.
This commit is contained in:
Ariadne Conill 2020-08-29 08:38:16 -06:00 committed by GitHub
commit 375b5d46cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -15,6 +15,9 @@
#include <ctype.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "libifupdown/environment.h"
#include "libifupdown/execute.h"
@ -237,9 +240,19 @@ 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;
/* we should do error handling here, but ifupdown1 doesn't */
lif_execute_fmt(opts, envp, "/bin/run-parts /etc/network/if-%s.d", phase);
/* 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 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;