aboutsummaryrefslogtreecommitdiffstats
path: root/src/ftcat.c
diff options
context:
space:
mode:
authorBjoern B. Brandenburg <bbb@cs.unc.edu>2008-05-21 23:59:53 -0400
committerBjoern B. Brandenburg <bbb@cs.unc.edu>2008-05-21 23:59:53 -0400
commit889a3c1661c870ad3742614d42ec19b0bff0230f (patch)
tree8558718210d7856ff0e4fedb2f49b160547a3e4b /src/ftcat.c
parent65d2e481b266c51c5efcc4808be258ef7a13d039 (diff)
add new time stamps and drain on SIGUSR1
Diffstat (limited to 'src/ftcat.c')
-rw-r--r--src/ftcat.c49
1 files changed, 38 insertions, 11 deletions
diff --git a/src/ftcat.c b/src/ftcat.c
index 4d83f56..0afba87 100644
--- a/src/ftcat.c
+++ b/src/ftcat.c
@@ -7,25 +7,37 @@
7 7
8#include "timestamp.h" 8#include "timestamp.h"
9 9
10#define MAX_EVENTS 128
11
10static int fd; 12static int fd;
13static int event_count = 1;
14static unsigned long ids[MAX_EVENTS];
11 15
12static void on_sigint(int sig) 16static int disable_all(int fd)
13{ 17{
14 close(fd); 18 int ret, size;
15 exit(0); 19 ids[0] = DISABLE_CMD;
20 fprintf(stderr, "Disabling %d events.\n", event_count - 1);
21 size = event_count * sizeof(long);
22 ret = write(fd, ids, size);
23 //fprintf(stderr, "write = %d, meant to write %d (%m)\n", ret, size);
24 return size == ret;
16} 25}
17 26
18static int enable_events(int fd, char* str) 27static int enable_events(int fd, char* str)
19{ 28{
20 unsigned long id; 29 unsigned long *id;
21 unsigned long cmd[3]; 30 unsigned long cmd[3];
22 31
23 if (!str2event(str, &id)) 32 id = ids + event_count;
33 if (!str2event(str, id))
24 return 0; 34 return 0;
25 35
36 event_count += 2;
37 id[1] = id[0] + 1;
26 cmd[0] = ENABLE_CMD; 38 cmd[0] = ENABLE_CMD;
27 cmd[1] = id; 39 cmd[1] = id[0];
28 cmd[2] = id + 1; 40 cmd[2] = id[1];
29 return write(fd, cmd, 3 * sizeof(long)) == 3 * sizeof(long); 41 return write(fd, cmd, 3 * sizeof(long)) == 3 * sizeof(long);
30} 42}
31 43
@@ -34,8 +46,8 @@ static void cat2stdout(int fd)
34{ 46{
35 static char buf[4096]; 47 static char buf[4096];
36 int rd; 48 int rd;
37 while ((rd = read(fd, buf, 4096))) 49 while ((rd = read(fd, buf, 4096)) > 0)
38 fwrite(buf, 1, rd, stdout); 50 fwrite(buf, 1, rd, stdout);
39} 51}
40 52
41 53
@@ -49,6 +61,20 @@ static void usage(void)
49 exit(1); 61 exit(1);
50} 62}
51 63
64static void on_sigint(int sig)
65{
66 close(fd);
67 exit(0);
68}
69
70static void on_sigusr1(int sig)
71{
72 int ok;
73 ok = disable_all(fd);
74 if (!ok)
75 fprintf(stderr, "disable_all: %m\n");
76}
77
52int main(int argc, char** argv) 78int main(int argc, char** argv)
53{ 79{
54 if (argc < 3) 80 if (argc < 3)
@@ -61,10 +87,11 @@ int main(int argc, char** argv)
61 } 87 }
62 argc -= 2; 88 argc -= 2;
63 argv += 2; 89 argv += 2;
64 signal(SIGINT,on_sigint); 90 signal(SIGINT, on_sigint);
91 signal(SIGUSR1, on_sigusr1);
65 while (argc--) { 92 while (argc--) {
66 if (!enable_events(fd, *argv)) { 93 if (!enable_events(fd, *argv)) {
67 fprintf(stderr, "Enabling %s failed.\n", *argv); 94 fprintf(stderr, "Enabling %s failed: %m\n", *argv);
68 return 2; 95 return 2;
69 } 96 }
70 argv++; 97 argv++;