]> git.sesse.net Git - vlc/blobdiff - src/libvlc.c
Fix stats collecting
[vlc] / src / libvlc.c
index 9b7a7dbff15281c91e003378e59a06b1e2862068..077648b3a02ab482a227f9ce8ba95ae9d67ebb81 100644 (file)
@@ -419,6 +419,33 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
 
         p_vlc->p_libvlc->b_daemon = VLC_TRUE;
 
+        /* lets check if we need to write the pidfile */
+        char * psz_pidfile = config_GetPsz( p_vlc, "pidfile" );
+        
+        msg_Dbg( p_vlc, "psz_pidfile is %s", psz_pidfile );
+        
+        if( psz_pidfile != NULL )
+        {
+            FILE *pidfile;
+            pid_t i_pid = getpid ();
+            
+            msg_Dbg( p_vlc, "our PID is %d, writing it to %s", i_pid, psz_pidfile );
+            
+            pidfile = utf8_fopen( psz_pidfile,"w" );
+            if( pidfile != NULL )
+            {
+                utf8_fprintf( pidfile, "%d", (int)i_pid );
+                fclose( pidfile );
+            }
+            else
+            {
+                msg_Err( p_vlc, "Cannot open pid file for writing: %s, error: %s", 
+                        psz_pidfile, strerror(errno) );
+            }
+        }
+
+        free( psz_pidfile );
+
 #else
         pid_t i_pid;
 
@@ -686,7 +713,9 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
     }
 
     libvlc.b_stats = config_GetInt( p_vlc, "stats" );
-    libvlc.p_stats = NULL;
+    libvlc.i_timers = 0;
+    libvlc.pp_timers = NULL;
+    vlc_mutex_init( p_vlc, &libvlc.timer_lock );
 
     /*
      * Initialize hotkey handling
@@ -887,7 +916,6 @@ int VLC_CleanUp( int i_object )
     vout_thread_t      * p_vout;
     aout_instance_t    * p_aout;
     announce_handler_t * p_announce;
-    stats_handler_t    * p_stats;
     vlc_t *p_vlc = vlc_current_object( i_object );
 
     /* Check that the handle is valid */
@@ -942,14 +970,8 @@ int VLC_CleanUp( int i_object )
         aout_Delete( p_aout );
     }
 
-    while( ( p_stats = vlc_object_find( p_vlc, VLC_OBJECT_STATS, FIND_CHILD) ))
-    {
-        stats_TimersDumpAll( p_vlc );
-        stats_HandlerDestroy( p_stats );
-        vlc_object_detach( (vlc_object_t*) p_stats );
-        vlc_object_release( (vlc_object_t *)p_stats );
-        // TODO: Delete it
-    }
+    stats_TimersDumpAll( p_vlc );
+    stats_TimersClean( p_vlc );
 
     /*
      * Free announce handler(s?)