diff options
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | src/config.c | 1 | ||||
-rw-r--r-- | src/config.h | 4 | ||||
-rw-r--r-- | src/run.c | 3 | ||||
-rw-r--r-- | src/tty.c | 17 |
5 files changed, 20 insertions, 6 deletions
@@ -3,6 +3,7 @@ refactoring lt_run to check the latrace got killed * adding tests for latrace termination * args - replacing destination strings with void pointers + * tty output - move fd to the config struct 2011-05-24 Jiri Olsa <olsajiri@gmail.com> * args - use isprint to decide whether to print the character, diff --git a/src/config.c b/src/config.c index 83b031c..cef8e41 100644 --- a/src/config.c +++ b/src/config.c @@ -342,6 +342,7 @@ int lt_config(struct lt_config_app *cfg, int argc, char **argv) lt_sh(cfg, args_maxlen) = LR_ARGS_MAXLEN; lt_sh(cfg, args_detail_maxlen) = LR_ARGS_DETAIL_MAXLEN; cfg->csort = LT_CSORT_CALL; + cfg->output_tty_fd = -1; /* read the default config file first */ if (read_config(cfg, conf_file)) { diff --git a/src/config.h b/src/config.h index d800b20..1f49273 100644 --- a/src/config.h +++ b/src/config.h @@ -166,7 +166,8 @@ struct lt_config_app { int csort; - int output_tty; + int output_tty; + int output_tty_fd; char output_tty_file[LT_MAXFILE]; struct lt_thread *threads; @@ -360,6 +361,7 @@ int tty_master(struct lt_config_app *cfg); int tty_init(struct lt_config_app *cfg, int master); int tty_restore(struct lt_config_app *cfg); int tty_process(struct lt_config_app *cfg, int master); +void tty_close(struct lt_config_app *cfg); #define PRINT(fmt, args...) \ do { \ @@ -357,8 +357,9 @@ static void run_cleanup(struct lt_config_app *cfg, { if (lt_sh(cfg, pipe)) close(pa->fd_notify); + if (cfg->output_tty) - close(pa->fd_tty_master); + tty_close(cfg); remove_dir(cfg, pa->dir); } @@ -83,12 +83,19 @@ int tty_init(struct lt_config_app *cfg, int master) return 0; } +void tty_close(struct lt_config_app *cfg) +{ + close(cfg->output_tty_fd); +} + int tty_restore(struct lt_config_app *cfg) { int i, num_files = getdtablesize(); - for(i = 0; i < num_files; i++) - close(i); + for(i = 0; i < num_files; i++) { + if (fcntl(i, F_GETFD, NULL) != -1) + close(i); + } open("/dev/tty", O_RDWR); dup(0); @@ -102,9 +109,9 @@ int tty_process(struct lt_config_app *cfg, int master) #define BUFSIZE 4096 char buf[BUFSIZE]; ssize_t ret; - static int fd = 0; + int fd = cfg->output_tty_fd; - if (!fd) { + if (fd == -1) { fd = open(cfg->output_tty_file, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); if (fd < 0) { @@ -114,6 +121,8 @@ int tty_process(struct lt_config_app *cfg, int master) } PRINT_VERBOSE(cfg, 1, "opened tty output file %s\n", cfg->output_tty_file); + + cfg->output_tty_fd = fd; } ret = read(master, buf, BUFSIZE); |