]> git.sesse.net Git - vlc/blobdiff - bin/vlc.c
Call libvlc_set_exit_handler() before the interfaces and playlist start
[vlc] / bin / vlc.c
index ef3a4b511e7ec3db1b57d38516f9d1fa02ecde4a..7e775d384b3e5ebaaa0e3aaaf9a15bc337d5b8c2 100644 (file)
--- a/bin/vlc.c
+++ b/bin/vlc.c
@@ -74,6 +74,11 @@ static void vlc_kill (void *data)
     pthread_kill (*ps, SIGTERM);
 }
 
+static void exit_timeout (int signum)
+{
+    (void) signum;
+    signal (SIGINT, SIG_DFL);
+}
 
 /*****************************************************************************
  * main: parse command line, start interface and spawn threads.
@@ -198,6 +203,10 @@ int main( int i_argc, const char *ppsz_argv[] )
     if (vlc == NULL)
         goto out;
 
+    pthread_t self = pthread_self ();
+    libvlc_set_exit_handler (vlc, vlc_kill, &self);
+    libvlc_set_user_agent (vlc, "VLC media player", NULL);
+
 #if !defined (HAVE_MAEMO) && !defined __APPLE__
     libvlc_add_intf (vlc, "globalhotkeys,none");
 #endif
@@ -206,10 +215,6 @@ int main( int i_argc, const char *ppsz_argv[] )
 
     libvlc_playlist_play (vlc, -1, 0, NULL);
 
-    /* Wait for a termination signal */
-    pthread_t self = pthread_self ();
-    libvlc_set_exit_handler (vlc, vlc_kill, &self);
-
     if (signal_ignored (SIGHUP)) /* <- needed to handle nohup properly */
         sigdelset (&set, SIGHUP);
     sigdelset (&set, SIGPIPE);
@@ -219,6 +224,15 @@ int main( int i_argc, const char *ppsz_argv[] )
         sigwait (&set, &signum);
     while (signum == SIGCHLD);
 
+    /* Restore default signal behaviour after 3 seconds */
+    sigemptyset (&set);
+    sigaddset (&set, SIGINT);
+    sigaddset (&set, SIGALRM);
+    signal (SIGINT, SIG_IGN);
+    signal (SIGALRM, exit_timeout);
+    pthread_sigmask (SIG_UNBLOCK, &set, NULL);
+    alarm (3);
+
     /* Cleanup */
 out:
     if (vlc != NULL)