diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-26 16:18:36 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-26 16:18:36 +0000 |
commit | 6c3ea4f47ea280811a7fe53a22f7832e4533c9ec (patch) | |
tree | 3d7ed5da23b5dbf6f9e450dfb61642832249c31e /lib/run_part.c | |
parent | Adding upstream version 1:4.13+dfsg1. (diff) | |
download | shadow-upstream.tar.xz shadow-upstream.zip |
Adding upstream version 1:4.15.2.upstream/1%4.15.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | lib/run_part.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/lib/run_part.c b/lib/run_part.c index bce11d3..670d815 100644 --- a/lib/run_part.c +++ b/lib/run_part.c @@ -1,3 +1,5 @@ +#include <config.h> + #include <dirent.h> #include <errno.h> #include <stdio.h> @@ -8,9 +10,12 @@ #include <sys/wait.h> #include <unistd.h> #include <lib/prototypes.h> + +#include "alloc.h" #include "run_part.h" #include "shadowlog_internal.h" + int run_part (char *script_path, const char *name, const char *action) { int pid; @@ -53,25 +58,22 @@ int run_parts (const char *directory, const char *name, const char *action) } for (n=0; n<scanlist; n++) { - int path_length; - struct stat sb; + char *s; + struct stat sb; - path_length=strlen(directory) + strlen(namelist[n]->d_name) + 2; - char *s = (char*)malloc(path_length); - if (!s) { - printf ("could not allocate memory\n"); + if (asprintf(&s, "%s/%s", directory, namelist[n]->d_name) == -1) { + fprintf(stderr, "could not allocate memory\n"); for (; n<scanlist; n++) { - free (namelist[n]); + free(namelist[n]); } - free (namelist); + free(namelist); return (1); } - snprintf (s, path_length, "%s/%s", directory, namelist[n]->d_name); execute_result = 0; if (stat (s, &sb) == -1) { perror ("stat"); - free (s); + free(s); for (; n<scanlist; n++) { free (namelist[n]); } @@ -83,7 +85,7 @@ int run_parts (const char *directory, const char *name, const char *action) execute_result = run_part (s, name, action); } - free (s); + free(s); if (execute_result!=0) { fprintf (shadow_logfd, |