34
34
#include <stdlib.h>
35
35
#include <locale.h>
38
42
/* Explicit HACK */
39
43
extern void LocaleFree (const char *);
40
44
extern char *FromLocale (const char *);
45
extern void vlc_enable_override (void);
42
47
#include <signal.h>
44
49
#include <pthread.h>
45
50
#include <unistd.h>
54
static void dummy_handler (int signum)
47
60
/*****************************************************************************
48
61
* main: parse command line, start interface and spawn threads.
49
62
*****************************************************************************/
50
63
int main( int i_argc, const char *ppsz_argv[] )
65
/* The so-called POSIX-compliant MacOS X reportedly processes SIGPIPE even
66
* if it is blocked in all thread. Also some libraries want SIGPIPE blocked
67
* as they have no clue about signal masks.
68
* Note: this is NOT an excuse for not protecting against SIGPIPE. If
69
* LibVLC runs outside of VLC, we cannot rely on this code snippet. */
70
signal (SIGPIPE, SIG_IGN);
71
/* Restore default for SIGCHLD in case parent ignores it. */
72
signal (SIGCHLD, SIG_DFL);
76
/* Activate malloc checking routines to detect heap corruptions. */
77
setenv ("MALLOC_CHECK_", "2", 1);
79
/* Disable the ugly Gnome crash dialog so that we properly segfault */
80
setenv ("GNOME_DISABLE_CRASH_DIALOG", "1", 1);
83
/* Clear the X.Org startup notification ID. Otherwise the UI might try to
84
* change the environment while the process is multi-threaded. That could
85
* crash. Screw you X.Org. Next time write a thread-safe specification. */
86
unsetenv ("DESKTOP_STARTUP_ID");
54
89
#ifndef ALLOW_RUN_AS_ROOT
55
90
if (geteuid () == 0)
68
103
/* This clutters OSX GUI error logs */
69
fprintf( stderr, "VLC media player %s\n", libvlc_get_version() );
74
/* Activate malloc checking routines to detect heap corruptions. */
75
putenv( (char*)"MALLOC_CHECK_=2" );
77
/* Disable the ugly Gnome crash dialog so that we properly segfault */
78
putenv( (char *)"GNOME_DISABLE_CRASH_DIALOG=1" );
104
fprintf( stderr, "VLC media player %s (revision %s)\n",
105
libvlc_get_version(), libvlc_get_changeset() );
82
108
/* Synchronously intercepted POSIX signals.
84
110
* In a threaded program such as VLC, the only sane way to handle signals
85
* is to block them in all thread but one - this is the only way to
111
* is to block them in all threads but one - this is the only way to
86
112
* predict which thread will receive them. If any piece of code depends
87
113
* on delivery of one of this signal it is intrinsically not thread-safe
88
114
* and MUST NOT be used in VLC, whether we like it or not.
110
136
sigemptyset (&set);
111
137
for (unsigned i = 0; i < sizeof (sigs) / sizeof (sigs[0]); i++)
112
138
sigaddset (&set, sigs[i]);
140
sigaddset (&set, SIGRTMIN);
142
struct sigaction act = { .sa_handler = dummy_handler, };
143
sigaction (SIGRTMIN, &act, NULL);
114
147
/* Block all these signals */
115
148
pthread_sigmask (SIG_BLOCK, &set, NULL);
117
150
sigdelset (&set, SIGCHLD);
119
152
/* Note that FromLocale() can be used before libvlc is initialized */
120
const char *argv[i_argc + 3];
153
const char *argv[i_argc + 4];
156
argv[argc++] = "--no-ignore-config";
157
argv[argc++] = "--user-agent=\"VLC media player\"";
123
158
#ifdef TOP_BUILDDIR
124
159
argv[argc++] = FromLocale ("--plugin-path="TOP_BUILDDIR"/modules");
126
161
#ifdef TOP_SRCDIR
128
argv[argc++] = FromLocale ("--http-src="TOP_SRCDIR"/share/http");
162
argv[argc++] = FromLocale ("--data-path="TOP_SRCDIR"/share");
132
for (int i = 1; i < i_argc; i++)
167
/* When VLC.app is run by double clicking in Mac OS X, the 2nd arg
168
* is the PSN - process serial number (a unique PID-ish thingie)
169
* still ok for real Darwin & when run from command line
170
* for example -psn_0_9306113 */
171
if(i_argc >= 2 && !strncmp( ppsz_argv[1] , "-psn" , 4 ))
174
for (; i < i_argc; i++)
133
175
if ((argv[argc++] = FromLocale (ppsz_argv[i])) == NULL)
134
176
return 1; // BOOM!
136
libvlc_exception_t ex, dummy;
137
libvlc_exception_init (&ex);
138
libvlc_exception_init (&dummy);
179
vlc_enable_override ();
140
181
/* Initialize libvlc */
141
libvlc_instance_t *vlc = libvlc_new (argc, argv, &ex);
182
libvlc_instance_t *vlc = libvlc_new (argc, argv);
145
libvlc_add_intf (vlc, "signals", &ex);
146
if (libvlc_exception_raised (&ex))
186
if (libvlc_add_intf (vlc, "signals"))
187
pthread_sigmask (SIG_UNBLOCK, &set, NULL);
188
#if !defined (HAVE_MAEMO)
189
libvlc_add_intf (vlc, "globalhotkeys,none");
191
if (libvlc_add_intf (vlc, NULL) == 0)
148
libvlc_exception_clear (&ex);
149
pthread_sigmask (SIG_UNBLOCK, &set, NULL);
193
libvlc_playlist_play (vlc, -1, 0, NULL);
151
libvlc_add_intf (vlc, "globalhotkeys,none", &ex);
152
libvlc_exception_clear (&ex);
153
libvlc_add_intf (vlc, NULL, &ex);
154
libvlc_playlist_play (vlc, -1, 0, NULL, &dummy);
156
196
libvlc_release (vlc);
158
i_ret = libvlc_exception_raised (&ex);
160
fprintf( stderr, "%s\n", libvlc_exception_get_message( &ex));
162
libvlc_exception_clear (&ex);
163
libvlc_exception_clear (&dummy);
165
for (int i = 0; i < argc; i++)
199
for (int i = 2; i < argc; i++)
166
200
LocaleFree (argv[i]);