Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc
Commits
860a707f
Commit
860a707f
authored
Dec 29, 2009
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
screensaver: convert to POSIX spawn
parent
2a817cdb
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
29 deletions
+35
-29
modules/misc/screensaver.c
modules/misc/screensaver.c
+35
-29
No files found.
modules/misc/screensaver.c
View file @
860a707f
...
...
@@ -33,11 +33,13 @@
#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_inhibit.h>
#include <vlc_charset.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <
unistd
.h>
#include <
fcntl
.h>
#include <signal.h>
#include <spawn.h>
/*****************************************************************************
* Local prototypes
...
...
@@ -51,8 +53,12 @@ static void Inhibit( vlc_inhibit_t *, bool );
struct
vlc_inhibit_sys
{
vlc_timer_t
timer
;
posix_spawn_file_actions_t
actions
;
posix_spawnattr_t
attr
;
int
nullfd
;
};
extern
char
**
environ
;
/*****************************************************************************
* Module descriptor
...
...
@@ -82,6 +88,21 @@ static int Activate( vlc_object_t *p_this )
}
p_ih
->
inhibit
=
Inhibit
;
int
fd
=
utf8_open
(
"/dev/null"
,
O_WRONLY
);
posix_spawn_file_actions_init
(
&
p_sys
->
actions
);
if
(
fd
!=
-
1
)
{
posix_spawn_file_actions_adddup2
(
&
p_sys
->
actions
,
fd
,
1
);
posix_spawn_file_actions_adddup2
(
&
p_sys
->
actions
,
fd
,
2
);
posix_spawn_file_actions_addclose
(
&
p_sys
->
actions
,
fd
);
}
p_sys
->
nullfd
=
fd
;
sigset_t
set
;
posix_spawnattr_init
(
&
p_sys
->
attr
);
sigemptyset
(
&
set
);
posix_spawnattr_setsigmask
(
&
p_sys
->
attr
,
&
set
);
return
VLC_SUCCESS
;
}
...
...
@@ -94,7 +115,10 @@ static void Deactivate( vlc_object_t *p_this )
vlc_inhibit_sys_t
*
p_sys
=
p_ih
->
p_sys
;
vlc_timer_destroy
(
p_sys
->
timer
);
if
(
p_sys
->
nullfd
!=
-
1
)
close
(
p_sys
->
nullfd
);
posix_spawnattr_destroy
(
&
p_sys
->
attr
);
posix_spawn_file_actions_destroy
(
&
p_sys
->
actions
);
free
(
p_sys
);
}
...
...
@@ -107,33 +131,15 @@ static void Inhibit( vlc_inhibit_t *p_ih, bool suspend )
/*****************************************************************************
* Execute: Spawns a process using execv()
*****************************************************************************/
static
void
Execute
(
vlc_object_t
*
p_this
,
const
char
*
const
*
ppsz_args
)
static
void
Execute
(
vlc_inhibit_t
*
p_ih
,
const
char
*
const
*
argv
)
{
pid_t
pid
=
fork
();
switch
(
pid
)
{
case
0
:
/* we're the child */
vlc_inhibit_sys_t
*
p_sys
=
p_ih
->
p_sys
;
pid_t
pid
;
if
(
posix_spawn
(
&
pid
,
argv
[
0
],
&
p_sys
->
actions
,
&
p_sys
->
attr
,
(
char
**
)
argv
,
environ
)
==
0
)
{
sigset_t
set
;
sigemptyset
(
&
set
);
pthread_sigmask
(
SIG_SETMASK
,
&
set
,
NULL
);
/* We don't want output */
if
(
(
freopen
(
"/dev/null"
,
"w"
,
stdout
)
!=
NULL
)
&&
(
freopen
(
"/dev/null"
,
"w"
,
stderr
)
!=
NULL
)
)
execv
(
ppsz_args
[
0
]
,
(
char
*
const
*
)
ppsz_args
);
/* If the file we want to execute doesn't exist we exit() */
exit
(
EXIT_FAILURE
);
}
case
-
1
:
/* we're the error */
msg_Dbg
(
p_this
,
"Couldn't fork() while launching %s"
,
ppsz_args
[
0
]
);
break
;
default:
/* we're the parent */
/* Wait for the child to exit.
* We will not deadlock because we ran "/bin/sh &" */
while
(
waitpid
(
pid
,
NULL
,
0
)
!=
pid
);
break
;
while
(
waitpid
(
pid
,
NULL
,
0
)
!=
pid
);
}
}
...
...
@@ -151,9 +157,9 @@ static void Timer( void *data )
/* http://www.jwz.org/xscreensaver/faq.html#dvd */
const
char
*
const
ppsz_xsargs
[]
=
{
"/bin/sh"
,
"-c"
,
"xscreensaver-command -deactivate &"
,
(
char
*
)
NULL
};
Execute
(
VLC_OBJECT
(
p_ih
),
ppsz_xsargs
);
Execute
(
p_ih
,
ppsz_xsargs
);
const
char
*
const
ppsz_gsargs
[]
=
{
"/bin/sh"
,
"-c"
,
"gnome-screensaver-command --poke &"
,
(
char
*
)
NULL
};
Execute
(
VLC_OBJECT
(
p_ih
),
ppsz_gsargs
);
Execute
(
p_ih
,
ppsz_gsargs
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment