- if (libvlc_add_intf (vlc, NULL) == 0)
- {
- libvlc_playlist_play (vlc, -1, 0, NULL);
- libvlc_wait (vlc);
- }
- libvlc_release (vlc);
- }
+ if (libvlc_add_intf (vlc, NULL))
+ goto out;
+
+ libvlc_playlist_play (vlc, -1, 0, NULL);
+
+ /* Wait for a termination signal */
+ pthread_t self = pthread_self ();
+ libvlc_set_exit_handler (vlc, vlc_kill, &self);
+
+ if (signal_ignored (SIGHUP)) /* <- needed to handle nohup properly */
+ sigdelset (&set, SIGHUP);
+ sigdelset (&set, SIGPIPE);
+
+ int signum;
+ do
+ sigwait (&set, &signum);
+ while (signum == SIGCHLD);