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[] )
56 fprintf (stderr, "VLC is not supposed to be run as root. Sorry.\n"
57 "If you need to use real-time priorities and/or privileged TCP ports\n"
58 "you can use %s-wrapper (make sure it is Set-UID root first and\n"
59 "cannot be run by non-trusted users first).\n", ppsz_argv[0]);
63 setlocale (LC_ALL, "");
66 /* This clutters OSX GUI error logs */
67 fprintf( stderr, "VLC media player %s\n", libvlc_get_version() );
72 /* Activate malloc checking routines to detect heap corruptions. */
73 putenv( (char*)"MALLOC_CHECK_=2" );
75 putenv( (char*)"MallocErrorAbort=crash_my_baby_crash" );
78 /* Disable the ugly Gnome crash dialog so that we properly segfault */
79 putenv( (char *)"GNOME_DISABLE_CRASH_DIALOG=1" );
83 /* Synchronously intercepted POSIX signals.
85 * In a threaded program such as VLC, the only sane way to handle signals
86 * is to block them in all thread but one - this is the only way to
87 * predict which thread will receive them. If any piece of code depends
88 * on delivery of one of this signal it is intrinsically not thread-safe
89 * and MUST NOT be used in VLC, whether we like it or not.
90 * There is only one exception: if the signal is raised with
91 * pthread_kill() - we do not use this in LibVLC but some pthread
92 * implementations use them internally. You should really use conditions
93 * for thread synchronization anyway.
95 * Signal that request a clean shutdown, and force an unclean shutdown
96 * if they are triggered again 2+ seconds later.
97 * We have to handle SIGTERM cleanly because of daemon mode.
98 * Note that we set the signals after the vlc_create call. */
99 static const int sigs[] = {
100 SIGINT, SIGHUP, SIGQUIT, SIGTERM,
101 /* Signals that cause a no-op:
102 * - SIGPIPE might happen with sockets and would crash VLC. It MUST be
103 * blocked by any LibVLC-dependent application, in addition to VLC.
104 * - SIGCHLD is comes after exec*() (such as httpd CGI support) and must
105 * be dequeued to cleanup zombie processes.
112 for (unsigned i = 0; i < sizeof (sigs) / sizeof (sigs[0]); i++)
113 sigaddset (&set, sigs[i]);
115 /* Block all these signals */
116 pthread_sigmask (SIG_BLOCK, &set, NULL);
118 /* Note that FromLocale() can be used before libvlc is initialized */
119 for (int i = 0; i < i_argc; i++)
120 if ((ppsz_argv[i] = FromLocale (ppsz_argv[i])) == NULL)
123 libvlc_exception_t ex, dummy;
124 libvlc_exception_init (&ex);
125 libvlc_exception_init (&dummy);
127 /* Initialize libvlc */
128 int i_argc_real = i_argc ? i_argc - 1 : 0;
129 const char **ppsz_argv_real = i_argc ? &ppsz_argv[1] : ppsz_argv;
130 libvlc_instance_t *vlc = libvlc_new (i_argc_real, ppsz_argv_real, &ex);
134 libvlc_add_intf (vlc, "signals", &dummy);
135 libvlc_add_intf (vlc, NULL, &ex);
136 libvlc_playlist_play (vlc, -1, 0, NULL, &dummy);
138 libvlc_release (vlc);
140 i_ret = libvlc_exception_raised (&ex);
142 fprintf( stderr, "%s\n", libvlc_exception_get_message( &ex));
144 libvlc_exception_clear (&ex);
145 libvlc_exception_clear (&dummy);
147 for (int i = 0; i < i_argc; i++)
148 LocaleFree (ppsz_argv[i]);