[PATCH] tar --to-command

Ladislav Michl Ladislav.Michl at seznam.cz
Fri Jun 25 13:29:22 UTC 2010


On Fri, Jun 25, 2010 at 10:36:53AM +0200, Bernhard Reutner-Fischer wrote:
> On Thu, Jun 24, 2010 at 04:51:49AM +0200, Denys Vlasenko wrote:
> >On Monday 21 June 2010 19:41, Ladislav Michl wrote:
> 
> >> +		static const char *sh = "/bin/sh";
> >
> >static const char sh[] = "/bin/sh",
> >but better just use literal "/bin/sh" where you need the string.
> 
> and the best thing would be to use DEFAULT_SHELL (see include/libbb.h)
> Other occurances of literal "/bin/sh" that crept in lately should be
> fixed, too.

Thanks, see patch bellow.

> >> +		xpipe(p);
> >> +		sig_pipe = signal(SIGPIPE, SIG_IGN);
> >> +		pid = BB_MMU ? fork() : vfork();
> 
> Didn't look at the full patch, but this hunk may sound like a candidate
> for spawn_and_wait(), perhaps?

No, spawn_and_wait() does too much at once. We need fork, setup environment,
exec, copy file to child's stdin, close it and then wait.


Use DEFAULT_SHELL instead of literal "/bin/sh".

Signed-off-by: Ladislav Michl <ladis at linux-mips.org>
---
 data_extract_to_command.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/archival/libunarchive/data_extract_to_command.c b/archival/libunarchive/data_extract_to_command.c
index 983c530..a0a1fe2 100644
--- a/archival/libunarchive/data_extract_to_command.c
+++ b/archival/libunarchive/data_extract_to_command.c
@@ -102,8 +102,9 @@ void FAST_FUNC data_extract_to_command(archive_handle_t *archive_handle)
 			close(p[1]);
 			xdup2(p[0], STDIN_FILENO);
 			signal(SIGPIPE, SIG_DFL);
-			execl("/bin/sh", "/bin/sh" + 5, "-c", archive_handle->tar__to_command, NULL);
-			bb_perror_msg_and_die("can't execute '%s'", "/bin/sh");
+			execl(DEFAULT_SHELL, DEFAULT_SHELL_SHORT_NAME, "-c",
+			      archive_handle->tar__to_command, NULL);
+			bb_perror_msg_and_die("can't execute '%s'", DEFAULT_SHELL);
 		}
 		close(p[0]);
 		/* Our caller is expected to do signal(SIGPIPE, SIG_IGN)



More information about the busybox mailing list