diff options
author | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2008-11-08 21:59:31 -0500 |
---|---|---|
committer | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2008-11-08 21:59:31 -0500 |
commit | fb72274a8a8a172421111e0b69e31fd7340c5808 (patch) | |
tree | 11790732174219f375b25985d4ee88b2b2ce842e | |
parent | 1db6dd3a2a5e1e5c09c761764614535bee585971 (diff) |
display bytes transferred
-rw-r--r-- | src/ftcat.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/ftcat.c b/src/ftcat.c index f1a269f..7b966fe 100644 --- a/src/ftcat.c +++ b/src/ftcat.c | |||
@@ -12,6 +12,8 @@ | |||
12 | static int fd; | 12 | static int fd; |
13 | static int event_count = 1; | 13 | static int event_count = 1; |
14 | static cmd_t ids[MAX_EVENTS]; | 14 | static cmd_t ids[MAX_EVENTS]; |
15 | static unsigned long total_bytes = 0; | ||
16 | |||
15 | 17 | ||
16 | static int disable_all(int fd) | 18 | static int disable_all(int fd) |
17 | { | 19 | { |
@@ -46,8 +48,10 @@ static void cat2stdout(int fd) | |||
46 | { | 48 | { |
47 | static char buf[4096]; | 49 | static char buf[4096]; |
48 | int rd; | 50 | int rd; |
49 | while ((rd = read(fd, buf, 4096)) > 0) | 51 | while ((rd = read(fd, buf, 4096)) > 0) { |
52 | total_bytes += rd; | ||
50 | fwrite(buf, 1, rd, stdout); | 53 | fwrite(buf, 1, rd, stdout); |
54 | } | ||
51 | } | 55 | } |
52 | 56 | ||
53 | 57 | ||
@@ -62,10 +66,11 @@ static void usage(void) | |||
62 | static void on_sigint(int sig) | 66 | static void on_sigint(int sig) |
63 | { | 67 | { |
64 | close(fd); | 68 | close(fd); |
69 | fflush(stdout); | ||
65 | exit(0); | 70 | exit(0); |
66 | } | 71 | } |
67 | 72 | ||
68 | static void on_sigusr1(int sig) | 73 | static void shutdown(int sig) |
69 | { | 74 | { |
70 | int ok; | 75 | int ok; |
71 | ok = disable_all(fd); | 76 | ok = disable_all(fd); |
@@ -75,18 +80,21 @@ static void on_sigusr1(int sig) | |||
75 | 80 | ||
76 | int main(int argc, char** argv) | 81 | int main(int argc, char** argv) |
77 | { | 82 | { |
83 | const char* trace_file; | ||
78 | if (argc < 3) | 84 | if (argc < 3) |
79 | usage(); | 85 | usage(); |
80 | 86 | ||
81 | fd = open(argv[1], O_RDWR); | 87 | trace_file = argv[1]; |
88 | fd = open(trace_file, O_RDWR); | ||
82 | if (fd < 0) { | 89 | if (fd < 0) { |
83 | perror("could not open feathertrace"); | 90 | perror("could not open feathertrace"); |
84 | return 1; | 91 | return 1; |
85 | } | 92 | } |
86 | argc -= 2; | 93 | argc -= 2; |
87 | argv += 2; | 94 | argv += 2; |
88 | signal(SIGINT, on_sigint); | 95 | signal(SIGINT, shutdown); |
89 | signal(SIGUSR1, on_sigusr1); | 96 | signal(SIGUSR1, shutdown); |
97 | signal(SIGTERM, shutdown); | ||
90 | while (argc--) { | 98 | while (argc--) { |
91 | if (!enable_events(fd, *argv)) { | 99 | if (!enable_events(fd, *argv)) { |
92 | fprintf(stderr, "Enabling %s failed: %m\n", *argv); | 100 | fprintf(stderr, "Enabling %s failed: %m\n", *argv); |
@@ -97,6 +105,8 @@ int main(int argc, char** argv) | |||
97 | 105 | ||
98 | cat2stdout(fd); | 106 | cat2stdout(fd); |
99 | close(fd); | 107 | close(fd); |
108 | fflush(stdout); | ||
109 | fprintf(stderr, "%s: %lu bytes read.\n", trace_file, total_bytes); | ||
100 | return 0; | 110 | return 0; |
101 | } | 111 | } |
102 | 112 | ||