]> git.neil.brown.name Git - gta04-gsm-voice-routing.git/commitdiff
Better handle sigterm, correctly close stream
authorRadek Polak <psonek2@seznam.cz>
Fri, 30 Mar 2012 22:00:02 +0000 (00:00 +0200)
committerRadek Polak <psonek2@seznam.cz>
Fri, 30 Mar 2012 22:00:02 +0000 (00:00 +0200)
gsm-voice-routing.c

index 9e060a284d43be6ef3bc8f0fa2495dce37e66324..f6a6daee0b48da54fb55133da3931e494f6c1001 100644 (file)
@@ -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);