From 1ee8f63e50275f083b5ab1836658e50a49c1e330 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Sun, 15 Nov 2009 02:12:14 -0500 Subject: [PATCH] lttd: 0.75, improve error handling of file open Signed-off-by: Mathieu Desnoyers --- configure.in | 2 +- lttd/lttd.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/configure.in b/configure.in index 51e8f26..82cc2c3 100644 --- a/configure.in +++ b/configure.in @@ -23,7 +23,7 @@ AC_PREREQ(2.57) AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS) #AC_WITH_LTDL # not needed ? -AM_INIT_AUTOMAKE(ltt-control,0.74-12112009) +AM_INIT_AUTOMAKE(ltt-control,0.75-15112009) AM_CONFIG_HEADER(config.h) AM_PROG_LIBTOOL diff --git a/lttd/lttd.c b/lttd/lttd.c index 61d2468..b2e7127 100644 --- a/lttd/lttd.c +++ b/lttd/lttd.c @@ -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; } } } -- 2.34.1