mirror of
https://gitlab.xiph.org/xiph/ezstream.git
synced 2024-12-04 14:46:31 -05:00
Do a clean shutdown on SIGINT and SIGTERM.
git-svn-id: https://svn.xiph.org/trunk/ezstream@13438 0101bb08-14d6-0310-b084-bc0e0c8e3800
This commit is contained in:
parent
c444af6814
commit
3dd13ec7aa
@ -36,7 +36,6 @@ extern char *__progname;
|
|||||||
static EZCONFIG ezConfig;
|
static EZCONFIG ezConfig;
|
||||||
static const char *blankString = "";
|
static const char *blankString = "";
|
||||||
|
|
||||||
void freeConfig(EZCONFIG *);
|
|
||||||
unsigned int checkDecoderLine(const char *, const char *, long);
|
unsigned int checkDecoderLine(const char *, const char *, long);
|
||||||
unsigned int checkEncoderLine(const char *, const char *, long);
|
unsigned int checkEncoderLine(const char *, const char *, long);
|
||||||
unsigned int checkFormatLine(const char *, const char *, long);
|
unsigned int checkFormatLine(const char *, const char *, long);
|
||||||
|
@ -71,5 +71,6 @@ EZCONFIG * getEZConfig(void);
|
|||||||
const char * getFormatEncoder(const char *format);
|
const char * getFormatEncoder(const char *format);
|
||||||
const char * getFormatDecoder(const char *match);
|
const char * getFormatDecoder(const char *match);
|
||||||
int parseConfig(const char *fileName);
|
int parseConfig(const char *fileName);
|
||||||
|
void freeConfig(EZCONFIG *);
|
||||||
|
|
||||||
#endif /* __CONFIGFILE_H__ */
|
#endif /* __CONFIGFILE_H__ */
|
||||||
|
@ -87,17 +87,21 @@ playlist_t *playlist = NULL;
|
|||||||
int playlistMode = 0;
|
int playlistMode = 0;
|
||||||
|
|
||||||
#ifdef HAVE_SIGNALS
|
#ifdef HAVE_SIGNALS
|
||||||
const int ezstream_signals[] = { SIGHUP, SIGUSR1, SIGUSR2 };
|
const int ezstream_signals[] = {
|
||||||
|
SIGTERM, SIGINT, SIGHUP, SIGUSR1, SIGUSR2
|
||||||
|
};
|
||||||
|
|
||||||
volatile sig_atomic_t rereadPlaylist = 0;
|
volatile sig_atomic_t rereadPlaylist = 0;
|
||||||
volatile sig_atomic_t rereadPlaylist_notify = 0;
|
volatile sig_atomic_t rereadPlaylist_notify = 0;
|
||||||
volatile sig_atomic_t skipTrack = 0;
|
volatile sig_atomic_t skipTrack = 0;
|
||||||
volatile sig_atomic_t queryMetadata = 0;
|
volatile sig_atomic_t queryMetadata = 0;
|
||||||
|
volatile sig_atomic_t quit = 0;
|
||||||
#else
|
#else
|
||||||
int rereadPlaylist = 0;
|
int rereadPlaylist = 0;
|
||||||
int rereadPlaylist_notify = 0;
|
int rereadPlaylist_notify = 0;
|
||||||
int skipTrack = 0;
|
int skipTrack = 0;
|
||||||
int queryMetadata = 0;
|
int queryMetadata = 0;
|
||||||
|
int quit = 0;
|
||||||
#endif /* HAVE_SIGNALS */
|
#endif /* HAVE_SIGNALS */
|
||||||
|
|
||||||
typedef struct tag_ID3Tag {
|
typedef struct tag_ID3Tag {
|
||||||
@ -137,6 +141,10 @@ void
|
|||||||
sig_handler(int sig)
|
sig_handler(int sig)
|
||||||
{
|
{
|
||||||
switch (sig) {
|
switch (sig) {
|
||||||
|
case SIGTERM:
|
||||||
|
case SIGINT:
|
||||||
|
quit = 1;
|
||||||
|
break;
|
||||||
case SIGHUP:
|
case SIGHUP:
|
||||||
rereadPlaylist = 1;
|
rereadPlaylist = 1;
|
||||||
rereadPlaylist_notify = 1;
|
rereadPlaylist_notify = 1;
|
||||||
@ -666,6 +674,9 @@ reconnectServer(shout_t *shout, int closeConn)
|
|||||||
|
|
||||||
printf("%s: Waiting 5s for %s to come back ...\n",
|
printf("%s: Waiting 5s for %s to come back ...\n",
|
||||||
__progname, pezConfig->URL);
|
__progname, pezConfig->URL);
|
||||||
|
if (quit)
|
||||||
|
return (0);
|
||||||
|
else
|
||||||
sleep(5);
|
sleep(5);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -735,6 +746,8 @@ sendStream(shout_t *shout, FILE *filepstream, const char *fileName,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (quit)
|
||||||
|
break;
|
||||||
if (rereadPlaylist_notify) {
|
if (rereadPlaylist_notify) {
|
||||||
rereadPlaylist_notify = 0;
|
rereadPlaylist_notify = 0;
|
||||||
if (!pezConfig->fileNameIsProgram)
|
if (!pezConfig->fileNameIsProgram)
|
||||||
@ -853,6 +866,8 @@ streamFile(shout_t *shout, const char *fileName)
|
|||||||
do {
|
do {
|
||||||
ret = sendStream(shout, filepstream, fileName, isStdin, NULL, NULL);
|
ret = sendStream(shout, filepstream, fileName, isStdin, NULL, NULL);
|
||||||
#endif
|
#endif
|
||||||
|
if (quit)
|
||||||
|
break;
|
||||||
if (ret != STREAM_DONE) {
|
if (ret != STREAM_DONE) {
|
||||||
if ((skipTrack && rereadPlaylist) ||
|
if ((skipTrack && rereadPlaylist) ||
|
||||||
(skipTrack && queryMetadata)) {
|
(skipTrack && queryMetadata)) {
|
||||||
@ -944,6 +959,8 @@ streamPlaylist(shout_t *shout, const char *fileName)
|
|||||||
strlcpy(lastSong, song, sizeof(lastSong));
|
strlcpy(lastSong, song, sizeof(lastSong));
|
||||||
if (!streamFile(shout, song))
|
if (!streamFile(shout, song))
|
||||||
return (0);
|
return (0);
|
||||||
|
if (quit)
|
||||||
|
break;
|
||||||
if (rereadPlaylist) {
|
if (rereadPlaylist) {
|
||||||
rereadPlaylist = rereadPlaylist_notify = 0;
|
rereadPlaylist = rereadPlaylist_notify = 0;
|
||||||
if (pezConfig->fileNameIsProgram)
|
if (pezConfig->fileNameIsProgram)
|
||||||
@ -994,6 +1011,7 @@ shutdown(int exitval)
|
|||||||
{
|
{
|
||||||
shout_shutdown();
|
shout_shutdown();
|
||||||
playlist_shutdown();
|
playlist_shutdown();
|
||||||
|
freeConfig(pezConfig);
|
||||||
xalloc_shutdown();
|
xalloc_shutdown();
|
||||||
|
|
||||||
return (exitval);
|
return (exitval);
|
||||||
@ -1320,6 +1338,8 @@ main(int argc, char *argv[])
|
|||||||
} else {
|
} else {
|
||||||
ret = streamFile(shout, pezConfig->fileName);
|
ret = streamFile(shout, pezConfig->fileName);
|
||||||
}
|
}
|
||||||
|
if (quit)
|
||||||
|
break;
|
||||||
if (pezConfig->streamOnce)
|
if (pezConfig->streamOnce)
|
||||||
break;
|
break;
|
||||||
} while (ret);
|
} while (ret);
|
||||||
@ -1329,6 +1349,9 @@ main(int argc, char *argv[])
|
|||||||
printf("%s: Connection to http://%s:%d%s failed: %s\n", __progname,
|
printf("%s: Connection to http://%s:%d%s failed: %s\n", __progname,
|
||||||
host, port, mount, shout_get_error(shout));
|
host, port, mount, shout_get_error(shout));
|
||||||
|
|
||||||
|
if (quit)
|
||||||
|
printf("\r%s: SIGINT or SIGTERM received\n", __progname);
|
||||||
|
|
||||||
if (vFlag)
|
if (vFlag)
|
||||||
printf("%s: Exiting ...\n", __progname);
|
printf("%s: Exiting ...\n", __progname);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user