+#if defined (HAVE_GETEUID) && !defined (SYS_BEOS)
+ /* FIXME: rootwrap (); */
+#endif
+
+ /* Create a libvlc structure */
+ i_ret = VLC_Create();
+ if( i_ret < 0 )
+ {
+ return -i_ret;
+ }
+
+#if !defined(WIN32) && !defined(UNDER_CE)
+ /* Synchronously intercepted POSIX signals.
+ *
+ * In a threaded program such as VLC, the only sane way to handle signals
+ * is to block them in all thread but one - this is the only way to
+ * predict which thread will receive them. If any piece of code depends
+ * on delivery of one of this signal it is intrinsically not thread-safe
+ * and MUST NOT be used in VLC, whether we like it or not.
+ * There is only one exception: if the signal is raised with
+ * pthread_kill() - we do not use this in LibVLC but some pthread
+ * implementations use them internally. You should really use conditions
+ * for thread synchronization anyway.
+ *
+ * Signal that request a clean shutdown, and force an unclean shutdown
+ * if they are triggered again 2+ seconds later.
+ * We have to handle SIGTERM cleanly because of daemon mode.
+ * Note that we set the signals after the vlc_create call. */
+ static const int exitsigs[] = { SIGINT, SIGHUP, SIGQUIT, SIGTERM };
+ /* Signals that cause a no-op:
+ * - SIGALRM should not happen, but lets stay on the safe side.
+ * - SIGPIPE might happen with sockets and would crash VLC. It MUST be
+ * blocked by any LibVLC-dependant application, in addition to VLC.
+ * - SIGCHLD is comes after exec*() (such as httpd CGI support) and must
+ * be dequeued to cleanup zombie processes.
+ */
+ static const int dummysigs[] = { SIGALRM, SIGPIPE, SIGCHLD };
+
+ sigset_t set;
+ pthread_t sigth;
+
+ sigemptyset (&set);
+ for (unsigned i = 0; i < sizeof (exitsigs) / sizeof (exitsigs[0]); i++)
+ sigaddset (&set, exitsigs[i]);
+ for (unsigned i = 0; i < sizeof (dummysigs) / sizeof (dummysigs[0]); i++)
+ sigaddset (&set, dummysigs[i]);
+
+ /* Block all these signals */
+ pthread_sigmask (SIG_BLOCK, &set, NULL);
+
+ for (unsigned i = 0; i < sizeof (dummysigs) / sizeof (dummysigs[0]); i++)
+ sigdelset (&set, dummysigs[i]);
+
+ pthread_create (&sigth, NULL, SigHandler, &set);
+#endif
+
+#ifdef WIN32
+ /* Replace argv[1..n] with unicode for Windows NT and above */
+ if( GetVersion() < 0x80000000 )