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
;
34 void launch_only_once(const char *uri
)
37 posix_spawn_file_actions_t fa
;
41 char *uridup
= strdup(uri
);
42 char *prog
= strdup("mpv");
43 char *quiet
= strdup("--quiet");
44 char * const argv
[4] = { prog
, quiet
, uridup
, 0 };
52 if (posix_spawn_file_actions_init(&fa
)) {
53 PERROR_MESSAGE("posix_spawn_file_actions_init");
59 if (posix_spawnattr_init(&sa
)) {
60 PERROR_MESSAGE("posix_spawnattr_init");
66 if (posix_spawn_file_actions_addclose(&fa
, 0)) {
67 PERROR_MESSAGE("posix_spawn_file_actions_addclose");
71 if (posix_spawn_file_actions_addclose(&fa
, 1)) {
72 PERROR_MESSAGE("posix_spawn_file_actions_addclose");
76 if (posix_spawn_file_actions_addclose(&fa
, 2)) {
77 PERROR_MESSAGE("posix_spawn_file_actions_addclose");
81 if (posix_spawnattr_setflags(&sa
, POSIX_SPAWN_SETSIGDEF
)) {
82 PERROR_MESSAGE("posix_spawnattr_setflags");
86 if (posix_spawn_file_actions_addopen(&fa
, 0, "/dev/null", O_RDONLY
,
88 PERROR_MESSAGE("posix_spawn_file_actions_addopen");
92 if (posix_spawn_file_actions_addopen(&fa
, 1, "/dev/null", O_WRONLY
,
94 PERROR_MESSAGE("posix_spawn_file_actions_addopen");
98 if (posix_spawn_file_actions_adddup2(&fa
, 1, 2)) {
99 PERROR_MESSAGE("posix_spawn_file_actions_adddup2");
103 posix_spawnp(&dummy
, "mpv-with-load-screen", &fa
, &sa
, argv
, environ
);
107 posix_spawn_file_actions_destroy(&fa
);
111 posix_spawnattr_destroy(&sa
);