aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rpt.c34
1 files changed, 18 insertions, 16 deletions
diff --git a/rpt.c b/rpt.c
index 4c1fc1d..5d013d1 100644
--- a/rpt.c
+++ b/rpt.c
@@ -76,28 +76,30 @@ wait_child(pid_t pid, void (*handle_error_f)(int status))
handle_error_f(exit_status);
}
-/* Invoke the executable *ARGV COUNT times, passing it the rest of ARG as
- arguments. Call HANDLE_ERROR_F between each process. */
void
-repeat_cmd(char **argv, long count, void (*handle_error_f)(int status))
+invoke_cmd(char **argv, void (*handle_error_f)(int status))
{
- pid_t pid;
+ pid_t pid = fork();
- for(long i = 0; i < count; ++i)
+ if (pid < 0)
{
- pid = fork();
+ perror("rpt");
+ exit(4);
+ }
- if (pid < 0)
- {
- perror("rpt");
- exit(4);
- }
+ if (pid == 0)
+ exec_child(argv);
+ else
+ wait_child(pid, handle_error_f);
+}
- if (pid == 0)
- exec_child(argv);
- else
- wait_child(pid, handle_error_f);
- }
+/* Invoke the executable *ARGV COUNT times, passing it the rest of ARG as
+ arguments. Call HANDLE_ERROR_F between each process. */
+void
+repeat_cmd(char **argv, long count, void (*handle_error_f)(int status))
+{
+ for(long i = 0; i < count; ++i)
+ invoke_cmd(argv, handle_error_f);
}
int