- signal( SIGINT, SigHandler );
- signal( SIGHUP, SigHandler );
- signal( SIGQUIT, SigHandler );
-
- /* Other signals */
- signal( SIGALRM, SIG_IGN );
- signal( SIGPIPE, SIG_IGN );
-#endif
-
-#ifdef WIN32
- /* Replace argv[1..n] with unicode for Windows NT and above */
- if( GetVersion() < 0x80000000 )
- {
- wchar_t **wargv, **wenvp;
- int i,i_wargc;
- int si = { 0 };
- __wgetmainargs(&i_wargc, &wargv, &wenvp, 0, &si);
-
- for( i = 1; i < i_wargc; i++ )
- {
- int len = WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, NULL, 0, NULL, NULL);
- if( len > 0 )
- {
- if( len > 1 ) {
- char *utf8arg = (char *)malloc(len);
- if( NULL != utf8arg )
- {
- WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, utf8arg, len, NULL, NULL);
- ppsz_argv[i] = utf8arg;
- }
- else
- {
- /* failed!, quit */
- return -1;
- }
- }
- else
- {
- ppsz_argv[i] = "";
- }
- }
- else
- {
- /* failed!, quit */
- return -1;
- }
- }
- }
-#endif
+ static const int sigs[] = {
+ SIGINT, SIGHUP, SIGQUIT, SIGTERM,
+ /* Signals that cause a no-op:
+ * - SIGPIPE might happen with sockets and would crash VLC. It MUST be
+ * blocked by any LibVLC-dependent application, in addition to VLC.
+ * - SIGCHLD is comes after exec*() (such as httpd CGI support) and must
+ * be dequeued to cleanup zombie processes.
+ */
+ SIGPIPE, SIGCHLD
+ };
+
+ sigset_t set;
+ sigemptyset (&set);
+ for (unsigned i = 0; i < sizeof (sigs) / sizeof (sigs[0]); i++)
+ sigaddset (&set, sigs[i]);
+
+ /* Block all these signals */
+ pthread_sigmask (SIG_BLOCK, &set, NULL);
+
+ /* Note that FromLocale() can be used before libvlc is initialized */
+ for (int i = 0; i < i_argc; i++)
+ if ((ppsz_argv[i] = FromLocale (ppsz_argv[i])) == NULL)
+ return 1; // BOOM!
+
+ libvlc_exception_t ex, dummy;
+ libvlc_exception_init (&ex);
+ libvlc_exception_init (&dummy);