diff options
Diffstat (limited to 'src/ftcat.c')
-rw-r--r-- | src/ftcat.c | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/src/ftcat.c b/src/ftcat.c index 61e007f..685f65b 100644 --- a/src/ftcat.c +++ b/src/ftcat.c | |||
@@ -24,43 +24,52 @@ | |||
24 | #include <unistd.h> | 24 | #include <unistd.h> |
25 | #include <errno.h> | 25 | #include <errno.h> |
26 | 26 | ||
27 | #include <sys/ioctl.h> | ||
28 | |||
27 | #include "timestamp.h" | 29 | #include "timestamp.h" |
28 | 30 | ||
29 | #define MAX_EVENTS 128 | 31 | #define MAX_EVENTS 128 |
30 | 32 | ||
31 | static int fd; | 33 | static int fd; |
32 | static int event_count = 1; | 34 | static int event_count = 0; |
33 | static cmd_t ids[MAX_EVENTS]; | 35 | static cmd_t ids[MAX_EVENTS]; |
34 | static unsigned long total_bytes = 0; | 36 | static unsigned long total_bytes = 0; |
35 | 37 | ||
36 | 38 | ||
37 | static int disable_all(int fd) | 39 | static int disable_all(int fd) |
38 | { | 40 | { |
39 | int ret, size; | 41 | int disabled = 0; |
40 | ids[0] = DISABLE_CMD; | 42 | int i; |
41 | fprintf(stderr, "Disabling %d events.\n", event_count - 1); | 43 | |
42 | size = event_count * sizeof(cmd_t); | 44 | fprintf(stderr, "Disabling %d events.\n", event_count); |
43 | ret = write(fd, ids, size); | 45 | for (i = 0; i < event_count; i++) |
44 | if (ret != size) | 46 | if (ioctl(fd, DISABLE_CMD, ids[i]) < 0) |
45 | fprintf(stderr, "write = %d, meant to write %d (%m)\n", ret, size); | 47 | perror("ioctl(DISABLE_CMD)"); |
46 | return size == ret; | 48 | else |
49 | disabled++; | ||
50 | |||
51 | return disabled == event_count; | ||
47 | } | 52 | } |
48 | 53 | ||
49 | static int enable_event(int fd, char* str) | 54 | static int enable_event(int fd, char* str) |
50 | { | 55 | { |
51 | cmd_t *id; | 56 | cmd_t *id; |
52 | cmd_t cmd[2]; | 57 | int err; |
53 | 58 | ||
54 | id = ids + event_count; | 59 | id = ids + event_count; |
55 | if (!str2event(str, id)) { | 60 | if (!str2event(str, id)) { |
56 | errno = EINVAL; | 61 | errno = EINVAL; |
57 | return 0; | 62 | return 0; |
58 | } | 63 | } |
59 | |||
60 | event_count += 1; | 64 | event_count += 1; |
61 | cmd[0] = ENABLE_CMD; | 65 | |
62 | cmd[1] = id[0]; | 66 | err = ioctl(fd, ENABLE_CMD, *id); |
63 | return write(fd, cmd, sizeof(cmd)) == sizeof(cmd_t) * 2; | 67 | |
68 | if (err < 0) | ||
69 | printf("ioctl(%d, %d, %d) => %d (errno: %d)\n", fd, (int) ENABLE_CMD, *id, | ||
70 | err, errno); | ||
71 | |||
72 | return err == 0; | ||
64 | } | 73 | } |
65 | 74 | ||
66 | 75 | ||