aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Riehs <tristan.riehs@bordeaux-inp.fr>2023-10-08 19:52:25 +0200
committerTristan Riehs <tristan.riehs@bordeaux-inp.fr>2023-10-08 19:52:25 +0200
commit0cc35b207df562084f2351a1edd8723acbbc5477 (patch)
tree103fa85d766515e5b3a1e5a6dcd7f2b72a57ea52
parent654e1be127f663d50c91fc7d7d1a932aec091d17 (diff)
refactoring
-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