summaryrefslogtreecommitdiffstats
path: root/lib/run_part.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lib/run_part.c24
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,