Commit d19530bc authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

libvlc: remove "evil" daemon global variable and clean up

(The unlikely corner case of ENOMEM remains unhandled/unfixed.)
parent ec44ae90
......@@ -78,14 +78,6 @@
#include <assert.h>
/*****************************************************************************
* The evil global variables. We handle them with care, don't worry.
*****************************************************************************/
#if !defined(_WIN32) && !defined(__OS2__)
static bool b_daemon = false;
#endif
/*****************************************************************************
* Local prototypes
*****************************************************************************/
......@@ -210,8 +202,6 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
/* Check for daemon mode */
if( var_InheritBool( p_libvlc, "daemon" ) )
{
char *psz_pidfile = NULL;
if( daemon( 1, 0) != 0 )
{
msg_Err( p_libvlc, "Unable to fork vlc to daemon mode" );
......@@ -219,29 +209,28 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
vlc_LogDeinit (p_libvlc);
return VLC_ENOMEM;
}
b_daemon = true;
/* lets check if we need to write the pidfile */
psz_pidfile = var_CreateGetNonEmptyString( p_libvlc, "pidfile" );
if( psz_pidfile != NULL )
{
FILE *pidfile;
pid_t i_pid = getpid ();
msg_Dbg( p_libvlc, "PID is %d, writing it to %s",
i_pid, psz_pidfile );
pidfile = vlc_fopen( psz_pidfile,"w" );
char *pidfile = var_InheritString( p_libvlc, "pidfile" );
if( pidfile != NULL )
{
utf8_fprintf( pidfile, "%d", (int)i_pid );
fclose( pidfile );
FILE *stream = vlc_fopen( pidfile, "w" );
if( stream != NULL )
{
fprintf( stream, "%d", (int)getpid() );
fclose( stream );
msg_Dbg( p_libvlc, "written PID file %s", pidfile );
}
else
{
msg_Err( p_libvlc, "cannot open pid file %s for writing: %s",
psz_pidfile, vlc_strerror_c(errno) );
msg_Err( p_libvlc, "cannot write PID file %s: %s",
pidfile, vlc_strerror_c(errno) );
free( pidfile );
}
}
free( psz_pidfile );
else
{
var_Create( p_libvlc, "pidfile", VLC_VAR_STRING );
var_SetString( p_libvlc, "pidfile", "" );
}
#endif
......@@ -557,21 +546,14 @@ void libvlc_InternalCleanup( libvlc_int_t *p_libvlc )
playlist_Destroy( p_playlist );
#if !defined( _WIN32 ) && !defined( __OS2__ )
char* psz_pidfile = NULL;
if( b_daemon )
{
psz_pidfile = var_CreateGetNonEmptyString( p_libvlc, "pidfile" );
if( psz_pidfile != NULL )
{
msg_Dbg( p_libvlc, "removing pid file %s", psz_pidfile );
if( unlink( psz_pidfile ) == -1 )
char *pidfile = var_InheritString( p_libvlc, "pidfile" );
if( pidfile != NULL )
{
msg_Dbg( p_libvlc, "removing pid file %s: %s",
psz_pidfile, vlc_strerror_c(errno) );
}
}
free( psz_pidfile );
msg_Dbg( p_libvlc, "removing PID file %s", pidfile );
if( unlink( pidfile ) )
msg_Warn( p_libvlc, "cannot remove PID file %s: %s",
pidfile, vlc_strerror_c(errno) );
free( pidfile );
}
#endif
......@@ -617,24 +599,21 @@ int libvlc_InternalAddIntf( libvlc_int_t *p_libvlc, char const *psz_module )
if( !p_libvlc )
return VLC_EGENERIC;
if( !psz_module ) /* requesting the default interface */
if( psz_module == NULL ) /* requesting the default interface */
{
char *psz_interface = var_CreateGetNonEmptyString( p_libvlc, "intf" );
if( !psz_interface ) /* "intf" has not been set */
char *intf = var_InheritString( p_libvlc, "intf" );
if( intf != NULL ) /* "intf" has not been set */
free( intf );
else
{
#if !defined( _WIN32 ) && !defined( __OS2__ )
if( b_daemon )
/* Daemon mode hack.
* We prefer the dummy interface if none is specified. */
psz_module = "dummy";
char *pidfile = var_InheritString( p_libvlc, "pidfile" );
if( pidfile != NULL )
free( pidfile );
else
#endif
msg_Info( p_libvlc, "%s",
_("Running vlc with the default interface. "
"Use 'cvlc' to use vlc without interface.") );
}
free( psz_interface );
var_Destroy( p_libvlc, "intf" );
}
/* Try to create the interface */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment