#include <vlc_plugin.h>
#include <vlc_stream.h>
#include <vlc_network.h>
+#include <vlc_fs.h>
#include <assert.h>
#include <unistd.h>
#include <errno.h>
int write_fd, read_fd;
};
-static void cloexec (int fd)
-{
- int flags = fcntl (fd, F_GETFD);
- fcntl (fd, F_SETFD, FD_CLOEXEC | ((flags != -1) ? flags : 0));
-}
-
extern char **environ;
static const size_t bufsize = 65536;
break;
vlc_cleanup_push (cleanup_mmap, buf);
#else
- unsigned char buf[bufsize];
+ unsigned char *buf = malloc (bufsize);
+ if (unlikely(buf == NULL))
+ break;
+ vlc_cleanup_push (free, buf);
#endif
len = stream_Read (stream->p_source, buf, bufsize);
break;
}
}
-#ifdef HAVE_VMSPLICE
- vlc_cleanup_run (); /* munmap (buf, bufsize) */
-#endif
+ vlc_cleanup_run (); /* free (buf) */
}
while (!error);
msg_Dbg (stream, "compressed stream at EOF");
+ /* Let child process know about EOF */
+ p_sys->write_fd = -1;
+ close (fd);
return NULL;
}
/* We use two pipes rather than one stream socket pair, so that we can
* use vmsplice() on Linux. */
- if (pipe (comp) == 0)
+ if (vlc_pipe (comp) == 0)
{
- cloexec (comp[1]);
p_sys->write_fd = comp[1];
int uncomp[2];
- if (pipe (uncomp) == 0)
+ if (vlc_pipe (uncomp) == 0)
{
- cloexec (uncomp[0]);
p_sys->read_fd = uncomp[0];
#if (_POSIX_SPAWN >= 0)
char *const argv[] = { (char *)path, NULL };
if (!posix_spawn_file_actions_adddup2 (&actions, comp[0], 0)
- && !posix_spawn_file_actions_addclose (&actions, comp[0])
&& !posix_spawn_file_actions_adddup2 (&actions, uncomp[1], 1)
- && !posix_spawn_file_actions_addclose (&actions, uncomp[1])
&& !posix_spawnp (&p_sys->pid, path, &actions, NULL, argv,
environ))
{
break;
case 0:
dup2 (comp[0], 0);
- close (comp[0]);
dup2 (uncomp[1], 1);
- close (uncomp[1]);
execlp (path, path, (char *)NULL);
exit (1); /* if we get, execlp() failed! */
default:
vlc_cancel (p_sys->thread);
close (p_sys->read_fd);
vlc_join (p_sys->thread, NULL);
- close (p_sys->write_fd);
+ if (p_sys->write_fd != -1)
+ /* Killed before EOF? */
+ close (p_sys->write_fd);
msg_Dbg (obj, "waiting for PID %u", (unsigned)p_sys->pid);
while (waitpid (p_sys->pid, &status, 0) == -1);