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 #if defined (HAVE_GETEUID) && !defined (SYS_BEOS)
84 /* FIXME: rootwrap (); */
87 /* Synchronously intercepted POSIX signals.
89 * In a threaded program such as VLC, the only sane way to handle signals
90 * is to block them in all thread but one - this is the only way to
91 * predict which thread will receive them. If any piece of code depends
92 * on delivery of one of this signal it is intrinsically not thread-safe
93 * and MUST NOT be used in VLC, whether we like it or not.
94 * There is only one exception: if the signal is raised with
95 * pthread_kill() - we do not use this in LibVLC but some pthread
96 * implementations use them internally. You should really use conditions
97 * for thread synchronization anyway.
99 * Signal that request a clean shutdown, and force an unclean shutdown
100 * if they are triggered again 2+ seconds later.
101 * We have to handle SIGTERM cleanly because of daemon mode.
102 * Note that we set the signals after the vlc_create call. */
103 static const int sigs
[] = {
104 SIGINT
, SIGHUP
, SIGQUIT
, SIGTERM
,
105 /* Signals that cause a no-op:
106 * - SIGPIPE might happen with sockets and would crash VLC. It MUST be
107 * blocked by any LibVLC-dependent application, in addition to VLC.
108 * - SIGCHLD is comes after exec*() (such as httpd CGI support) and must
109 * be dequeued to cleanup zombie processes.
116 for (unsigned i
= 0; i
< sizeof (sigs
) / sizeof (sigs
[0]); i
++)
117 sigaddset (&set
, sigs
[i
]);
119 /* Block all these signals */
120 pthread_sigmask (SIG_BLOCK
, &set
, NULL
);
122 /* Note that FromLocale() can be used before libvlc is initialized */
123 for (int i
= 0; i
< i_argc
; i
++)
124 if ((ppsz_argv
[i
] = FromLocale (ppsz_argv
[i
])) == NULL
)
127 libvlc_exception_t ex
, dummy
;
128 libvlc_exception_init (&ex
);
129 libvlc_exception_init (&dummy
);
131 /* Initialize libvlc */
132 int i_argc_real
= i_argc
? i_argc
- 1 : 0;
133 const char **ppsz_argv_real
= i_argc
? &ppsz_argv
[1] : ppsz_argv
;
134 libvlc_instance_t
*vlc
= libvlc_new (i_argc_real
, ppsz_argv_real
, &ex
);
138 libvlc_add_intf (vlc
, "signals", &dummy
);
139 libvlc_add_intf (vlc
, NULL
, &ex
);
140 libvlc_playlist_play (vlc
, -1, 0, NULL
, &dummy
);
142 libvlc_release (vlc
);
144 i_ret
= libvlc_exception_raised (&ex
);
146 fprintf( stderr
, "%s\n", libvlc_exception_get_message( &ex
));
148 libvlc_exception_clear (&ex
);
149 libvlc_exception_clear (&dummy
);
151 for (int i
= 0; i
< i_argc
; i
++)
152 LocaleFree (ppsz_argv
[i
]);