From: Radek Polak Date: Fri, 30 Mar 2012 22:00:02 +0000 (+0200) Subject: Better handle sigterm, correctly close stream X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=70b661aa9a185316552db98d2775db898a95d816;p=gta04-gsm-voice-routing.git Better handle sigterm, correctly close stream --- diff --git a/gsm-voice-routing.c b/gsm-voice-routing.c index 9e060a2..f6a6dae 100644 --- a/gsm-voice-routing.c +++ b/gsm-voice-routing.c @@ -122,6 +122,10 @@ struct route_stream static int err(const char *msg, int snd_err, struct route_stream *s, int return_code) { + if(terminating) { + return ERR_TERMINATING; + } + fprintf(logfile, "%s (%s): %s", s->id, s->pcm_name, msg); if (snd_err < 0) { fprintf(logfile, ": %s", snd_strerror(snd_err)); @@ -262,10 +266,12 @@ static int close_route_stream(struct route_stream *s) return 0; } snd_pcm_close(s->handle); + s->handle = 0; if (s->period_buffer == 0) { return 0; } free(s->period_buffer); + s->period_buffer = 0; return 0; } @@ -296,10 +302,6 @@ static int route_stream_read(struct route_stream *s) return 0; } - if (terminating) { - return ERR_TERMINATING; - } - /* EPIPE means overrun */ if (rc == -EPIPE) { err("overrun occured", rc, s, ERR_READ_OVERRUN); @@ -327,10 +329,6 @@ static int route_stream_write(struct route_stream *s) return 0; } - if (terminating) { - return ERR_TERMINATING; - } - /* EPIPE means underrun */ if (rc == -EPIPE) { err("underrun occured", rc, s, ERR_WRITE_UNDERRUN);