[MPlayer-dev-eng] [PATCH] Use unrar for open vobsubs if available

Ulion ulion2002 at gmail.com
Tue Dec 11 08:30:47 CET 2007


2007/12/8, Ulion <ulion2002 at gmail.com>:
> 2007/12/8, Reimar Döffinger <Reimar.Doeffinger at stud.uni-karlsruhe.de>:
> > Hello,
> > On Sat, Dec 08, 2007 at 12:43:36AM +0800, Ulion wrote:
> > > 2007/12/8, Reimar Doeffinger <Reimar.Doeffinger at stud.uni-karlsruhe.de>:
> > [...]
> > > > > How about:
> > > > >
> > > > >         fd = open("/dev/null", O_WRONLY);
> > > > >         if(fd == -1)
> > > > >             _exit(EXIT_FAILURE);
> > > > >         if (fd != 2) {
> > > > >             dup2(fd, 2);
> > > > >             close(fd);
> > > > >         }
> > > >
> > > > What is the point of the != 2 check then? Either you assume that
> > > > stdin, stdout and stderr are correctly set at the beginning,
> > > > then fd _can_ not be 2 (because you did not close it before).
> > > > Or if you don't assume that and you should check for that case (which,
> > > > due to "open" being required to return the smallest non-open
> > > > descriptor, my < 3 test does, though I admit it is not ideal
> > > > in clearness).
> > >
> > > I assume stdout is correctly set, does not assume whether stdin and
> > > stderr are correctly set.
> > > So my last code will works fine with the assume -- stdout is correctly set.
> > > That's enough for current implement since it only care the stdout.
> >
> > Except that if you only assume stdout is opened, the first file opened
> > by the unrar binary would become its stdin.
> > The same applies to stderr if this dup2 fails.
> > A truly proper solution would also try to close all other open file
> > descriptors that are not needed, but that is quite ugly (I think OpenBSD
> > has an extra syscall for that, I must say that really is a very
> > advisable thing).
> > I think code like this would make sense (note you'll have to replace
> > that pipefd by the right variable, I forgot the name):
> > > // close MPlayer's stdin, stdout and stderr so the unrar binary
> > > // can not mess them up
> > > // TODO: close all other files except the pipe
> > > close(0); close(1); close(2);
> > > // assign new stdin, stdout and stderr and check they actually got the
> > > // right descriptors
> > > if (open("/dev/null", O_RDONLY) != 0 || dup(pipefd) != 1 || open("/dev/null", O_WRONLY) != 2)
> > >   _exit(EXIT_FAILURE);
>
> This one is really good, updated.

Update win32 popen to escape char '%'.


-- 
Ulion
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: unrar_exec14.diff
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20071211/8d68b98b/attachment.asc>


More information about the MPlayer-dev-eng mailing list