[RFC] tar --to-command
Denys Vlasenko
vda.linux at googlemail.com
Sat Jun 19 18:41:13 UTC 2010
On Friday 18 June 2010 11:11, Ladislav Michl wrote:
> On Fri, Jun 18, 2010 at 02:41:08AM +0200, Denys Vlasenko wrote:
> > On Friday 18 June 2010 02:15, Ladislav Michl wrote:
> > > Above is typicaly fed with firmware file over ssh:
> > > ssh -l root <target_ip> "fw_install -" < fwfile
> >
> > This adds an incompatible option to tar.
>
> True, I'm not aware of any other tar implementation, except GNU's supporting
> it.
Aha, I didn't know they added it.
Then in principle it's ok. Let's look at the patch...
+ If you enable this option you'll be able to instruct tar to send
+ the contents of each extracted file to the standard input of an
+ external program.
Broken indent
+ IF_FEATURE_TAR_TO_COMMAND("b:")
Standard tar don't support short opt for it, please do not add it.
+ if (pid == 0) {
+ /* Child */
+ xdup2(p[0], STDIN_FILENO);
+ fcntl(p[1], F_SETFD, FD_CLOEXEC);
Just close(p[1]) -> it is smaller code.
+ xsetenv("TAR_FILENAME", file_header->name);
+ xsetenv("TAR_SIZE", file_header->size);
This might leak memory on parent side.
+ argv[0] = (char*)"/bin/sh";
+ argv[1] = (char*)"-c";
+ argv[2] = archive_handle->tar__to_command;
+ argv[3] = NULL;
+
+ execv ("/bin/sh", argv);
execl() might be smaller code.
+ xclose(p[0]);
+ bb_copyfd_exact_size(archive_handle->src_fd, p[1], file_header->size);
+// wait4pid(pid);
+ xclose(p[1]);
close() is ok here. xclose is needed when we write to _files or devices_.
Upstream tar does wait for child to finish. try:
tar xf linux-2.6.35-rc3.tar.bz2 --to-command='sleep 1; echo -$TAR_FILENAME-'
Not waiting for child may fork bomb the machine.
--
vda
--
vda
More information about the busybox
mailing list