diff options
author | Jiri Olsa <Jiri Olsa jolsa@redhat.com> | 2010-04-06 10:55:42 +0200 |
---|---|---|
committer | Jiri Olsa <Jiri Olsa jolsa@redhat.com> | 2010-04-06 10:55:42 +0200 |
commit | 6ec8cd6803ea46fed6b106c9fe7c7aeaa7ac54e9 (patch) | |
tree | cd9c62394d52844d1718c01430ed932263bc4dcc /src | |
parent | 2db562a5587d7e5ca8ca0436c9678f8141734e04 (diff) | |
download | tsnif-6ec8cd6803ea46fed6b106c9fe7c7aeaa7ac54e9.tar.gz tsnif-6ec8cd6803ea46fed6b106c9fe7c7aeaa7ac54e9.tar.xz tsnif-6ec8cd6803ea46fed6b106c9fe7c7aeaa7ac54e9.zip |
fixes for slave/master display
Diffstat (limited to 'src')
-rw-r--r-- | src/storage-mmap.c | 40 | ||||
-rw-r--r-- | src/storage-mmap.h | 1 | ||||
-rw-r--r-- | src/storage.h | 10 | ||||
-rw-r--r-- | src/test-storage-mmap.c | 27 | ||||
-rw-r--r-- | src/test.c | 12 | ||||
-rw-r--r-- | src/test.h | 13 | ||||
-rw-r--r-- | src/tsnif-replay.c | 35 | ||||
-rw-r--r-- | src/tsnif.c | 9 |
8 files changed, 124 insertions, 23 deletions
diff --git a/src/storage-mmap.c b/src/storage-mmap.c index 6fa4565..232a442 100644 --- a/src/storage-mmap.c +++ b/src/storage-mmap.c @@ -20,8 +20,10 @@ static int write_header(int fd, struct tsnif_storage_opts *opts) struct tsnif_storage_header_mmap header = { .common = { - .magic = TSNIF_HEADER_MAGIC, - .type = TSNIF_STORAGE_TYPE_MMAP, + .magic = TSNIF_HEADER_MAGIC, + .version = TSNIF_STORAGE_VERSION, + .storage_type = TSNIF_STORAGE_TYPE_MMAP, + .term_type = opts->term_type, }, .size_max = opts->size_max, }; @@ -51,11 +53,36 @@ static int map_header(struct tsnif_storage_handle *h) return 0; } +static int check_header(struct tsnif_storage_handle *h) +{ + struct tsnif_storage_header_mmap *header = h->header; + struct tsnif_storage_header *common = &header->common; + + if (common->magic != TSNIF_HEADER_MAGIC) { + TSNIF_DEBUG("failed: wrong header magic %x\n", common->magic); + return -1; + } + + if (common->version != TSNIF_STORAGE_VERSION) { + TSNIF_DEBUG("failed: wrong storage version %x\n", common->version); + return -1; + } + + if (common->storage_type != TSNIF_STORAGE_TYPE_MMAP) { + TSNIF_DEBUG("failed: wrong storage type %x\n", common->storage_type); + return -1; + } + + TSNIF_DEBUG("got terminal type %d\n", common->term_type); + return 0; +} + int tsnif_storage_init(struct tsnif_storage_handle *h, struct tsnif_storage_opts *opts, char *name) { int fd, create, err; int flags = O_RDONLY; + int mode = S_IRUSR | S_IWUSR; if (!opts) return -1; @@ -71,7 +98,7 @@ int tsnif_storage_init(struct tsnif_storage_handle *h, if (create) flags |= O_CREAT | O_TRUNC | O_RDWR; - fd = open(name, flags); + fd = open(name, flags, mode); if (fd < 0) { TSNIF_DEBUG("open failed for '%s': %s\n", name, strerror(errno)); @@ -106,6 +133,8 @@ int tsnif_storage_init(struct tsnif_storage_handle *h, return err; h->file_size = st.st_size; + + return check_header(h); } return 0; @@ -459,3 +488,8 @@ int tsnif_storage_read(struct tsnif_storage_handle *h, int what, return read_rec(h, rec, what); } + +int tsnif_storage_term_type(struct tsnif_storage_handle *h) +{ + return h->header->common.term_type; +} diff --git a/src/storage-mmap.h b/src/storage-mmap.h index 8b00934..22dffb7 100644 --- a/src/storage-mmap.h +++ b/src/storage-mmap.h @@ -32,6 +32,7 @@ struct tsnif_storage_opts { int size_max; uint flags; int chunk_size; + int term_type; }; struct tsnif_storage_chunk { diff --git a/src/storage.h b/src/storage.h index 2099059..e6972ce 100644 --- a/src/storage.h +++ b/src/storage.h @@ -9,14 +9,17 @@ struct tsnif_storage_handle; struct tsnif_storage_opts; enum { - TSNIF_STORAGE_TYPE_MMAP, + TSNIF_STORAGE_TYPE_MMAP = 1, }; -#define TSNIF_HEADER_MAGIC 0xdeadfeed +#define TSNIF_HEADER_MAGIC 0xdeadbeaf +#define TSNIF_STORAGE_VERSION 0x1 struct tsnif_storage_header { uint32_t magic; - uint32_t type; + uint32_t version; + uint32_t storage_type; + uint32_t term_type; }; enum { @@ -45,6 +48,7 @@ int tsnif_storage_write(struct tsnif_storage_handle *h, struct tsnif_storage_rec *rec); int tsnif_storage_read(struct tsnif_storage_handle *h, int what, struct tsnif_storage_rec *rec); +int tsnif_storage_term_type(struct tsnif_storage_handle *h); /* TODO make CONFIG option and ifdef this place */ #include "storage-mmap.h" diff --git a/src/test-storage-mmap.c b/src/test-storage-mmap.c index 44f3571..e5ab736 100644 --- a/src/test-storage-mmap.c +++ b/src/test-storage-mmap.c @@ -19,8 +19,9 @@ int test_storage_mmap_init(void) struct tsnif_storage_handle handle; struct tsnif_storage_header_mmap *header; struct tsnif_storage_opts opts = { - .flags = TSNIF_STORAGE_OPT_WRITE | TSNIF_STORAGE_OPT_WRITE, - .size_max = 1024*1024, + .flags = TSNIF_STORAGE_OPT_WRITE | TSNIF_STORAGE_OPT_WRITE, + .size_max = 1024*1024, + .term_type = 1, }; TEST_ASSERT(0 == tsnif_storage_init(&handle, &opts, FILENAME), out); @@ -30,9 +31,12 @@ int test_storage_mmap_init(void) TEST_ASSERT(handle.fd != 0, out_free); TEST_ASSERT(handle.header != NULL, out_free); + /* header check before when creating new file */ header = handle.header; TEST_ASSERT(header->common.magic == TSNIF_HEADER_MAGIC, out_free); - TEST_ASSERT(header->common.type == TSNIF_STORAGE_TYPE_MMAP, out_free); + TEST_ASSERT(header->common.storage_type == TSNIF_STORAGE_TYPE_MMAP, out_free); + TEST_ASSERT(header->common.term_type == 1, out_free); + TEST_ASSERT(header->common.version == TSNIF_STORAGE_VERSION, out_free); TEST_ASSERT(header->size_max == opts.size_max, out_free); out_free: @@ -49,9 +53,11 @@ int test_storage_mmap_open(void) { int rc = 0; struct tsnif_storage_handle handle; + struct tsnif_storage_header_mmap *header; struct tsnif_storage_opts opts = { - .flags = TSNIF_STORAGE_OPT_WRITE | TSNIF_STORAGE_OPT_WRITE, - .size_max = 1024*1024, + .flags = TSNIF_STORAGE_OPT_WRITE, + .size_max = 1024*1024, + .term_type = 1, }; TEST_ASSERT(0 == tsnif_storage_init(&handle, &opts, FILENAME), out); @@ -59,6 +65,17 @@ int test_storage_mmap_open(void) opts.flags = TSNIF_STORAGE_OPT_READ; TEST_ASSERT(0 == tsnif_storage_init(&handle, &opts, FILENAME), out); + + /* header check before when opening file */ + header = handle.header; + TEST_ASSERT(header->common.magic == TSNIF_HEADER_MAGIC, out_free); + TEST_ASSERT(header->common.storage_type == TSNIF_STORAGE_TYPE_MMAP, out_free); + TEST_ASSERT(header->common.term_type == 1, out_free); + TEST_ASSERT(header->common.version == TSNIF_STORAGE_VERSION, out_free); + TEST_ASSERT(header->size_max == opts.size_max, out_free); + TEST_ASSERT(tsnif_storage_term_type(&handle) == 1, out_free); + +out_free: TEST_ASSERT(0 == tsnif_storage_close(&handle), out); out: @@ -10,10 +10,10 @@ do { \ printf("FAILED test " # test "\n"); \ goto out; \ } \ - printf("\n"); \ } while(0) int tsnif_debug = 0; +int assert_debug = 0; static void usage() { @@ -23,6 +23,8 @@ static void usage() static int get_args(int argc, char **argv) { + int debug = 0; + while (1) { int c; int option_index = 0; @@ -39,7 +41,7 @@ static int get_args(int argc, char **argv) switch (c) { case 'd': - tsnif_debug = 1; + debug++; break; default: @@ -47,6 +49,12 @@ static int get_args(int argc, char **argv) } /* switch(c) */ } /* while(1) */ + if (debug > 1) + tsnif_debug = 1; + + if (debug > 0) + assert_debug = 1; + return 0; } @@ -5,19 +5,24 @@ #include <stdio.h> #include "intf.h" +extern int assert_debug; + #define TEST_ASSERT(cond, out_label) \ do { \ - printf(" ASSERT '" #cond "' ... "); \ + if (assert_debug) \ + printf(" ASSERT '" #cond "' ... "); \ if (tsnif_debug) \ printf("\n"); \ if (!(cond)) { \ rc = -1; \ printf("FAILED\n"); \ - printf(" ^^^^^^ %s:%d function %s\n",\ - __FILE__, __LINE__, __FUNCTION__); \ + if (assert_debug) \ + printf(" ^^^^^^ %s:%d function %s\n",\ + __FILE__, __LINE__, __FUNCTION__); \ goto out_label; \ } \ - printf("OK\n"); \ + if (assert_debug) \ + printf("OK\n"); \ } while(0) #endif /* TEST_H */ diff --git a/src/tsnif-replay.c b/src/tsnif-replay.c index 40db4da..2e4700a 100644 --- a/src/tsnif-replay.c +++ b/src/tsnif-replay.c @@ -111,10 +111,41 @@ static int display_slave = 1; static int display_master= 0; static int play = 1; +static int display_pty(int flags) +{ + if ((flags == TSNIF_FLAGS_PTY_SLAVE) && + !display_slave) + return 0; + + if ((flags == TSNIF_FLAGS_PTY_MASTER) && + !display_master) + return 0; + + return 1; +} + static int output(struct tsnif_storage_rec *rec) { - fwrite(rec->ptr, rec->len, 1, stdout); - fflush(NULL); + int type = tsnif_storage_term_type(&storage_handle); + + switch(type) { + case TSNIF_TYPE_PTY: + /* follow the user pty display settings */ + if (!display_pty(rec->flags)) + return 0; + + /* fallback intentionally */ + + case TSNIF_TYPE_TTY: + case TSNIF_TYPE_TTYS: + fwrite(rec->ptr, rec->len, 1, stdout); + fflush(NULL); + break; + + default: + printf("failed: got unknown terminal type %d\n", type); + } + return 0; } diff --git a/src/tsnif.c b/src/tsnif.c index aca8e56..643424f 100644 --- a/src/tsnif.c +++ b/src/tsnif.c @@ -58,6 +58,9 @@ static int store_data(struct tsnif_data *data) static int data_cb(struct tsnif_term* term, struct tsnif_data *data) { + if (store) + store_data(data); + /* rule out unwanted PTY channel */ if ((term->type == TSNIF_TYPE_PTY) && !display_pty(data->flags)) @@ -65,10 +68,6 @@ static int data_cb(struct tsnif_term* term, struct tsnif_data *data) fwrite(data->ptr, data->len, 1, stdout); fflush(NULL); - - if (store) - return store_data(data); - return 0; } @@ -249,6 +248,8 @@ int main(int argc, char **argv) if (err) longjmp(env, 1); + storage_opts.term_type = type; + /* initialize storage unit if needed */ if (store) { err = tsnif_storage_init(&storage_handle, &storage_opts, storage_file); |