diff options
author | Jiri Olsa <jolsa@redhat.com> | 2011-05-29 11:28:51 +0200 |
---|---|---|
committer | Jiri Olsa <Jiri Olsa jolsa@redhat.com> | 2011-05-29 19:05:55 +0200 |
commit | 3dbc9de2a57344b61f98d1550508058f9af34c30 (patch) | |
tree | e97cf848463eb815b2b062cd558bec9e838074f5 /src | |
parent | 7a2b45ec4873e2d51e0d92197dc412a2edb21b32 (diff) | |
download | latrace-3dbc9de2a57344b61f98d1550508058f9af34c30.tar.gz latrace-3dbc9de2a57344b61f98d1550508058f9af34c30.tar.xz latrace-3dbc9de2a57344b61f98d1550508058f9af34c30.zip |
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
Diffstat (limited to 'src')
-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 |
4 files changed, 19 insertions, 6 deletions
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); |