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 *);
51 /*****************************************************************************
52 * main: parse command line, start interface and spawn threads.
53 *****************************************************************************/
54 int main( int i_argc, const char *ppsz_argv[] )
57 /* The so-called POSIX-compliant MacOS X is not.
58 * SIGPIPE fires even when it is blocked in all threads! */
59 signal (SIGPIPE, SIG_IGN);
62 #ifndef ALLOW_RUN_AS_ROOT
65 fprintf (stderr, "VLC is not supposed to be run as root. Sorry.\n"
66 "If you need to use real-time priorities and/or privileged TCP ports\n"
67 "you can use %s-wrapper (make sure it is Set-UID root and\n"
68 "cannot be run by non-trusted users first).\n", ppsz_argv[0]);
73 setlocale (LC_ALL, "");
76 /* This clutters OSX GUI error logs */
77 fprintf( stderr, "VLC media player %s (revision %s)\n",
78 libvlc_get_version(), libvlc_get_changeset() );
83 /* Activate malloc checking routines to detect heap corruptions. */
84 putenv( (char*)"MALLOC_CHECK_=2" );
86 /* Disable the ugly Gnome crash dialog so that we properly segfault */
87 putenv( (char *)"GNOME_DISABLE_CRASH_DIALOG=1" );
91 /* Synchronously intercepted POSIX signals.
93 * In a threaded program such as VLC, the only sane way to handle signals
94 * is to block them in all threads but one - this is the only way to
95 * predict which thread will receive them. If any piece of code depends
96 * on delivery of one of this signal it is intrinsically not thread-safe
97 * and MUST NOT be used in VLC, whether we like it or not.
98 * There is only one exception: if the signal is raised with
99 * pthread_kill() - we do not use this in LibVLC but some pthread
100 * implementations use them internally. You should really use conditions
101 * for thread synchronization anyway.
103 * Signal that request a clean shutdown, and force an unclean shutdown
104 * if they are triggered again 2+ seconds later.
105 * We have to handle SIGTERM cleanly because of daemon mode.
106 * Note that we set the signals after the vlc_create call. */
107 static const int sigs[] = {
108 SIGINT, SIGHUP, SIGQUIT, SIGTERM,
109 /* Signals that cause a no-op:
110 * - SIGPIPE might happen with sockets and would crash VLC. It MUST be
111 * blocked by any LibVLC-dependent application, not just VLC.
112 * - SIGCHLD comes after exec*() (such as httpd CGI support) and must
113 * be dequeued to cleanup zombie processes.
120 for (unsigned i = 0; i < sizeof (sigs) / sizeof (sigs[0]); i++)
121 sigaddset (&set, sigs[i]);
123 /* Block all these signals */
124 pthread_sigmask (SIG_BLOCK, &set, NULL);
125 sigdelset (&set, SIGPIPE);
126 sigdelset (&set, SIGCHLD);
128 /* Note that FromLocale() can be used before libvlc is initialized */
129 const char *argv[i_argc + 3];
132 argv[argc++] = "--no-ignore-config";
134 argv[argc++] = FromLocale ("--plugin-path="TOP_BUILDDIR"/modules");
137 argv[argc++] = FromLocale ("--data-path="TOP_SRCDIR"/share");
142 /* When VLC.app is run by double clicking in Mac OS X, the 2nd arg
143 * is the PSN - process serial number (a unique PID-ish thingie)
144 * still ok for real Darwin & when run from command line
145 * for example -psn_0_9306113 */
146 if(i_argc >= 2 && !strncmp( ppsz_argv[1] , "-psn" , 4 ))
149 for (; i < i_argc; i++)
150 if ((argv[argc++] = FromLocale (ppsz_argv[i])) == NULL)
154 /* Initialize libvlc */
155 libvlc_instance_t *vlc = libvlc_new (argc, argv);
159 if (libvlc_add_intf (vlc, "signals"))
160 pthread_sigmask (SIG_UNBLOCK, &set, NULL);
161 #if !defined (HAVE_MAEMO)
162 libvlc_add_intf (vlc, "globalhotkeys,none");
164 if (libvlc_add_intf (vlc, NULL) == 0)
166 libvlc_playlist_play (vlc, -1, 0, NULL);
169 libvlc_release (vlc);
172 for (int i = 1; i < argc; i++)
173 LocaleFree (argv[i]);