Changeset 1d58919125812d569c23bde687e42fca86858e33

Show
Ignore:
Timestamp:
03/01/07 18:52:11 (2 years ago)
Author:
Rémi Denis-Courmont <rem@videolan.org>
git-committer:
Rémi Denis-Courmont <rem@videolan.org> 1172771531 +0000
git-parent:

[14c5e914ffb2ca51676a2d6c6b081a8e324fe47e]

git-author:
Rémi Denis-Courmont <rem@videolan.org> 1172771531 +0000
Message:

Fix abortion if killing signals are re-used.
Of course, VLC has no bugs, so you never need to abort it that way,
so that this fixes nothing.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • include/vlc_threads.h

    r65d2183 r1d58919  
    5757#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )  /* pthreads (like Linux & BSD) */ 
    5858#   define LIBVLC_USE_PTHREAD 1 
     59#   define _APPLE_C_SOURCE    1 /* Proper pthread semantics on OSX */ 
    5960 
    6061#   include <pthread.h> 
  • src/vlc.c

    reeb6783 r1d58919  
    2828#include "config.h" 
    2929 
     30#include <vlc/vlc.h> 
    3031#include <stdio.h>                                              /* fprintf() */ 
    3132#include <stdlib.h>                                  /* putenv(), strtol(),  */ 
    32 #ifdef HAVE_SIGNAL_H 
    33 #   include <signal.h>                            /* SIGHUP, SIGINT, SIGKILL */ 
    34 #endif 
    35 #ifdef HAVE_TIME_H 
    36 #   include <time.h>                                               /* time() */ 
    37 #endif 
    38 #ifdef HAVE_PTHREAD_H 
    39 #   include <pthread.h> 
    40 #endif 
    41  
    42 #include <vlc/vlc.h> 
    43  
     33 
     34 
     35/***************************************************************************** 
     36 * Local prototypes. 
     37 *****************************************************************************/ 
    4438#ifdef WIN32 
    4539#include <windows.h> 
    4640extern void __wgetmainargs(int *argc, wchar_t ***wargv, wchar_t ***wenviron, 
    4741                           int expand_wildcards, int *startupinfo); 
    48 #endif 
    49  
    50 /***************************************************************************** 
    51  * Local prototypes. 
    52  *****************************************************************************/ 
    53 #if !defined(WIN32) && !defined(UNDER_CE) 
    54 static void *SigHandler  ( void *set ); 
     42#else 
     43 
     44# include <signal.h> 
     45# include <time.h> 
     46# include <pthread.h> 
     47# include <stdbool.h> 
     48 
     49static struct 
     50
     51    bool flag; 
     52    pthread_mutex_t lock; 
     53} live = { true, PTHREAD_MUTEX_INITIALIZER }; 
     54 
     55static void *SigHandler (void *set); 
    5556#endif 
    5657 
     
    172173    i_ret = VLC_AddIntf( 0, NULL, VLC_TRUE, VLC_TRUE ); 
    173174 
     175    /* Finish the threads */ 
     176    VLC_CleanUp( 0 ); 
     177 
     178    /* Destroy the libvlc structure */ 
     179    VLC_Destroy( 0 ); 
     180 
    174181#if !defined(WIN32) && !defined(UNDER_CE) 
    175182    pthread_cancel (sigth); 
    176183    pthread_join (sigth, NULL); 
    177184#endif 
    178  
    179     /* Finish the threads */ 
    180     VLC_CleanUp( 0 ); 
    181  
    182     /* Destroy the libvlc structure */ 
    183     VLC_Destroy( 0 ); 
    184185 
    185186    return i_ret; 
     
    193194 * It tries to end the program in a clean way. 
    194195 *****************************************************************************/ 
    195 static void *SigHandler( void *data
     196static void *SigHandler (void *data
    196197{ 
    197198    const sigset_t *set = (sigset_t *)data; 
     
    209210 
    210211        pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &state); 
    211         if( !b_die
     212        if (!b_die
    212213        { 
    213214            b_die = VLC_TRUE; 
    214             abort_time = time( NULL ); 
    215  
    216             fprintf( stderr, "signal %d received, terminating vlc - do it " 
    217                             "again in case it gets stuck\n", i_signal ); 
     215            abort_time = time (NULL); 
     216 
     217            fprintf (stderr, "signal %d received, terminating vlc - do it " 
     218                            "again in case it gets stuck\n", i_signal); 
    218219 
    219220            /* Acknowledge the signal received */ 
    220             VLC_Die( 0 ); 
     221            pthread_mutex_lock (&live.lock); 
     222            if (live.flag) 
     223            { 
     224                VLC_Die (0); 
     225                live.flag = false; 
     226            } 
     227            pthread_mutex_unlock (&live.lock); 
    221228        } 
    222229        else if( time( NULL ) > abort_time + 2 ) 
     
    224231            /* If user asks again 1 or 2 seconds later, die badly */ 
    225232            pthread_sigmask (SIG_UNBLOCK, set, NULL); 
    226             fprintf( stderr, "user insisted too much, dying badly\n" ); 
    227             abort(); 
     233            fprintf (stderr, "user insisted too much, dying badly\n"); 
     234            abort (); 
    228235        } 
    229236        pthread_setcancelstate (state, NULL);