2 * Copyright (c) 2018, De Rais <derais@cock.li>
4 * Permission to use, copy, modify, and/or distribute this software for
5 * any purpose with or without fee is hereby granted, provided that the
6 * above copyright notice and this permission notice appear in all
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
26 #include <sys/types.h>
32 extern char **environ
;
35 launch_only_once(const char *uri
)
38 posix_spawn_file_actions_t fa
;
42 char *uridup
= strdup(uri
);
43 char *prog
= strdup("mpv");
44 char *quiet
= strdup("--quiet");
45 char * const argv
[4] = { prog
, quiet
, uridup
, 0 };
53 if (posix_spawn_file_actions_init(&fa
)) {
54 PERROR_MESSAGE("posix_spawn_file_actions_init");
60 if (posix_spawnattr_init(&sa
)) {
61 PERROR_MESSAGE("posix_spawnattr_init");
67 if (posix_spawn_file_actions_addclose(&fa
, 0)) {
68 PERROR_MESSAGE("posix_spawn_file_actions_addclose");
72 if (posix_spawn_file_actions_addclose(&fa
, 1)) {
73 PERROR_MESSAGE("posix_spawn_file_actions_addclose");
77 if (posix_spawn_file_actions_addclose(&fa
, 2)) {
78 PERROR_MESSAGE("posix_spawn_file_actions_addclose");
82 if (posix_spawnattr_setflags(&sa
, POSIX_SPAWN_SETSIGDEF
)) {
83 PERROR_MESSAGE("posix_spawnattr_setflags");
87 if (posix_spawn_file_actions_addopen(&fa
, 0, "/dev/null", O_RDONLY
,
89 PERROR_MESSAGE("posix_spawn_file_actions_addopen");
93 if (posix_spawn_file_actions_addopen(&fa
, 1, "/dev/null", O_WRONLY
,
95 PERROR_MESSAGE("posix_spawn_file_actions_addopen");
99 if (posix_spawn_file_actions_adddup2(&fa
, 1, 2)) {
100 PERROR_MESSAGE("posix_spawn_file_actions_adddup2");
104 posix_spawnp(&dummy
, "mpv-with-load-screen", &fa
, &sa
, argv
, environ
);
108 posix_spawn_file_actions_destroy(&fa
);
112 posix_spawnattr_destroy(&sa
);