From 70b661aa9a185316552db98d2775db898a95d816 Mon Sep 17 00:00:00 2001 From: Radek Polak Date: Sat, 31 Mar 2012 00:00:02 +0200 Subject: [PATCH] Better handle sigterm, correctly close stream --- gsm-voice-routing.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) 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); -- 2.39.5