[vlc-commits] decomp: use vlc_spawn()

Rémi Denis-Courmont git at videolan.org
Sun Sep 20 11:53:12 CEST 2020


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Sep 19 13:25:00 2020 +0300| [76e99955fa9cf2832d9b16535e071212f4443894] | committer: Rémi Denis-Courmont

decomp: use vlc_spawn()

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=76e99955fa9cf2832d9b16535e071212f4443894
---

 modules/stream_filter/decomp.c | 62 ++++++++++--------------------------------
 1 file changed, 14 insertions(+), 48 deletions(-)

diff --git a/modules/stream_filter/decomp.c b/modules/stream_filter/decomp.c
index 330f3822f2..ebd3929545 100644
--- a/modules/stream_filter/decomp.c
+++ b/modules/stream_filter/decomp.c
@@ -27,17 +27,10 @@
 #include <vlc_stream.h>
 #include <vlc_network.h>
 #include <vlc_fs.h>
-#include <assert.h>
+#include <vlc_spawn.h>
 #include <unistd.h>
 #include <errno.h>
-#ifndef _POSIX_SPAWN
-# define _POSIX_SPAWN (-1)
-#endif
 #include <fcntl.h>
-#if (_POSIX_SPAWN >= 0)
-# include <spawn.h>
-#endif
-#include <sys/wait.h>
 #include <sys/ioctl.h>
 #if defined (__linux__) && defined (HAVE_VMSPLICE)
 # include <sys/uio.h>
@@ -274,47 +267,23 @@ static int Open (stream_t *stream, const char *path)
         int uncomp[2];
         if (vlc_pipe (uncomp) == 0)
         {
+            int fdv[] = { comp[0], uncomp[1], 2, -1 };
+            const char *argv[] = { path, NULL };
+
             p_sys->read_fd = uncomp[0];
 
-#if (_POSIX_SPAWN >= 0)
-            posix_spawn_file_actions_t actions;
-            if (posix_spawn_file_actions_init (&actions) == 0)
+            if (vlc_spawnp(&p_sys->pid, path, fdv, argv) == 0)
             {
-                char *const argv[] = { (char *)path, NULL };
-
-                if (!posix_spawn_file_actions_adddup2 (&actions, comp[0], 0)
-                 && !posix_spawn_file_actions_adddup2 (&actions, uncomp[1], 1)
-                 && !posix_spawnp (&p_sys->pid, path, &actions, NULL, argv,
-                                   environ))
-                {
-                    if (vlc_clone (&p_sys->thread, Thread, stream,
-                                   VLC_THREAD_PRIORITY_INPUT) == 0)
-                        ret = VLC_SUCCESS;
-                }
-                else
-                {
-                    msg_Err (stream, "cannot execute %s", path);
-                    p_sys->pid = -1;
-                }
-                posix_spawn_file_actions_destroy (&actions);
+                if (vlc_clone(&p_sys->thread, Thread, stream,
+                              VLC_THREAD_PRIORITY_INPUT) == 0)
+                    ret = VLC_SUCCESS;
             }
-#else /* _POSIX_SPAWN */
-            switch (p_sys->pid = fork ())
+            else
             {
-                case -1:
-                    msg_Err (stream, "cannot fork: %s", vlc_strerror_c(errno));
-                    break;
-                case 0:
-                    dup2 (comp[0], 0);
-                    dup2 (uncomp[1], 1);
-                    execlp (path, path, (const 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;
+                msg_Err (stream, "cannot execute %s", path);
+                p_sys->pid = -1;
             }
-#endif /* _POSIX_SPAWN < 0 */
+
             vlc_close (uncomp[1]);
             if (ret != VLC_SUCCESS)
                 vlc_close (uncomp[0]);
@@ -327,7 +296,7 @@ static int Open (stream_t *stream, const char *path)
     if (ret != VLC_SUCCESS)
     {
         if (p_sys->pid != -1)
-            while (waitpid (p_sys->pid, &(int){ 0 }, 0) == -1);
+            vlc_waitpid(p_sys->pid);
         free (p_sys);
         return ret;
     }
@@ -346,7 +315,6 @@ static void Close (vlc_object_t *obj)
 {
     stream_t *stream = (stream_t *)obj;
     stream_sys_t *p_sys = stream->p_sys;
-    int status;
 
     vlc_cancel (p_sys->thread);
     vlc_close (p_sys->read_fd);
@@ -356,9 +324,7 @@ static void Close (vlc_object_t *obj)
         vlc_close (p_sys->write_fd);
 
     msg_Dbg (obj, "waiting for PID %u", (unsigned)p_sys->pid);
-    while (waitpid (p_sys->pid, &status, 0) == -1);
-    msg_Dbg (obj, "exit status %d", status);
-
+    msg_Dbg (obj, "exit status %d", vlc_waitpid(p_sys->pid));
     free (p_sys);
 }
 



More information about the vlc-commits mailing list