1
0
mirror of https://gitlab.xiph.org/xiph/ezstream.git synced 2024-12-04 14:46:31 -05:00

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
This commit is contained in:
moritz 2007-02-25 16:00:41 +00:00
parent 733c989d1b
commit ea8d29f742

View File

@ -58,6 +58,7 @@
# include "strlfctns.h" # include "strlfctns.h"
#endif #endif
#include "configfile.h" #include "configfile.h"
#include "ezsignals.h"
#include "playlist.h" #include "playlist.h"
#include "util.h" #include "util.h"
@ -81,13 +82,13 @@
#endif /* WIN32 */ #endif /* WIN32 */
#ifdef HAVE___PROGNAME #ifdef HAVE___PROGNAME
extern char *__progname; extern char *__progname;
#else #else
char *__progname; char *__progname;
#endif /* HAVE___PROGNAME */ #endif /* HAVE___PROGNAME */
int qFlag; int qFlag;
int vFlag; int vFlag;
EZCONFIG *pezConfig = NULL; EZCONFIG *pezConfig = NULL;
static const char *blankString = ""; static const char *blankString = "";
@ -95,9 +96,11 @@ playlist_t *playlist = NULL;
int playlistMode = 0; int playlistMode = 0;
#ifdef HAVE_SIGNALS #ifdef HAVE_SIGNALS
volatile sig_atomic_t rereadPlaylist = 0; const int ezstream_signals[] = { SIGHUP, SIGUSR1 };
volatile sig_atomic_t rereadPlaylist_notify = 0;
volatile sig_atomic_t skipTrack = 0; volatile sig_atomic_t rereadPlaylist = 0;
volatile sig_atomic_t rereadPlaylist_notify = 0;
volatile sig_atomic_t skipTrack = 0;
void void
sig_handler(int sig) sig_handler(int sig)
@ -115,9 +118,9 @@ sig_handler(int sig)
} }
} }
#else #else
int rereadPlaylist = 0; int rereadPlaylist = 0;
int rereadPlaylist_notify = 0; int rereadPlaylist_notify = 0;
int skipTrack = 0; int skipTrack = 0;
#endif /* HAVE_SIGNALS */ #endif /* HAVE_SIGNALS */
typedef struct tag_ID3Tag { typedef struct tag_ID3Tag {
@ -664,10 +667,14 @@ streamFile(shout_t *shout, const char *fileName)
break; break;
} }
} }
if (ferror(filepstream)) if (ferror(filepstream)) {
printf("%s: streamFile(): Error while reading '%s': %s\n", if (errno == EINTR) {
__progname, fileName, strerror(errno)); clearerr(filepstream);
else retval = 1;
} else
printf("%s: streamFile(): Error while reading '%s': %s\n",
__progname, fileName, strerror(errno));
} else
retval = 1; retval = 1;
if (popenFlag) if (popenFlag)
@ -769,6 +776,9 @@ main(int argc, char *argv[])
shout_t *shout; shout_t *shout;
extern char *optarg; extern char *optarg;
extern int optind; extern int optind;
#ifdef HAVE_SIGNALS
struct sigaction act;
#endif
__progname = getProgname(argv[0]); __progname = getProgname(argv[0]);
pezConfig = getEZConfig(); pezConfig = getEZConfig();
@ -994,8 +1004,12 @@ main(int argc, char *argv[])
} }
#ifdef HAVE_SIGNALS #ifdef HAVE_SIGNALS
signal(SIGHUP, sig_handler); memset(&act, 0, sizeof(act));
signal(SIGUSR1, sig_handler); act.sa_handler = sig_handler;
# ifdef SA_RESTART
act.sa_flags = SA_RESTART;
# endif
SIGS_INSTALL(ezstream_signals, &act);
#endif /* HAVE_SIGNALS */ #endif /* HAVE_SIGNALS */
if (qFlag) { if (qFlag) {