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 *****************************************************************************/
43 extern void LocaleFree (const char *);
44 extern char *FromLocale (const char *);
45 extern void vlc_enable_override (void);
53 /*****************************************************************************
54 * main: parse command line, start interface and spawn threads.
55 *****************************************************************************/
56 int main( int i_argc, const char *ppsz_argv[] )
58 /* The so-called POSIX-compliant MacOS X reportedly processes SIGPIPE even
59 * if it is blocked in all thread. Also some libraries want SIGPIPE blocked
60 * as they have no clue about signal masks.
61 * Note: this is NOT an excuse for not protecting against SIGPIPE. If
62 * LibVLC runs outside of VLC, we cannot rely on this code snippet. */
63 signal (SIGPIPE, SIG_IGN);
67 /* Activate malloc checking routines to detect heap corruptions. */
68 putenv( (char*)"MALLOC_CHECK_=2" );
70 /* Disable the ugly Gnome crash dialog so that we properly segfault */
71 putenv( (char *)"GNOME_DISABLE_CRASH_DIALOG=1" );
74 /* Make Xlib hide visuals with an alphachannel. Ensure that Qt4 will not
75 * use the alpha channel for the embedded video window. */
76 putenv( (char *)"XLIB_SKIP_ARGB_VISUALS=1" );
79 #ifndef ALLOW_RUN_AS_ROOT
82 fprintf (stderr, "VLC is not supposed to be run as root. Sorry.\n"
83 "If you need to use real-time priorities and/or privileged TCP ports\n"
84 "you can use %s-wrapper (make sure it is Set-UID root and\n"
85 "cannot be run by non-trusted users first).\n", ppsz_argv[0]);
90 setlocale (LC_ALL, "");
93 /* This clutters OSX GUI error logs */
94 fprintf( stderr, "VLC media player %s (revision %s)\n",
95 libvlc_get_version(), libvlc_get_changeset() );
98 /* Synchronously intercepted POSIX signals.
100 * In a threaded program such as VLC, the only sane way to handle signals
101 * is to block them in all threads but one - this is the only way to
102 * predict which thread will receive them. If any piece of code depends
103 * on delivery of one of this signal it is intrinsically not thread-safe
104 * and MUST NOT be used in VLC, whether we like it or not.
105 * There is only one exception: if the signal is raised with
106 * pthread_kill() - we do not use this in LibVLC but some pthread
107 * implementations use them internally. You should really use conditions
108 * for thread synchronization anyway.
110 * Signal that request a clean shutdown, and force an unclean shutdown
111 * if they are triggered again 2+ seconds later.
112 * We have to handle SIGTERM cleanly because of daemon mode.
113 * Note that we set the signals after the vlc_create call. */
114 static const int sigs[] = {
115 SIGINT, SIGHUP, SIGQUIT, SIGTERM,
116 /* Signals that cause a no-op:
117 * - SIGPIPE might happen with sockets and would crash VLC. It MUST be
118 * blocked by any LibVLC-dependent application, not just VLC.
119 * - SIGCHLD comes after exec*() (such as httpd CGI support) and must
120 * be dequeued to cleanup zombie processes.
127 for (unsigned i = 0; i < sizeof (sigs) / sizeof (sigs[0]); i++)
128 sigaddset (&set, sigs[i]);
130 /* Block all these signals */
131 pthread_sigmask (SIG_BLOCK, &set, NULL);
132 sigdelset (&set, SIGPIPE);
133 sigdelset (&set, SIGCHLD);
135 /* Note that FromLocale() can be used before libvlc is initialized */
136 const char *argv[i_argc + 3];
139 argv[argc++] = "--no-ignore-config";
141 argv[argc++] = FromLocale ("--plugin-path="TOP_BUILDDIR"/modules");
144 argv[argc++] = FromLocale ("--data-path="TOP_SRCDIR"/share");
149 /* When VLC.app is run by double clicking in Mac OS X, the 2nd arg
150 * is the PSN - process serial number (a unique PID-ish thingie)
151 * still ok for real Darwin & when run from command line
152 * for example -psn_0_9306113 */
153 if(i_argc >= 2 && !strncmp( ppsz_argv[1] , "-psn" , 4 ))
156 for (; i < i_argc; i++)
157 if ((argv[argc++] = FromLocale (ppsz_argv[i])) == NULL)
161 vlc_enable_override ();
163 /* Initialize libvlc */
164 libvlc_instance_t *vlc = libvlc_new (argc, argv);
168 if (libvlc_add_intf (vlc, "signals"))
169 pthread_sigmask (SIG_UNBLOCK, &set, NULL);
170 #if !defined (HAVE_MAEMO)
171 libvlc_add_intf (vlc, "globalhotkeys,none");
173 if (libvlc_add_intf (vlc, NULL) == 0)
175 libvlc_playlist_play (vlc, -1, 0, NULL);
178 libvlc_release (vlc);
181 for (int i = 1; i < argc; i++)
182 LocaleFree (argv[i]);
185 /* Avoid crash in KIO scheduler cleanup. */
186 /* This is ugly, but we get way too many crash reports due to this. */
187 if (dlopen ("libkfilemodule.so", RTLD_LAZY|RTLD_LOCAL|RTLD_NOLOAD) != NULL)
189 fprintf (stderr, "KFile plugin present. Unclean shutdown!\n");