]> git.sesse.net Git - vlc/blobdiff - src/libvlc.c
* src/libvlc.c, include/vlc_interface.h: don't open a win32 console when using a...
[vlc] / src / libvlc.c
index a93bbcdc12bf1695fcbe862b74536b5291c820f9..8164fa2ef262b476490912bb7d18b72fb7036fa8 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Authors: Vincent Seguin <seguin@via.ecp.fr>
  *          Samuel Hocevar <sam@zoy.org>
- *          Gildas Bazin <gbazin@netcourrier.com>
+ *          Gildas Bazin <gbazin@videolan.org>
  *          Derk-Jan Hartman <hartman at videolan dot org>
  *
  * This program is free software; you can redistribute it and/or modify
 #   include <locale.h>
 #endif
 
+#ifdef HAVE_HAL
+#   include <hal/libhal.h>
+#endif
+
 #include "vlc_cpu.h"                                        /* CPU detection */
 #include "os_specific.h"
 
@@ -103,6 +107,8 @@ static int  ConsoleWidth  ( void );
 static int  VerboseCallback( vlc_object_t *, char const *,
                              vlc_value_t, vlc_value_t, void * );
 
+static void InitDeviceValues( vlc_t * );
+
 /*****************************************************************************
  * vlc_current_object: return the current object.
  *****************************************************************************
@@ -346,7 +352,17 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
 #ifndef WIN32
     if( config_GetInt( p_vlc, "daemon" ) )
     {
-        pid_t i_pid = 0;
+#if HAVE_DAEMON
+        if( daemon( 0, 0) != 0 )
+        {
+            msg_Err( p_vlc, "Unable to fork vlc to daemon mode" );
+            b_exit = VLC_TRUE;
+        }
+
+        p_vlc->p_libvlc->b_daemon = VLC_TRUE;
+
+#else
+        pid_t i_pid;
 
         if( ( i_pid = fork() ) < 0 )
         {
@@ -363,12 +379,13 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
         {
             /* We are the child */
             msg_Dbg( p_vlc, "daemon spawned" );
-            close( 0 );
-            close( 1 );
-            close( 2 );
+            close( STDIN_FILENO );
+            close( STDOUT_FILENO );
+            close( STDERR_FILENO );
 
             p_vlc->p_libvlc->b_daemon = VLC_TRUE;
         }
+#endif
     }
 #endif
 
@@ -402,10 +419,10 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
         /* Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
         msg_Dbg( p_vlc, "translation test: code is \"%s\"", _("C") );
 
-        textdomain( PACKAGE );
+        textdomain( PACKAGE_NAME );
 
 #if defined( ENABLE_UTF8 )
-        bind_textdomain_codeset( PACKAGE, "UTF-8" );
+        bind_textdomain_codeset( PACKAGE_NAME, "UTF-8" );
 #endif
 
         module_EndBank( p_vlc );
@@ -488,6 +505,11 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
         return VLC_EEXIT;
     }
 
+    /*
+     * Init device values
+     */
+    InitDeviceValues( p_vlc );
+
     /*
      * Override default configuration with config file settings
      */
@@ -969,7 +991,7 @@ int VLC_VariableSet( int i_object, char const *psz_var, vlc_value_t value )
 /*****************************************************************************
  * VLC_VariableGet: get a vlc variable
  *****************************************************************************/
-int VLC_Get( int i_object, char const *psz_var, vlc_value_t *p_value )
+int VLC_VariableGet( int i_object, char const *psz_var, vlc_value_t *p_value )
 {
     vlc_t *p_vlc = vlc_current_object( i_object );
     int i_ret;
@@ -979,7 +1001,7 @@ int VLC_Get( int i_object, char const *psz_var, vlc_value_t *p_value )
         return VLC_ENOOBJ;
     }
 
-    i_ret = var_Get( p_vlc, psz_var, p_value );
+    i_ret = var_Get( p_vlc , psz_var, p_value );
 
     if( i_object ) vlc_object_release( p_vlc );
     return i_ret;
@@ -1747,17 +1769,17 @@ static void SetLanguage ( char const *psz_lang )
               "locale" );
     psz_path = psz_tmp;
 #endif
-    if( !bindtextdomain( PACKAGE, psz_path ) )
+    if( !bindtextdomain( PACKAGE_NAME, psz_path ) )
     {
         fprintf( stderr, "warning: no domain %s in directory %s\n",
-                 PACKAGE, psz_path );
+                 PACKAGE_NAME, psz_path );
     }
 
     /* Set the default domain */
-    textdomain( PACKAGE );
+    textdomain( PACKAGE_NAME );
 
 #if defined( ENABLE_UTF8 )
-    bind_textdomain_codeset( PACKAGE, "UTF-8" );
+    bind_textdomain_codeset( PACKAGE_NAME, "UTF-8" );
 #endif
 
 #endif
@@ -2146,11 +2168,15 @@ static void Version( void )
 static void ShowConsole( void )
 {
 #   ifndef UNDER_CE
+
+    if( getenv( "PWD" ) && getenv( "PS1" ) ) return; /* cygwin shell */
+
     AllocConsole();
     freopen( "CONOUT$", "w", stdout );
     freopen( "CONOUT$", "w", stderr );
     freopen( "CONIN$", "r", stdin );
 #   endif
+
     return;
 }
 #endif
@@ -2206,3 +2232,51 @@ static int VerboseCallback( vlc_object_t *p_this, const char *psz_variable,
     }
     return VLC_SUCCESS;
 }
+
+/*****************************************************************************
+ * InitDeviceValues: initialize device values
+ *****************************************************************************
+ * This function inits the dvd, vcd and cd-audio values
+ *****************************************************************************/
+static void InitDeviceValues( vlc_t *p_vlc )
+{
+#ifdef HAVE_HAL
+    LibHalContext * ctx;
+    int i, i_devices;
+    char **devices;
+    char *block_dev;
+    dbus_bool_t b_dvd;
+
+    if( ( ctx = hal_initialize( NULL, FALSE ) ) )
+    {
+        if( ( devices = hal_get_all_devices( ctx, &i_devices ) ) )
+        {
+            for( i = 0; i < i_devices; i++ )
+            {
+                if( !hal_device_property_exists( ctx, devices[ i ],
+                                                "storage.cdrom.dvd" ) )
+                {
+                    continue;
+                }
+
+                b_dvd = hal_device_get_property_bool( ctx, devices[ i ],
+                                                      "storage.cdrom.dvd" );
+                block_dev = hal_device_get_property_string( ctx, devices[ i ],
+                                                            "block.device" );
+
+                if( b_dvd )
+                {
+                    config_PutPsz( p_vlc, "dvd", block_dev );
+                }
+
+                config_PutPsz( p_vlc, "vcd", block_dev );
+                config_PutPsz( p_vlc, "cd-audio", block_dev );
+
+                hal_free_string( block_dev );
+            }
+        }
+
+        hal_shutdown( ctx );
+    }
+#endif
+}