From: Alberto Leiva Popper Date: Thu, 17 Oct 2024 23:29:59 +0000 (-0600) Subject: Move the rsync arg builder to the child pipeline X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9744898146e4b106a771dbf150774e7daef4c118;p=thirdparty%2FFORT-validator.git Move the rsync arg builder to the child pipeline This was (annoyingly) outside because it used to allocate. (The child is only allowed to call async-signal-safe functions.) But a) It doesn't allocate anymore. b) The async-signal-safe constraint is going to die in a few refactors. Incidentally deletes the argument echoer, since the arguments are not variable anymore. --- diff --git a/src/rsync.c b/src/rsync.c index 72da3117..e77afb6e 100644 --- a/src/rsync.c +++ b/src/rsync.c @@ -38,7 +38,7 @@ duplicate_fds(int fds[2][2]) } static void -prepare_rsync(char **args, char const *url, char const *path) +prepare_rsync_args(char **args, char const *url, char const *path) { size_t i = 0; @@ -76,11 +76,13 @@ prepare_rsync(char **args, char const *url, char const *path) } __dead static void -handle_child_thread(char **args, int fds[2][2]) +handle_child_thread(char const *url, char const *path, int fds[2][2]) { /* THIS FUNCTION MUST NEVER RETURN!!! */ + char *args[20]; int error; + prepare_rsync_args(args, url, path); duplicate_fds(fds); execvp(args[0], args); @@ -276,23 +278,13 @@ exhaust_pipes(int fds[2][2]) int rsync_download(char const *url, char const *path) { - char *args[32]; /* Descriptors to pipe stderr (first element) and stdout (second) */ int fork_fds[2][2]; pid_t child_pid; - unsigned int i; int child; int error; - /* Prepare everything for the child exec */ - prepare_rsync(args, url, path); - pr_val_info("rsync: %s -> %s", url, path); - if (log_val_enabled(LOG_DEBUG)) { - pr_val_debug("Executing rsync:"); - for (i = 0; args[i] != NULL; i++) - pr_val_debug(" %s", args[i]); - } error = create_pipes(fork_fds); if (error) @@ -314,7 +306,7 @@ rsync_download(char const *url, char const *path) * execute async-signal-safe operations until such time * as one of the exec functions is called." */ - handle_child_thread(args, fork_fds); + handle_child_thread(url, path, fork_fds); } if (child_pid < 0) { error = errno;