Do not call wordsplit on multiple places when not necessary. Move the xexec function into #ifndef MSDOS part of file.
* system.c (try_exec): New function - modified previous xexec. (xexec): Re-use try_exec and fail when not try_exec unsuccessful. (run_decompress_program): Do not call wordsplit - rather reuse xexec. (sys_exec_command): Remove unused variable argv. (sys_child_open_for_compress): Trim line. --- src/system.c | 72 +++++++++++++++++++++++++++--------------------------------- 1 file changed, 32 insertions(+), 40 deletions(-) diff --git a/src/system.c b/src/system.c index 6adcbf0..9d9bda9 100644 --- a/src/system.c +++ b/src/system.c @@ -23,19 +23,6 @@ #include <signal.h> #include <wordsplit.h> -static void -xexec (const char *cmd) -{ - struct wordsplit ws; - - ws.ws_env = (const char **) environ; - if (wordsplit (cmd, &ws, (WRDSF_DEFFLAGS | WRDSF_ENV) & ~WRDSF_NOVAR)) - FATAL_ERROR ((0, 0, _("cannot split string '%s': %s"), - cmd, wordsplit_strerror (&ws))); - execvp (ws.ws_wordv[0], ws.ws_wordv); - exec_fatal (cmd); -} - #if MSDOS bool @@ -125,6 +112,25 @@ sys_child_open_for_uncompress (void) #else +static void +try_exec (const char *cmd) +{ + struct wordsplit ws; + + ws.ws_env = (const char **) environ; + if (wordsplit (cmd, &ws, (WRDSF_DEFFLAGS | WRDSF_ENV) & ~WRDSF_NOVAR)) + FATAL_ERROR ((0, 0, _("cannot split string '%s': %s"), + cmd, wordsplit_strerror (&ws))); + execvp (ws.ws_wordv[0], ws.ws_wordv); +} + +static void +xexec (const char *cmd) +{ + try_exec (cmd); + exec_fatal (cmd); +} + extern union block *record_start; /* FIXME */ static struct stat archive_stat; /* stat block for archive file */ @@ -329,7 +335,7 @@ sys_child_open_for_compress (void) int child_pipe[2]; pid_t grandchild_pid; pid_t child_pid; - + xpipe (parent_pipe); child_pid = xfork (); @@ -468,15 +474,12 @@ static void run_decompress_program (void) { int i; - const char *p, *prog = NULL; - struct wordsplit ws; - int wsflags = (WRDSF_DEFFLAGS | WRDSF_ENV | WRDSF_DOOFFS) & ~WRDSF_NOVAR; + const char *p; + char *prog = NULL; - ws.ws_env = (const char **) environ; - ws.ws_offs = 1; - for (p = first_decompress_program (&i); p; p = next_decompress_program (&i)) { + int len = strlen (p); if (prog) { WARNOPT (WARN_DECOMPRESS_PROGRAM, @@ -484,16 +487,12 @@ run_decompress_program (void) WARNOPT (WARN_DECOMPRESS_PROGRAM, (0, 0, _("trying %s"), p)); } - if (wordsplit (p, &ws, wsflags)) - FATAL_ERROR ((0, 0, _("cannot split string '%s': %s"), - p, wordsplit_strerror (&ws))); - wsflags |= WRDSF_REUSE; - memmove(ws.ws_wordv, ws.ws_wordv + ws.ws_offs, - sizeof(ws.ws_wordv[0])*ws.ws_wordc); - ws.ws_wordv[ws.ws_wordc] = "-d"; - prog = p; - execvp (ws.ws_wordv[0], ws.ws_wordv); - ws.ws_wordv[ws.ws_wordc] = NULL; + prog = xmalloc (len + 4 /* { ' ', '-', 'd', '\0' } */); + strcpy (prog, p); + strcpy (prog + len, " -d"); + prog[len + 3] = 0; + + try_exec (prog); } if (!prog) FATAL_ERROR ((0, 0, _("unable to run decompression program"))); @@ -726,8 +725,7 @@ int sys_exec_command (char *file_name, int typechar, struct tar_stat_info *st) { int p[2]; - char *argv[4]; - + xpipe (p); pipe_handler = signal (SIGPIPE, SIG_IGN); global_pid = xfork (); @@ -787,7 +785,6 @@ int sys_exec_info_script (const char **archive_name, int volume_number) { pid_t pid; - char *argv[4]; char uintbuf[UINTMAX_STRSIZE_BOUND]; int p[2]; static RETSIGTYPE (*saved_handler) (int sig); @@ -849,7 +846,7 @@ sys_exec_info_script (const char **archive_name, int volume_number) archive_format_string (current_format == DEFAULT_FORMAT ? archive_format : current_format), 1); setenv ("TAR_FD", STRINGIFY_BIGINT (p[PWRITE], uintbuf), 1); - + xclose (p[PREAD]); priv_set_restore_linkdir (); @@ -862,9 +859,8 @@ sys_exec_checkpoint_script (const char *script_name, int checkpoint_number) { pid_t pid; - char *argv[4]; char uintbuf[UINTMAX_STRSIZE_BOUND]; - + pid = xfork (); if (pid != 0) @@ -893,10 +889,6 @@ sys_exec_checkpoint_script (const char *script_name, setenv ("TAR_FORMAT", archive_format_string (current_format == DEFAULT_FORMAT ? archive_format : current_format), 1); - argv[0] = (char *) "/bin/sh"; - argv[1] = (char *) "-c"; - argv[2] = (char *) script_name; - argv[3] = NULL; priv_set_restore_linkdir (); xexec (script_name); -- 1.8.1.2