]> git.sesse.net Git - vlc/blob - src/interface/main.c
The input-II. (more info by mail in about an hour)
[vlc] / src / interface / main.c
1 /*****************************************************************************
2  * main.c: main vlc source
3  * Includes the main() function for vlc. Parses command line, start interface
4  * and spawn threads.
5  *****************************************************************************
6  * Copyright (C) 1998, 1999, 2000 VideoLAN
7  *
8  * Authors:
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  * 
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include "defs.h"
29
30 #include <signal.h>                               /* SIGHUP, SIGINT, SIGKILL */
31 #include <getopt.h>                                              /* getopt() */
32 #include <stdio.h>                                              /* sprintf() */
33
34 #include <errno.h>                                                 /* ENOMEM */
35 #include <stdlib.h>                                  /* getenv(), strtol(),  */
36 #include <string.h>                                            /* strerror() */
37
38 #include "config.h"
39 #include "common.h"
40 #include "threads.h"
41 #include "mtime.h"
42 #include "tests.h"                                              /* TestMMX() */
43 #include "plugins.h"
44 #include "playlist.h"
45 #include "stream_control.h"
46 #include "input_ext-intf.h"
47
48 #include "intf_msg.h"
49 #include "interface.h"
50
51 #include "audio_output.h"
52
53 #ifdef SYS_BEOS
54 #include "beos_specific.h"
55 #endif
56
57 #include "main.h"
58
59 /*****************************************************************************
60  * Command line options constants. If something is changed here, be sure that
61  * GetConfiguration and Usage are also changed.
62  *****************************************************************************/
63
64 /* Long options return values - note that values corresponding to short options
65  * chars, and in general any regular char, should be avoided */
66 #define OPT_NOAUDIO             150
67 #define OPT_AOUT                151
68 #define OPT_STEREO              152
69 #define OPT_MONO                153
70
71 #define OPT_NOVIDEO             160
72 #define OPT_VOUT                161
73 #define OPT_DISPLAY             162
74 #define OPT_WIDTH               163
75 #define OPT_HEIGHT              164
76 #define OPT_COLOR               165
77 #define OPT_YUV                 166
78
79 #define OPT_VLANS               170
80 #define OPT_SERVER              171
81 #define OPT_PORT                172
82 #define OPT_BROADCAST           173
83
84 #define OPT_SYNCHRO             180
85
86 #define OPT_WARNING             190
87
88 /* Usage fashion */
89 #define USAGE                     0
90 #define SHORT_HELP                1
91 #define LONG_HELP                 2
92
93 /* Long options */
94 static const struct option longopts[] =
95 {
96     /*  name,               has_arg,    flag,   val */
97
98     /* General/common options */
99     {   "help",             0,          0,      'h' },
100     {   "longhelp",         0,          0,      'H' },
101     {   "version",          0,          0,      'v' },
102
103     /* Audio options */
104     {   "noaudio",          0,          0,      OPT_NOAUDIO },
105     {   "aout",             1,          0,      OPT_AOUT },
106     {   "stereo",           0,          0,      OPT_STEREO },
107     {   "mono",             0,          0,      OPT_MONO },
108
109     /* Video options */
110     {   "novideo",          0,          0,      OPT_NOVIDEO },
111     {   "vout",             1,          0,      OPT_VOUT },
112     {   "display",          1,          0,      OPT_DISPLAY },
113     {   "width",            1,          0,      OPT_WIDTH },
114     {   "height",           1,          0,      OPT_HEIGHT },
115     {   "grayscale",        0,          0,      'g' },
116     {   "color",            0,          0,      OPT_COLOR },
117     {   "yuv",              1,          0,      OPT_YUV },
118
119     /* DVD options */
120     {   "dvdaudio",         1,          0,      'a' },
121     {   "dvdchannel",       1,          0,      'c' },
122     {   "dvdsubtitle",      1,          0,      's' },
123     
124     /* Input options */
125     {   "vlans",            0,          0,      OPT_VLANS },
126     {   "server",           1,          0,      OPT_SERVER },
127     {   "port",             1,          0,      OPT_PORT },
128     {   "broadcast",        0,          0,      OPT_BROADCAST },
129
130     /* Synchro options */
131     {   "synchro",          1,          0,      OPT_SYNCHRO },
132
133     /* Interface messages */
134     {   "warning",          1,          0,      OPT_WARNING },
135     {   0,                  0,          0,      0 }
136 };
137
138 /* Short options */
139 static const char *psz_shortopts = "hHvga:s:c:";
140
141 /*****************************************************************************
142  * Global variable program_data - this is the one and only, see main.h
143  *****************************************************************************/
144 main_t *p_main;
145
146 /*****************************************************************************
147  * Local prototypes
148  *****************************************************************************/
149 static void SetDefaultConfiguration ( void );
150 static int  GetConfiguration        ( int i_argc, char *ppsz_argv[],
151                                       char *ppsz_env[] );
152 static void Usage                   ( int i_fashion );
153 static void Version                 ( void );
154
155 static void InitSignalHandler       ( void );
156 static void SignalHandler           ( int i_signal );
157 #ifdef HAVE_MMX
158        int  TestMMX                 ( void );
159 #endif
160
161 /*****************************************************************************
162  * main: parse command line, start interface and spawn threads
163  *****************************************************************************
164  * Steps during program execution are:
165  *      -configuration parsing and messages interface initialization
166  *      -opening of audio output device and some global modules
167  *      -execution of interface, which exit on error or on user request
168  *      -closing of audio output device and some global modules
169  * On error, the spawned threads are canceled, and the open devices closed.
170  *****************************************************************************/
171 int main( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
172 {
173     main_t  main_data;                      /* root of all data - see main.h */
174
175     p_main = &main_data;                       /* set up the global variable */
176
177     /*
178      * System specific initialization code
179      */
180 #ifdef SYS_BEOS
181     beos_Create();
182 #endif
183
184     /*
185      * Test if our code is likely to run on this CPU 
186      */
187 #ifdef HAVE_MMX
188     if( !TestMMX() )
189     {
190         fprintf( stderr, "Sorry, this program needs an MMX processor. "
191                          "Please run the non-MMX version.\n" );
192         return( 1 );
193     }
194 #endif
195
196     /*
197      * Initialize messages interface
198      */
199     p_main->p_msg = intf_MsgCreate();
200     if( !p_main->p_msg )                         /* start messages interface */
201     {
202         fprintf( stderr, "error: can't initialize messages interface (%s)\n",
203                 strerror(errno) );
204         return( errno );
205     }
206
207     /*
208      * Read configuration
209      */
210     if( GetConfiguration( i_argc, ppsz_argv, ppsz_env ) )  /* parse cmd line */
211     {
212         intf_MsgDestroy();
213         return( errno );
214     }
215
216     /*
217      * Initialize playlist and get commandline files
218      */
219     p_main->p_playlist = playlist_Create( );
220     if( !p_main->p_playlist )
221     {
222         intf_Msg( "Playlist initialization failed\n" );
223         intf_MsgDestroy();
224         return( errno );
225     }
226     playlist_Init( p_main->p_playlist, optind );
227
228     /*
229      * Initialize plugin bank
230      */
231     p_main->p_bank = bank_Create( );
232     if( !p_main->p_bank )
233     {
234         intf_Msg( "Plugin bank initialization failed\n" );
235         playlist_Destroy( p_main->p_playlist );
236         intf_MsgDestroy();
237         return( errno );
238     }
239     bank_Init( p_main->p_bank );
240
241     /*
242      * Initialize shared resources and libraries
243      */
244     /* FIXME: no VLANs */
245 #if 0
246     if( p_main->b_vlans && input_VlanCreate() )
247     {
248         /* On error during vlans initialization, switch off vlans */
249         intf_Msg( "Virtual LANs initialization failed : "
250                   "vlans management is deactivated\n" );
251         p_main->b_vlans = 0;
252     }
253 #endif
254
255     /*
256      * Open audio device and start aout thread
257      */
258     if( p_main->b_audio )
259     {
260         p_main->p_aout = aout_CreateThread( NULL );
261         if( p_main->p_aout == NULL )
262         {
263             /* On error during audio initialization, switch off audio */
264             intf_Msg( "Audio initialization failed : audio is deactivated\n" );
265             p_main->b_audio = 0;
266         }
267     }
268
269     /*
270      * Run interface
271      */
272     p_main->p_intf = intf_Create();
273     if( p_main->p_intf != NULL )
274     {
275         InitSignalHandler();             /* prepare signals for interception */
276
277         /*
278          * This is the main loop
279          */
280         intf_Run( p_main->p_intf );
281
282         intf_Destroy( p_main->p_intf );
283     }
284
285     /*
286      * Close audio device
287      */
288     if( p_main->b_audio )
289     {
290         aout_DestroyThread( p_main->p_aout, NULL );
291     }
292
293     /*
294      * Free shared resources and libraries
295      */
296     /* FIXME */
297 #if 0
298     if( p_main->b_vlans )
299     {
300         input_VlanDestroy();
301     }
302 #endif
303
304     /*
305      * Free plugin bank
306      */
307     bank_Destroy( p_main->p_bank );
308
309     /*
310      * Free playlist
311      */
312     playlist_Destroy( p_main->p_playlist );
313
314 #ifdef SYS_BEOS
315     /*
316      * System specific cleaning code
317      */
318     beos_Destroy();
319 #endif
320
321     /*
322      * Terminate messages interface and program
323      */
324     intf_Msg( "Program terminated.\n" );
325     intf_MsgDestroy();
326
327     return( 0 );
328 }
329
330 /*****************************************************************************
331  * main_GetIntVariable: get the int value of an environment variable
332  *****************************************************************************
333  * This function is used to read some default parameters in modules.
334  *****************************************************************************/
335 int main_GetIntVariable( char *psz_name, int i_default )
336 {
337     char *      psz_env;                                /* environment value */
338     char *      psz_end;                             /* end of parsing index */
339     long int    i_value;                                            /* value */
340
341     psz_env = getenv( psz_name );
342     if( psz_env )
343     {
344         i_value = strtol( psz_env, &psz_end, 0 );
345         if( (*psz_env != '\0') && (*psz_end == '\0') )
346         {
347             return( i_value );
348         }
349     }
350     return( i_default );
351 }
352
353 /*****************************************************************************
354  * main_GetPszVariable: get the string value of an environment variable
355  *****************************************************************************
356  * This function is used to read some default parameters in modules.
357  *****************************************************************************/
358 char * main_GetPszVariable( char *psz_name, char *psz_default )
359 {
360     char *psz_env;
361
362     psz_env = getenv( psz_name );
363     if( psz_env )
364     {
365         return( psz_env );
366     }
367     return( psz_default );
368 }
369
370 /*****************************************************************************
371  * main_PutPszVariable: set the string value of an environment variable
372  *****************************************************************************
373  * This function is used to set some default parameters in modules. The use of
374  * this function will cause some memory leak: since some systems use the pointer
375  * passed to putenv to store the environment string, it can't be freed.
376  *****************************************************************************/
377 void main_PutPszVariable( char *psz_name, char *psz_value )
378 {
379     char *psz_env;
380
381     psz_env = malloc( strlen(psz_name) + strlen(psz_value) + 2 );
382     if( psz_env == NULL )
383     {
384         intf_ErrMsg( "error: %s\n", strerror(ENOMEM) );
385     }
386     else
387     {
388         sprintf( psz_env, "%s=%s", psz_name, psz_value );
389         if( putenv( psz_env ) )
390         {
391             intf_ErrMsg( "error: %s\n", strerror(errno) );
392         }
393     }
394 }
395
396 /*****************************************************************************
397  * main_PutIntVariable: set the integer value of an environment variable
398  *****************************************************************************
399  * This function is used to set some default parameters in modules. The use of
400  * this function will cause some memory leak: since some systems use the pointer
401  * passed to putenv to store the environment string, it can't be freed.
402  *****************************************************************************/
403 void main_PutIntVariable( char *psz_name, int i_value )
404 {
405     char psz_value[ 256 ];                               /* buffer for value */
406
407     sprintf( psz_value, "%d", i_value );
408     main_PutPszVariable( psz_name, psz_value );
409 }
410
411 /* following functions are local */
412
413 /*****************************************************************************
414  * SetDefaultConfiguration: set default options
415  *****************************************************************************
416  * This function is called by GetConfiguration before command line is parsed.
417  * It sets all the default values required later by the program. At this stage,
418  * most structure are not yet allocated, so initialization must be done using
419  * environment.
420  *****************************************************************************/
421 static void SetDefaultConfiguration( void )
422 {
423     /*
424      * All features are activated by default execpted vlans
425      */
426     p_main->b_audio  = 1;
427     p_main->b_video  = 1;
428     p_main->b_vlans  = 0;
429 }
430
431 /*****************************************************************************
432  * GetConfiguration: parse command line
433  *****************************************************************************
434  * Parse command line and configuration file for configuration. If the inline
435  * help is requested, the function Usage() is called and the function returns
436  * -1 (causing main() to exit). The messages interface is initialized at this
437  * stage, but most structures are not allocated, so only environment should
438  * be used.
439  *****************************************************************************/
440 static int GetConfiguration( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
441 {
442     int c, i_opt;
443     char * p_pointer;
444
445     /* Set default configuration and copy arguments */
446     p_main->i_argc    = i_argc;
447     p_main->ppsz_argv = ppsz_argv;
448     p_main->ppsz_env  = ppsz_env;
449     SetDefaultConfiguration();
450
451     intf_MsgImm( COPYRIGHT_MESSAGE "\n" );
452
453     /* Get the executable name (similar to the basename command) */
454     p_main->psz_arg0 = p_pointer = ppsz_argv[ 0 ];
455     while( *p_pointer )
456     {
457         if( *p_pointer == '/' )
458         {
459             p_main->psz_arg0 = ++p_pointer;
460         }
461         else
462         {
463             ++p_pointer;
464         }
465     }
466
467     /* Parse command line options */
468     opterr = 0;
469     while( ( c = getopt_long( i_argc, ppsz_argv, psz_shortopts, longopts, 0 ) ) != EOF )
470     {
471         switch( c )
472         {
473         /* General/common options */
474         case 'h':                                              /* -h, --help */
475             Usage( SHORT_HELP );
476             return( -1 );
477             break;
478         case 'H':                                          /* -H, --longhelp */
479             Usage( LONG_HELP );
480             return( -1 );
481             break;
482         case 'v':                                           /* -v, --version */
483             Version();
484             return( -1 );
485             break;
486
487         /* Audio options */
488         case OPT_NOAUDIO:                                       /* --noaudio */
489             p_main->b_audio = 0;
490             break;
491         case OPT_AOUT:                                             /* --aout */
492             main_PutPszVariable( AOUT_METHOD_VAR, optarg );
493             break;
494         case OPT_STEREO:                                         /* --stereo */
495             main_PutIntVariable( AOUT_STEREO_VAR, 1 );
496             break;
497         case OPT_MONO:                                             /* --mono */
498             main_PutIntVariable( AOUT_STEREO_VAR, 0 );
499             break;
500
501         /* Video options */
502         case OPT_NOVIDEO:                                       /* --novideo */
503             p_main->b_video = 0;
504             break;
505         case OPT_VOUT:                                             /* --vout */
506             main_PutPszVariable( VOUT_METHOD_VAR, optarg );
507             break;
508         case OPT_DISPLAY:                                       /* --display */
509             main_PutPszVariable( VOUT_DISPLAY_VAR, optarg );
510             break;
511         case OPT_WIDTH:                                           /* --width */
512             main_PutPszVariable( VOUT_WIDTH_VAR, optarg );
513             break;
514         case OPT_HEIGHT:                                         /* --height */
515             main_PutPszVariable( VOUT_HEIGHT_VAR, optarg );
516             break;
517
518         case 'g':                                         /* -g, --grayscale */
519             main_PutIntVariable( VOUT_GRAYSCALE_VAR, 1 );
520             break;
521         case OPT_COLOR:                                           /* --color */
522             main_PutIntVariable( VOUT_GRAYSCALE_VAR, 0 );
523             break;
524         case OPT_YUV:                                               /* --yuv */
525             main_PutPszVariable( YUV_METHOD_VAR, optarg );
526             break;
527
528             /* FIXME */
529 #if 0
530         /* DVD options */
531         case 'a':
532             if ( ! strcmp(optarg, "mpeg") )
533                 main_PutIntVariable( INPUT_DVD_AUDIO_VAR, REQUESTED_MPEG );
534             else if ( ! strcmp(optarg, "lpcm") )
535                 main_PutIntVariable( INPUT_DVD_AUDIO_VAR, REQUESTED_LPCM );
536             else if ( ! strcmp(optarg, "off") )
537                 main_PutIntVariable( INPUT_DVD_AUDIO_VAR, REQUESTED_NOAUDIO );
538             else
539                 main_PutIntVariable( INPUT_DVD_AUDIO_VAR, REQUESTED_AC3 );
540             break;
541 #endif
542         case 'c':
543             main_PutIntVariable( INPUT_DVD_CHANNEL_VAR, atoi(optarg) );
544             break;
545         case 's':
546             main_PutIntVariable( INPUT_DVD_SUBTITLE_VAR, atoi(optarg) );
547             break;
548
549         /* Input options */
550         case OPT_VLANS:                                           /* --vlans */
551             p_main->b_vlans = 1;
552             break;
553         case OPT_SERVER:                                         /* --server */
554             main_PutPszVariable( INPUT_SERVER_VAR, optarg );
555             break;
556         case OPT_PORT:                                             /* --port */
557             main_PutPszVariable( INPUT_PORT_VAR, optarg );
558             break;
559         case OPT_BROADCAST:                                   /* --broadcast */
560             main_PutIntVariable( INPUT_BROADCAST_VAR, 1 );
561             break;
562
563         /* Synchro options */
564         case OPT_SYNCHRO:                                      
565             main_PutPszVariable( VPAR_SYNCHRO_VAR, optarg );
566             break;
567
568         /* Interface warning messages level */
569         case OPT_WARNING:                                       /* --warning */
570             main_PutIntVariable( INTF_WARNING_VAR, atoi(optarg) );
571             break;
572             
573         /* Internal error: unknown option */
574         case '?':
575         default:
576             intf_ErrMsg( "intf error: unknown option `%s'\n", ppsz_argv[optind - 1] );
577             Usage( USAGE );
578             return( EINVAL );
579             break;
580         }
581     }
582
583     /* Parse command line parameters - no check is made for these options */
584     for( i_opt = optind; i_opt < i_argc; i_opt++ )
585     {
586         putenv( ppsz_argv[ i_opt ] );
587     }
588     return( 0 );
589 }
590
591 /*****************************************************************************
592  * Usage: print program usage
593  *****************************************************************************
594  * Print a short inline help. Message interface is initialized at this stage.
595  *****************************************************************************/
596 static void Usage( int i_fashion )
597 {
598     /* Usage */
599     intf_Msg( "Usage: %s [options] [parameters] [file]...\n",
600               p_main->psz_arg0 );
601
602     if( i_fashion == USAGE )
603     {
604         intf_Msg( "Try `%s --help' for more information.\n",
605                   p_main->psz_arg0 );
606         return;
607     }
608
609     /* Options */
610     intf_Msg( "\n"
611               "Options:\n"
612               "      --noaudio                  \tdisable audio\n"
613               "      --aout <plugin>            \taudio output method\n"
614               "      --stereo, --mono           \tstereo/mono audio\n"
615               "\n"
616               "      --novideo                  \tdisable video\n"
617               "      --vout <plugin>            \tvideo output method\n"
618               "      --display <display>        \tdisplay string\n"
619               "      --width <w>, --height <h>  \tdisplay dimensions\n"
620               "  -g, --grayscale                \tgrayscale output\n"
621               "      --color                    \tcolor output\n"
622               "\n"
623               "  -a, --dvdaudio <type>          \tchoose DVD audio type\n"
624               "  -c, --dvdchannel <channel>     \tchoose DVD audio channel\n"
625               "  -s, --dvdsubtitle <channel>    \tchoose DVD subtitle channel\n"
626               "\n"
627               "      --vlans                    \tenable vlans\n"
628               "      --server <host>            \tvideo server address\n"
629               "      --port <port>              \tvideo server port\n"
630               "      --broadcast                \tlisten to a broadcast\n"
631               "\n"
632               "      --synchro <type>           \tforce synchro algorithm\n"
633               "\n"
634               "      --warning <level>          \tdisplay warning messages\n"
635               "\n"
636               "  -h, --help                     \tprint help and exit\n"
637               "  -H, --longhelp                 \tprint long help and exit\n"
638               "  -v, --version                  \toutput version information and exit\n" );
639
640     if( i_fashion == SHORT_HELP )
641         return;
642
643     /* Interface parameters */
644     intf_Msg( "\n"
645               "Interface parameters:\n"
646               "  " INTF_INIT_SCRIPT_VAR "=<filename>               \tinitialization script\n"
647               "  " INTF_CHANNELS_VAR "=<filename>            \tchannels list\n"
648               "  " INTF_WARNING_VAR "=<level>                \twarning level\n" );
649
650     /* Audio parameters */
651     intf_Msg( "\n"
652               "Audio parameters:\n"
653               "  " AOUT_METHOD_VAR "=<method name>        \taudio method\n"
654               "  " AOUT_DSP_VAR "=<filename>              \tdsp device path\n"
655               "  " AOUT_STEREO_VAR "={1|0}                \tstereo or mono output\n"
656               "  " AOUT_RATE_VAR "=<rate>             \toutput rate\n" );
657
658     /* Video parameters */
659     intf_Msg( "\n"
660               "Video parameters:\n"
661               "  " VOUT_METHOD_VAR "=<method name>        \tdisplay method\n"
662               "  " VOUT_DISPLAY_VAR "=<display name>      \tdisplay used\n"
663               "  " VOUT_WIDTH_VAR "=<width>               \tdisplay width\n"
664               "  " VOUT_HEIGHT_VAR "=<height>             \tdislay height\n"
665               "  " VOUT_FB_DEV_VAR "=<filename>           \tframebuffer device path\n"
666               "  " VOUT_GRAYSCALE_VAR "={1|0}             \tgrayscale or color output\n" );
667
668     /* DVD parameters */
669     intf_Msg( "\n"
670               "DVD parameters:\n"
671               "  " INPUT_DVD_AUDIO_VAR "={ac3|lpcm|mpeg|off} \taudio type\n"
672               "  " INPUT_DVD_CHANNEL_VAR "=[0-15]            \taudio channel\n"
673               "  " INPUT_DVD_SUBTITLE_VAR "=[0-31]           \tsubtitle channel\n" );
674
675     /* Input parameters */
676     intf_Msg( "\n"
677               "Input parameters:\n"
678               "  " INPUT_SERVER_VAR "=<hostname>          \tvideo server\n"
679               "  " INPUT_PORT_VAR "=<port>            \tvideo server port\n"
680               "  " INPUT_IFACE_VAR "=<interface>          \tnetwork interface\n"
681               "  " INPUT_BROADCAST_VAR "={1|0}            \tbroadcast mode\n"
682               "  " INPUT_VLAN_SERVER_VAR "=<hostname>     \tvlan server\n"
683               "  " INPUT_VLAN_PORT_VAR "=<port>           \tvlan server port\n" );
684
685     /* Synchro parameters */
686     intf_Msg( "\n"
687               "Synchro parameters:\n"
688               "  " VPAR_SYNCHRO_VAR "={I|I+|IP|IP+|IPB}   \tsynchro algorithm\n");
689 }
690
691 /*****************************************************************************
692  * Version: print complete program version
693  *****************************************************************************
694  * Print complete program version and build number.
695  *****************************************************************************/
696 static void Version( void )
697 {
698     intf_Msg( VERSION_MESSAGE
699               "This program comes with NO WARRANTY, to the extent permitted by law.\n"
700               "You may redistribute it under the terms of the GNU General Public License;\n"
701               "see the file named COPYING for details.\n"
702               "Written by the VideoLAN team at Ecole Centrale, Paris.\n" );
703
704 }
705
706 /*****************************************************************************
707  * InitSignalHandler: system signal handler initialization
708  *****************************************************************************
709  * Set the signal handlers. SIGTERM is not intercepted, because we need at
710  * at least a method to kill the program when all other methods failed, and
711  * when we don't want to use SIGKILL.
712  *****************************************************************************/
713 static void InitSignalHandler( void )
714 {
715     /* Termination signals */
716     signal( SIGHUP,  SignalHandler );
717     signal( SIGINT,  SignalHandler );
718     signal( SIGQUIT, SignalHandler );
719 }
720
721 /*****************************************************************************
722  * SignalHandler: system signal handler
723  *****************************************************************************
724  * This function is called when a signal is received by the program. It tries to
725  * end the program in a clean way.
726  *****************************************************************************/
727 static void SignalHandler( int i_signal )
728 {
729     /* Once a signal has been trapped, the termination sequence will be armed and
730      * following signals will be ignored to avoid sending messages to an interface
731      * having been destroyed */
732     signal( SIGHUP,  SIG_IGN );
733     signal( SIGINT,  SIG_IGN );
734     signal( SIGQUIT, SIG_IGN );
735
736     /* Acknowledge the signal received */
737     intf_ErrMsgImm("intf: signal %d received\n", i_signal );
738
739     /* Try to terminate everything - this is done by requesting the end of the
740      * interface thread */
741     p_main->p_intf->b_die = 1;
742 }
743