From 3dbc9de2a57344b61f98d1550508058f9af34c30 Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Sun, 29 May 2011 11:28:51 +0200 Subject: tty output - move fd to the config struct moving tty fd into the config struct, since it's better fit and it's needed for error simulation, which is comming in shortly --- ChangeLog | 1 + src/config.c | 1 + src/config.h | 4 +++- src/run.c | 3 ++- src/tty.c | 17 +++++++++++++---- 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index e5d8801..1ddb043 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 * 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 { \ diff --git a/src/run.c b/src/run.c index 568c97e..9a5fa43 100644 --- a/src/run.c +++ b/src/run.c @@ -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); } diff --git a/src/tty.c b/src/tty.c index a3c460e..5ccc8cf 100644 --- a/src/tty.c +++ b/src/tty.c @@ -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); -- cgit