From ea8d29f74295b1324db90326764c73e85de43ea4 Mon Sep 17 00:00:00 2001 From: moritz Date: Sun, 25 Feb 2007 16:00:41 +0000 Subject: [PATCH] Switch from using signal() to sigaction() and friends, so that SA_RESTART can be used. This is required for Solaris and possibly others, where signal handlers have to be reinstalled after having caught one signal via signal(). Also prevent Ezstream from being killed by a handled signal in streamFile(), where they can interrupt fread()'s system calls. This improves matters, but isn't perfect, yet. A SIGHUP signal can still cause skipping to the next track, which should be triggered only by SIGUSR1. git-svn-id: https://svn.xiph.org/trunk/ezstream@12563 0101bb08-14d6-0310-b084-bc0e0c8e3800 --- src/ezstream.c | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/src/ezstream.c b/src/ezstream.c index 23b3677..9d4d42c 100644 --- a/src/ezstream.c +++ b/src/ezstream.c @@ -58,6 +58,7 @@ # include "strlfctns.h" #endif #include "configfile.h" +#include "ezsignals.h" #include "playlist.h" #include "util.h" @@ -81,13 +82,13 @@ #endif /* WIN32 */ #ifdef HAVE___PROGNAME -extern char *__progname; +extern char *__progname; #else -char *__progname; +char *__progname; #endif /* HAVE___PROGNAME */ -int qFlag; -int vFlag; +int qFlag; +int vFlag; EZCONFIG *pezConfig = NULL; static const char *blankString = ""; @@ -95,9 +96,11 @@ playlist_t *playlist = NULL; int playlistMode = 0; #ifdef HAVE_SIGNALS -volatile sig_atomic_t rereadPlaylist = 0; -volatile sig_atomic_t rereadPlaylist_notify = 0; -volatile sig_atomic_t skipTrack = 0; +const int ezstream_signals[] = { SIGHUP, SIGUSR1 }; + +volatile sig_atomic_t rereadPlaylist = 0; +volatile sig_atomic_t rereadPlaylist_notify = 0; +volatile sig_atomic_t skipTrack = 0; void sig_handler(int sig) @@ -115,9 +118,9 @@ sig_handler(int sig) } } #else -int rereadPlaylist = 0; -int rereadPlaylist_notify = 0; -int skipTrack = 0; +int rereadPlaylist = 0; +int rereadPlaylist_notify = 0; +int skipTrack = 0; #endif /* HAVE_SIGNALS */ typedef struct tag_ID3Tag { @@ -664,10 +667,14 @@ streamFile(shout_t *shout, const char *fileName) break; } } - if (ferror(filepstream)) - printf("%s: streamFile(): Error while reading '%s': %s\n", - __progname, fileName, strerror(errno)); - else + if (ferror(filepstream)) { + if (errno == EINTR) { + clearerr(filepstream); + retval = 1; + } else + printf("%s: streamFile(): Error while reading '%s': %s\n", + __progname, fileName, strerror(errno)); + } else retval = 1; if (popenFlag) @@ -769,6 +776,9 @@ main(int argc, char *argv[]) shout_t *shout; extern char *optarg; extern int optind; +#ifdef HAVE_SIGNALS + struct sigaction act; +#endif __progname = getProgname(argv[0]); pezConfig = getEZConfig(); @@ -994,8 +1004,12 @@ main(int argc, char *argv[]) } #ifdef HAVE_SIGNALS - signal(SIGHUP, sig_handler); - signal(SIGUSR1, sig_handler); + memset(&act, 0, sizeof(act)); + act.sa_handler = sig_handler; +# ifdef SA_RESTART + act.sa_flags = SA_RESTART; +# endif + SIGS_INSTALL(ezstream_signals, &act); #endif /* HAVE_SIGNALS */ if (qFlag) {