summaryrefslogtreecommitdiffstats
path: root/src/tty.c
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@redhat.com>2011-05-29 11:28:51 +0200
committerJiri Olsa <Jiri Olsa jolsa@redhat.com>2011-05-29 19:05:55 +0200
commit3dbc9de2a57344b61f98d1550508058f9af34c30 (patch)
treee97cf848463eb815b2b062cd558bec9e838074f5 /src/tty.c
parent7a2b45ec4873e2d51e0d92197dc412a2edb21b32 (diff)
downloadlatrace-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/tty.c')
-rw-r--r--src/tty.c17
1 files changed, 13 insertions, 4 deletions
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);