]> git.sesse.net Git - vlc/blobdiff - modules/stream_filter/decomp.c
decomp: inclde spawn.h only if used
[vlc] / modules / stream_filter / decomp.c
index 81a35728b948587dc539e0ef9c0a4c5ad44a8c2f..2466b47150ef36f5e7678c60b747b51e82bdb2ca 100644 (file)
 #include <vlc_stream.h>
 #include <vlc_network.h>
 #include <unistd.h>
+#ifndef _POSIX_SPAWN
+# define _POSIX_SPAWN (-1)
+#endif
 #include <fcntl.h>
-#include <spawn.h>
+#if (_POSIX_SPAWN >= 0)
+# include <spawn.h>
+#endif
 #include <sys/wait.h>
 #include <sys/ioctl.h>
 #if defined (__linux__) && defined (HAVE_VMSPLICE)
@@ -255,6 +260,8 @@ static int Open (stream_t *stream, const char *path)
     int ret = VLC_EGENERIC;
     int comp[2];
 
+    /* We use two pipes rather than one stream socket pair, so that we can
+     * use vmsplice() on Linux. */
     if (pipe (comp) == 0)
     {
         cloexec (comp[1]);
@@ -266,6 +273,7 @@ static int Open (stream_t *stream, const char *path)
             cloexec (uncomp[0]);
             p_sys->read_fd = uncomp[0];
 
+#if (_POSIX_SPAWN >= 0)
             posix_spawn_file_actions_t actions;
             if (posix_spawn_file_actions_init (&actions) == 0)
             {
@@ -289,6 +297,25 @@ static int Open (stream_t *stream, const char *path)
                 }
                 posix_spawn_file_actions_destroy (&actions);
             }
+#else /* _POSIX_SPAWN */
+            switch (p_sys->pid = fork ())
+            {
+                case -1:
+                    msg_Err (stream, "Cannot fork (%m)");
+                    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:
+                    if (vlc_clone (&p_sys->thread, Thread, stream,
+                                   VLC_THREAD_PRIORITY_INPUT) == 0)
+                        ret = VLC_SUCCESS;
+            }
+#endif /* _POSIX_SPAWN < 0 */
             close (uncomp[1]);
             if (ret != VLC_SUCCESS)
                 close (uncomp[0]);