lttd: 0.75, improve error handling of file open
[ltt-control.git] / lttd / lttd.c
index f21c411eb8940de479fb62980917c6880fae7e99..b2e7127833141da0f66515918f73af51444398d1 100644 (file)
@@ -320,15 +320,26 @@ int open_buffer_file(char *filename, char *path_channel, char *path_trace,
                                                S_IRWXU|S_IRWXG|S_IRWXO);
                        if(fd_pairs->pair[fd_pairs->num_pairs-1].trace == -1) {
                                perror(path_trace);
+                               open_ret = -1;
+                               close(fd_pairs->pair[fd_pairs->num_pairs-1].channel);
+                               fd_pairs->num_pairs--;
+                               goto end;
                        }
                        ret = lseek(fd_pairs->pair[fd_pairs->num_pairs-1].trace,
                                    0, SEEK_END);
                        if (ret < 0) {
                                perror(path_trace);
+                               open_ret = -1;
+                               close(fd_pairs->pair[fd_pairs->num_pairs-1].channel);
+                               close(fd_pairs->pair[fd_pairs->num_pairs-1].trace);
+                               fd_pairs->num_pairs--;
+                               goto end;
                        }
                } else {
                        printf("File %s exists, cannot open. Try append mode.\n", path_trace);
                        open_ret = -1;
+                       close(fd_pairs->pair[fd_pairs->num_pairs-1].channel);
+                       fd_pairs->num_pairs--;
                        goto end;
                }
        } else {
@@ -338,6 +349,10 @@ int open_buffer_file(char *filename, char *path_channel, char *path_trace,
                                                S_IRWXU|S_IRWXG|S_IRWXO);
                        if(fd_pairs->pair[fd_pairs->num_pairs-1].trace == -1) {
                                perror(path_trace);
+                               open_ret = -1;
+                               close(fd_pairs->pair[fd_pairs->num_pairs-1].channel);
+                               fd_pairs->num_pairs--;
+                               goto end;
                        }
                }
        }
@@ -472,14 +487,14 @@ int read_subbuffer(struct fd_pair *pair)
                printf_verbose("splice chan to pipe offset %lu\n",
                        (unsigned long)offset);
                ret = splice(pair->channel, &offset, thread_pipe[1], NULL,
-                       len, SPLICE_F_MOVE);
+                       len, SPLICE_F_MOVE | SPLICE_F_MORE);
                printf_verbose("splice chan to pipe ret %ld\n", ret);
                if (ret < 0) {
                        perror("Error in relay splice");
                        goto write_error;
                }
                ret = splice(thread_pipe[0], NULL, pair->trace, NULL,
-                       ret, SPLICE_F_MOVE);
+                       ret, SPLICE_F_MOVE | SPLICE_F_MORE);
                printf_verbose("splice pipe to file %ld\n", ret);
                if (ret < 0) {
                        perror("Error in file splice");
This page took 0.022956 seconds and 4 git commands to generate.