Fix: kernel-consumer: double-close
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 4 Jul 2013 22:06:44 +0000 (18:06 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Fri, 5 Jul 2013 18:59:19 +0000 (14:59 -0400)
check for -1 out_fd

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
src/common/kernel-consumer/kernel-consumer.c

index ac2ac77d6d70a398d7007e2f9faf2355d291d60a..5c0dce45d27e87337c3c3190551522f122c4b49f 100644 (file)
@@ -260,12 +260,14 @@ int lttng_kconsumer_snapshot_channel(uint64_t key, char *path,
                }
 
                if (relayd_id == (uint64_t) -1ULL) {
-                       ret = close(stream->out_fd);
-                       if (ret < 0) {
-                               PERROR("Kernel consumer snapshot close out_fd");
-                               goto end_unlock;
+                       if (stream->out_fd >= 0) {
+                               ret = close(stream->out_fd);
+                               if (ret < 0) {
+                                       PERROR("Kernel consumer snapshot close out_fd");
+                                       goto end_unlock;
+                               }
+                               stream->out_fd = -1;
                        }
-                       stream->out_fd = -1;
                } else {
                        close_relayd_stream(stream);
                        stream->net_seq_idx = (uint64_t) -1ULL;
@@ -357,15 +359,17 @@ int lttng_kconsumer_snapshot_metadata(uint64_t key, char *path,
                close_relayd_stream(metadata_stream);
                metadata_stream->net_seq_idx = (uint64_t) -1ULL;
        } else {
-               ret = close(metadata_stream->out_fd);
-               if (ret < 0) {
-                       PERROR("Kernel consumer snapshot metadata close out_fd");
-                       /*
-                        * Don't go on error here since the snapshot was successful at this
-                        * point but somehow the close failed.
-                        */
+               if (metadata_stream->out_fd >= 0) {
+                       ret = close(metadata_stream->out_fd);
+                       if (ret < 0) {
+                               PERROR("Kernel consumer snapshot metadata close out_fd");
+                               /*
+                                * Don't go on error here since the snapshot was successful at this
+                                * point but somehow the close failed.
+                                */
+                       }
+                       metadata_stream->out_fd = -1;
                }
-               metadata_stream->out_fd = -1;
        }
 
        ret = 0;
This page took 0.028784 seconds and 4 git commands to generate.