diff --git a/audio_alsa.c b/audio_alsa.c index 6b16fef1..83ed20df 100644 --- a/audio_alsa.c +++ b/audio_alsa.c @@ -212,11 +212,10 @@ void handle_unfixable_error(int errorCode) { if (config.cmd_unfixable) { command_execute(config.cmd_unfixable, messageString, 1); } else { - warn("An unrecoverable error, \"output_device_error_%d\", has been " + die("An unrecoverable error, \"output_device_error_%d\", has been " "detected. Doing an emergency exit, as no run_this_if_an_unfixable_error_is_detected " "program.", errorCode); - _Exit(EXIT_FAILURE); } } } diff --git a/common.c b/common.c index c513077e..6efe070d 100644 --- a/common.c +++ b/common.c @@ -131,7 +131,6 @@ void set_alsa_out_dev(char *); #endif config_t config_file_stuff; -int type_of_exit_cleanup; uint64_t minimum_dac_queue_size; pthread_mutex_t the_conn_lock = PTHREAD_MUTEX_INITIALIZER; @@ -343,27 +342,6 @@ shairport_cfg config; sigset_t pselect_sigset; -// note -- don't use this to shutdown from dbus -- see its own code in dbus-service.c -void sps_shutdown(type_of_exit_type shutdown_type) { // TOE_normal, TOE_emergency - type_of_exit_cleanup = shutdown_type; - if (type_of_exit_cleanup == TOE_emergency) { - debug(1, "emergency shutdown requested"); - exit(EXIT_FAILURE); - } else { - debug(1, "normal shutdown requested"); - exit(EXIT_SUCCESS); - } -} - -int usleep_uncancellable(useconds_t usec) { - int response; - int oldState; - pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldState); - response = usleep(usec); - pthread_setcancelstate(oldState, NULL); - return response; -} - static uint16_t UDPPortIndex = 0; void resetFreeUDPPort() { diff --git a/common.h b/common.h index 3c523833..395ca539 100644 --- a/common.h +++ b/common.h @@ -52,11 +52,6 @@ typedef enum { } dbus_message_bus_t; #endif -typedef enum { - TOE_normal, - TOE_emergency, -} type_of_exit_type; - #define sps_extra_code_output_stalled 32768 #define sps_extra_code_output_state_cannot_make_ready 32769 @@ -558,7 +553,6 @@ uint32_t uatoi(const char *nptr); extern shairport_cfg config; extern config_t config_file_stuff; -extern int type_of_exit_cleanup; // normal, emergency, dbus requested... extern uint64_t minimum_dac_queue_size; @@ -581,8 +575,6 @@ void command_set_volume(double volume); int mkpath(const char *path, mode_t mode); -void sps_shutdown(type_of_exit_type shutdown_type); // TOE_normal, TOE_emergency, TOE_dbus - extern sigset_t pselect_sigset; extern pthread_mutex_t the_conn_lock; diff --git a/shairport.c b/shairport.c index 99129c18..d1a0cbc6 100644 --- a/shairport.c +++ b/shairport.c @@ -1890,17 +1890,15 @@ const char *pid_file_proc(void) { } #endif + void exit_rtsp_listener() { debug(3, "exit_rtsp_listener begins"); - if (type_of_exit_cleanup != TOE_emergency) { - pthread_cancel(rtsp_listener_thread); - pthread_join(rtsp_listener_thread, NULL); // not sure you need this - } + pthread_cancel(rtsp_listener_thread); + pthread_join(rtsp_listener_thread, NULL); // not sure you need this debug(2, "exit_rtsp_listener ends"); } void exit_function() { - if (type_of_exit_cleanup != TOE_emergency) { // the following is to ensure that if libdaemon has been included // that most of this code will be skipped when the parent process is exiting // exec @@ -2035,6 +2033,8 @@ void exit_function() { #ifdef CONFIG_LIBDAEMON if (this_is_the_daemon_process) { // this is the daemon that is exiting + mdns_unregister(); // once the dacp handler is done and all player threrads are done it should + // be safe debug(1, "libdaemon daemon process exit"); } else { if (config.daemonise) @@ -2043,13 +2043,10 @@ void exit_function() { debug(1, "normal exit"); } #else - mdns_unregister(); // once the dacp handler is done and all player threrads are done it should + mdns_unregister(); // once the dacp handler is done and all player threads are done it should // be safe debug(2, "normal exit"); #endif - } else { - debug(1, "emergency exit"); - } } // for removing zombie script processes @@ -2395,7 +2392,6 @@ int main(int argc, char **argv) { setlogmask(LOG_UPTO(LOG_DEBUG)); openlog(NULL, 0, LOG_DAEMON); #endif - type_of_exit_cleanup = TOE_normal; // what kind of exit cleanup needed debug(1, "adding the exit function"); atexit(exit_function); diff --git a/utilities/debug.c b/utilities/debug.c index 50ffd37c..75326052 100644 --- a/utilities/debug.c +++ b/utilities/debug.c @@ -143,7 +143,7 @@ void _die(const char *filename, const int linenumber, const char *format, ...) { // syslog(LOG_ERR, "%s", b); fprintf(stderr, "%s\n", b); pthread_setcancelstate(oldState, NULL); - exit(EXIT_FAILURE); + _Exit(EXIT_FAILURE); } void _warn(const char *filename, const int linenumber, const char *format, ...) {