]> git.sesse.net Git - vlc/commitdiff
support for creating pid files when going daemon mode.
authorPavlov Konstantin <thresh@videolan.org>
Fri, 30 Jun 2006 16:34:46 +0000 (16:34 +0000)
committerPavlov Konstantin <thresh@videolan.org>
Fri, 30 Jun 2006 16:34:46 +0000 (16:34 +0000)
Someone should really review it as it is my first experience in C.

include/main.h
src/libvlc.c
src/libvlc.h

index 55375520cb04e4d766db5e4eb55e5cc85e4d251d..495f75fd8bae65ecf50673425221a64f3c3273b1 100644 (file)
@@ -92,6 +92,7 @@ struct vlc_t
     char *                 psz_homedir;           /* configuration directory */
     char *                 psz_userdir;             /* user's home directory */
     char *                 psz_configfile;        /* location of config file */
+    char *                 psz_pidfile;
 
     /* Fast memcpy plugin used */
     module_t *             p_memcpy_module;
index 9e7d2bdd0a3ef17bc2c83acc1f65700bbf841dd8..ffffed9166e21abde08f8776ccfd65807ee27ba3 100644 (file)
@@ -419,6 +419,32 @@ 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 */
+               p_vlc->psz_pidfile = config_GetPsz( p_vlc, "pidfile" );
+
+               msg_Dbg( p_vlc, "p_vlc->psz_pidfile is %s", p_vlc->psz_pidfile );
+
+               if( p_vlc->psz_pidfile != NULL )
+               {
+                       pid_t i_pid;
+                       FILE *pidfile;
+                       
+                       i_pid = getpid();
+
+                       msg_Dbg( p_vlc, "our PID is %d, writing it to %s", i_pid, p_vlc->psz_pidfile );
+                       
+                       pidfile = utf8_fopen( p_vlc->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", p_vlc->psz_pidfile, strerror(errno) );
+                       }
+        }
+
 #else
         pid_t i_pid;
 
index 40b6666bea4e3ab43f7e777a1ab7048834617b4e..c7efc1ce2e1af76c69224ce22ccd015a0cdd4f46 100644 (file)
@@ -835,6 +835,10 @@ static char *ppsz_clock_descriptions[] =
 #define DAEMON_LONGTEXT N_( \
      "Runs VLC as a background daemon process.")
 
+#define PIDFILE_TEXT N_("Write process id to file")
+#define PIDFILE_LONGTEXT N_( \
+       "Writes proccess id into specified file.")
+
 #define FILE_LOG_TEXT N_( "Log to file" )
 #define FILE_LOG_LONGTEXT N_( \
     "Log all VLC messages to a text file." )
@@ -1591,6 +1595,9 @@ vlc_module_begin();
 #if !defined(WIN32)
     add_bool( "daemon", 0, NULL, DAEMON_TEXT, DAEMON_LONGTEXT, VLC_TRUE );
         change_short('d');
+
+    add_string( "pidfile", NULL, NULL, PIDFILE_TEXT, PIDFILE_LONGTEXT,
+                                       VLC_FALSE );
 #endif
 
     add_bool( "file-logging", VLC_FALSE, NULL, FILE_LOG_TEXT, FILE_LOG_LONGTEXT,