diff options
author | Tristan Riehs <tristan.riehs@bordeaux-inp.fr> | 2023-10-08 19:52:25 +0200 |
---|---|---|
committer | Tristan Riehs <tristan.riehs@bordeaux-inp.fr> | 2023-10-08 19:52:25 +0200 |
commit | 0cc35b207df562084f2351a1edd8723acbbc5477 (patch) | |
tree | 103fa85d766515e5b3a1e5a6dcd7f2b72a57ea52 /rpt.c | |
parent | 654e1be127f663d50c91fc7d7d1a932aec091d17 (diff) |
refactoring
Diffstat (limited to 'rpt.c')
-rw-r--r-- | rpt.c | 34 |
1 files changed, 18 insertions, 16 deletions
@@ -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 |