1 /*****************************************************************************
2 * vlc.c: the VLC player
3 *****************************************************************************
4 * Copyright (C) 1998-2008 the VideoLAN team
7 * Authors: Vincent Seguin <seguin@via.ecp.fr>
8 * Samuel Hocevar <sam@zoy.org>
9 * Gildas Bazin <gbazin@videolan.org>
10 * Derk-Jan Hartman <hartman at videolan dot org>
11 * Lots of other people, see the libvlc AUTHORS file
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26 *****************************************************************************/
39 extern void LocaleFree (const char *);
40 extern char *FromLocale (const char *);
47 /*****************************************************************************
48 * main: parse command line, start interface and spawn threads.
49 *****************************************************************************/
50 int main( int i_argc, const char *ppsz_argv[] )
54 setlocale (LC_ALL, "");
57 /* This clutters OSX GUI error logs */
58 fprintf( stderr, "VLC media player %s\n", libvlc_get_version() );
63 /* Activate malloc checking routines to detect heap corruptions. */
64 putenv( (char*)"MALLOC_CHECK_=2" );
66 putenv( (char*)"MallocErrorAbort=crash_my_baby_crash" );
69 /* Disable the ugly Gnome crash dialog so that we properly segfault */
70 putenv( (char *)"GNOME_DISABLE_CRASH_DIALOG=1" );
74 #if defined (HAVE_GETEUID) && !defined (SYS_BEOS)
75 /* FIXME: rootwrap (); */
78 /* Synchronously intercepted POSIX signals.
80 * In a threaded program such as VLC, the only sane way to handle signals
81 * is to block them in all thread but one - this is the only way to
82 * predict which thread will receive them. If any piece of code depends
83 * on delivery of one of this signal it is intrinsically not thread-safe
84 * and MUST NOT be used in VLC, whether we like it or not.
85 * There is only one exception: if the signal is raised with
86 * pthread_kill() - we do not use this in LibVLC but some pthread
87 * implementations use them internally. You should really use conditions
88 * for thread synchronization anyway.
90 * Signal that request a clean shutdown, and force an unclean shutdown
91 * if they are triggered again 2+ seconds later.
92 * We have to handle SIGTERM cleanly because of daemon mode.
93 * Note that we set the signals after the vlc_create call. */
94 static const int sigs[] = {
95 SIGINT, SIGHUP, SIGQUIT, SIGTERM,
96 /* Signals that cause a no-op:
97 * - SIGPIPE might happen with sockets and would crash VLC. It MUST be
98 * blocked by any LibVLC-dependent application, in addition to VLC.
99 * - SIGCHLD is comes after exec*() (such as httpd CGI support) and must
100 * be dequeued to cleanup zombie processes.
107 for (unsigned i = 0; i < sizeof (sigs) / sizeof (sigs[0]); i++)
108 sigaddset (&set, sigs[i]);
110 /* Block all these signals */
111 pthread_sigmask (SIG_BLOCK, &set, NULL);
113 /* Note that FromLocale() can be used before libvlc is initialized */
114 for (int i = 0; i < i_argc; i++)
115 if ((ppsz_argv[i] = FromLocale (ppsz_argv[i])) == NULL)
118 libvlc_exception_t ex, dummy;
119 libvlc_exception_init (&ex);
120 libvlc_exception_init (&dummy);
122 /* Initialize libvlc */
123 int i_argc_real = i_argc ? i_argc - 1 : 0;
124 const char **ppsz_argv_real = i_argc ? &ppsz_argv[1] : ppsz_argv;
125 libvlc_instance_t *vlc = libvlc_new (i_argc_real, ppsz_argv_real, &ex);
129 libvlc_add_intf (vlc, "signals", &dummy);
130 libvlc_add_intf (vlc, NULL, &ex);
131 libvlc_playlist_play (vlc, -1, 0, NULL, &dummy);
133 libvlc_release (vlc);
135 i_ret = libvlc_exception_raised (&ex);
137 fprintf( stderr, "%s\n", libvlc_exception_get_message( &ex));
139 libvlc_exception_clear (&ex);
140 libvlc_exception_clear (&dummy);
142 for (int i = 0; i < i_argc; i++)
143 LocaleFree (ppsz_argv[i]);