[xiph-commits] r13438 - trunk/ezstream/src

moritz at svn.xiph.org moritz at svn.xiph.org
Sat Aug 4 10:04:50 PDT 2007


Author: moritz
Date: 2007-08-04 10:04:50 -0700 (Sat, 04 Aug 2007)
New Revision: 13438

Modified:
   trunk/ezstream/src/configfile.c
   trunk/ezstream/src/configfile.h
   trunk/ezstream/src/ezstream.c
Log:
Do a clean shutdown on SIGINT and SIGTERM.


Modified: trunk/ezstream/src/configfile.c
===================================================================
--- trunk/ezstream/src/configfile.c	2007-08-04 16:46:17 UTC (rev 13437)
+++ trunk/ezstream/src/configfile.c	2007-08-04 17:04:50 UTC (rev 13438)
@@ -36,7 +36,6 @@
 static EZCONFIG		 ezConfig;
 static const char	*blankString = "";
 
-void	        freeConfig(EZCONFIG *);
 unsigned int	checkDecoderLine(const char *, const char *, long);
 unsigned int	checkEncoderLine(const char *, const char *, long);
 unsigned int	checkFormatLine(const char *, const char *, long);

Modified: trunk/ezstream/src/configfile.h
===================================================================
--- trunk/ezstream/src/configfile.h	2007-08-04 16:46:17 UTC (rev 13437)
+++ trunk/ezstream/src/configfile.h	2007-08-04 17:04:50 UTC (rev 13438)
@@ -71,5 +71,6 @@
 const char *	getFormatEncoder(const char *format);
 const char *	getFormatDecoder(const char *match);
 int		parseConfig(const char *fileName);
+void		freeConfig(EZCONFIG *);
 
 #endif /* __CONFIGFILE_H__ */

Modified: trunk/ezstream/src/ezstream.c
===================================================================
--- trunk/ezstream/src/ezstream.c	2007-08-04 16:46:17 UTC (rev 13437)
+++ trunk/ezstream/src/ezstream.c	2007-08-04 17:04:50 UTC (rev 13438)
@@ -87,17 +87,21 @@
 int			 playlistMode = 0;
 
 #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_notify = 0;
 volatile sig_atomic_t	 skipTrack = 0;
 volatile sig_atomic_t	 queryMetadata = 0;
+volatile sig_atomic_t	 quit = 0;
 #else
 int			 rereadPlaylist = 0;
 int			 rereadPlaylist_notify = 0;
 int			 skipTrack = 0;
 int			 queryMetadata = 0;
+int			 quit = 0;
 #endif /* HAVE_SIGNALS */
 
 typedef struct tag_ID3Tag {
@@ -137,6 +141,10 @@
 sig_handler(int sig)
 {
 	switch (sig) {
+	case SIGTERM:
+	case SIGINT:
+		quit = 1;
+		break;
 	case SIGHUP:
 		rereadPlaylist = 1;
 		rereadPlaylist_notify = 1;
@@ -666,7 +674,10 @@
 
 		printf("%s: Waiting 5s for %s to come back ...\n",
 		       __progname, pezConfig->URL);
-		sleep(5);
+		if (quit)
+			return (0);
+		else
+			sleep(5);
 	};
 
 	printf("%s: Giving up\n", __progname);
@@ -735,6 +746,8 @@
 			}
 		}
 
+		if (quit)
+			break;
 		if (rereadPlaylist_notify) {
 			rereadPlaylist_notify = 0;
 			if (!pezConfig->fileNameIsProgram)
@@ -853,6 +866,8 @@
 	do {
 		ret = sendStream(shout, filepstream, fileName, isStdin, NULL, NULL);
 #endif
+		if (quit)
+			break;
 		if (ret != STREAM_DONE) {
 			if ((skipTrack && rereadPlaylist) ||
 			    (skipTrack && queryMetadata)) {
@@ -944,6 +959,8 @@
 		strlcpy(lastSong, song, sizeof(lastSong));
 		if (!streamFile(shout, song))
 			return (0);
+		if (quit)
+			break;
 		if (rereadPlaylist) {
 			rereadPlaylist = rereadPlaylist_notify = 0;
 			if (pezConfig->fileNameIsProgram)
@@ -994,6 +1011,7 @@
 {
 	shout_shutdown();
 	playlist_shutdown();
+	freeConfig(pezConfig);
 	xalloc_shutdown();
 
 	return (exitval);
@@ -1320,6 +1338,8 @@
 			} else {
 				ret = streamFile(shout, pezConfig->fileName);
 			}
+			if (quit)
+				break;
 			if (pezConfig->streamOnce)
 				break;
 		} while (ret);
@@ -1329,6 +1349,9 @@
 		printf("%s: Connection to http://%s:%d%s failed: %s\n", __progname,
 		       host, port, mount, shout_get_error(shout));
 
+	if (quit)
+		printf("\r%s: SIGINT or SIGTERM received\n", __progname);
+
 	if (vFlag)
 		printf("%s: Exiting ...\n", __progname);
 



More information about the commits mailing list