]> git.sesse.net Git - vlc/commitdiff
retry on failure to connect to rc-unix socket. Patch by Greg Farrell (greg a lincor...
authorFelix Paul Kühne <fkuehne@videolan.org>
Thu, 9 Nov 2006 11:39:27 +0000 (11:39 +0000)
committerFelix Paul Kühne <fkuehne@videolan.org>
Thu, 9 Nov 2006 11:39:27 +0000 (11:39 +0000)
modules/control/rc.c

index 137164404410d9a638ea252dccab2a82a2fcb86f..8fa4b3b31367573e56e5695a6272973f1971287f 100644 (file)
@@ -167,6 +167,10 @@ void __msg_rc( intf_thread_t *p_intf, const char *psz_fmt, ... )
 #define UNIX_LONGTEXT N_("Accept commands over a Unix socket rather than " \
                          "stdin." )
 
+#define OVERWRITE_TEXT N_("Over-write UNIX socket")
+#define OVERWRITE_LONGTEXT N_("If unable to bind RC interface to the specified " \
+                        " UNIX socket will attempt to unlink it then retry." )
+
 #define HOST_TEXT N_("TCP command input")
 #define HOST_LONGTEXT N_("Accept commands over a socket rather than stdin. " \
             "You can set the address and port the interface will bind to." )
@@ -191,6 +195,7 @@ vlc_module_begin();
 #endif
     add_string( "rc-unix", 0, NULL, UNIX_TEXT, UNIX_LONGTEXT, VLC_TRUE );
     add_string( "rc-host", 0, NULL, HOST_TEXT, HOST_LONGTEXT, VLC_TRUE );
+    add_bool( "rc-overwrite", 0, NULL, OVERWRITE_TEXT, OVERWRITE_LONGTEXT, VLC_TRUE );
 
 #ifdef WIN32
     add_bool( "rc-quiet", 0, NULL, QUIET_TEXT, QUIET_LONGTEXT, VLC_FALSE );
@@ -221,7 +226,10 @@ static int Activate( vlc_object_t *p_this )
     psz_unix_path = config_GetPsz( p_intf, "rc-unix" );
     if( psz_unix_path )
     {
-        int i_socket;
+        int i_socket, i_overwrite;
+
+       i_overwrite = config_GetInt( p_intf, "rc-overwrite" );
+
 
 #if !defined(AF_LOCAL) || defined(WIN32)
         msg_Warn( p_intf, "your OS doesn't support filesystem sockets" );
@@ -249,11 +257,22 @@ static int Activate( vlc_object_t *p_this )
         if( (i_ret = bind( i_socket, (struct sockaddr*)&addr,
                            sizeof(struct sockaddr_un) ) ) < 0 )
         {
-            msg_Warn( p_intf, "couldn't bind socket to address: %s",
-                      strerror(errno) );
-            free( psz_unix_path );
-            net_Close( i_socket );
-            return VLC_EGENERIC;
+           if( i_overwrite )
+            {
+                msg_Warn( p_intf, "Found old UNIX socket: %s, deleting and re-trying", psz_unix_path );
+               unlink( psz_unix_path ); 
+            }
+           
+            if( !i_overwrite || bind( i_socket, (struct sockaddr*)&addr,
+                           sizeof(struct sockaddr_un) ) < 0 )
+            {
+            
+                msg_Warn( p_intf, "couldn't bind socket to address: %s",
+                           strerror(errno) );
+                free( psz_unix_path );
+                net_Close( i_socket );
+                return VLC_EGENERIC;
+            }
         }
 
         if( ( i_ret = listen( i_socket, 1 ) ) < 0 )