Merge lp:~jpakkane/evemu/robustness into lp:evemu

Proposed by Jussi Pakkanen
Status: Merged
Merged at revision: 41
Proposed branch: lp:~jpakkane/evemu/robustness
Merge into: lp:evemu
Diff against target: 77 lines (+38/-2)
2 files modified
src/evemu.c (+1/-0)
tools/evemu-record.c (+37/-2)
To merge this branch: bzr merge lp:~jpakkane/evemu/robustness
Reviewer Review Type Date Requested Status
Stephen M. Webb (community) Approve
Chase Douglas (community) Approve
Review via email: mp+66123@code.launchpad.net

Description of the change

Makes evemu-record write its output more robustly. Flush every event write and allow the user to specify an output file.

To post a comment you must log in.
lp:~jpakkane/evemu/robustness updated
43. By Jussi Pakkanen

Add signal handler to flush data in case of abrupt exit.

44. By Jussi Pakkanen

Indentation fix.

Revision history for this message
Chase Douglas (chasedouglas) wrote :

Looks good to me, and fixes a long standing issue :).

review: Approve
Revision history for this message
Stephen M. Webb (bregma) wrote :

Does the right thing.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/evemu.c'
--- src/evemu.c 2011-04-21 08:49:45 +0000
+++ src/evemu.c 2011-06-28 16:24:39 +0000
@@ -379,6 +379,7 @@
379 return ret;379 return ret;
380 if (ret == sizeof(ev))380 if (ret == sizeof(ev))
381 evemu_write_event(fp, &ev);381 evemu_write_event(fp, &ev);
382 fflush(fp);
382 }383 }
383384
384 return 0;385 return 0;
385386
=== modified file 'tools/evemu-record.c'
--- tools/evemu-record.c 2011-02-03 02:29:13 +0000
+++ tools/evemu-record.c 2011-06-28 16:24:39 +0000
@@ -45,14 +45,24 @@
45#include <fcntl.h>45#include <fcntl.h>
46#include <string.h>46#include <string.h>
47#include <unistd.h>47#include <unistd.h>
48#include <signal.h>
4849
49#define WAIT_MS 1000050#define WAIT_MS 10000
5051
52FILE *output;
53
54static void handler (int sig)
55{
56 fflush(output);
57 if (output != stdout)
58 fclose(output);
59}
60
51int main(int argc, char *argv[])61int main(int argc, char *argv[])
52{62{
53 int fd;63 int fd;
54 if (argc < 2) {64 if (argc < 2) {
55 fprintf(stderr, "Usage: %s <device>\n", argv[0]);65 fprintf(stderr, "Usage: %s <device> [output file]\n", argv[0]);
56 return -1;66 return -1;
57 }67 }
58 fd = open(argv[1], O_RDONLY | O_NONBLOCK);68 fd = open(argv[1], O_RDONLY | O_NONBLOCK);
@@ -60,9 +70,34 @@
60 fprintf(stderr, "error: could not open device\n");70 fprintf(stderr, "error: could not open device\n");
61 return -1;71 return -1;
62 }72 }
63 if (evemu_record(stdout, fd, WAIT_MS)) {73
74 struct sigaction act;
75 memset (&act, '\0', sizeof(act));
76 act.sa_handler = &handler;
77
78 if (sigaction(SIGTERM, &act, NULL) < 0) {
79 fprintf (stderr, "Could not attach TERM signal handler.\n");
80 return 1;
81 }
82 if (sigaction(SIGINT, &act, NULL) < 0) {
83 fprintf (stderr, "Could not attach INT signal handler.\n");
84 return 1;
85 }
86
87 if (argc < 3)
88 output = stdout;
89 else {
90 output = fopen(argv[2], "w");
91 if (!output) {
92 fprintf(stderr, "error: could not open output file");
93 }
94 }
95
96 if (evemu_record(output, fd, WAIT_MS)) {
64 fprintf(stderr, "error: could not describe device\n");97 fprintf(stderr, "error: could not describe device\n");
65 }98 }
66 close(fd);99 close(fd);
100 if (output != stdout)
101 fclose(output);
67 return 0;102 return 0;
68}103}

Subscribers

People subscribed via source and target branches