summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2016-03-01 10:49:24 +1000
committerBenjamin Tissoires <benjamin.tissoires@gmail.com>2016-03-01 15:10:40 +0100
commit26627d4f8a317468edfb3c3b3aa226139fbcc1bf (patch)
tree997b720bbd68ca9e9cc9dd40c87e2f2cd8d5daf2
parent6eeb5474affe6a88fafa2e23332844f813d52024 (diff)
evemu-record: if we have no events, delete the autorestarted file
Keep any file that has events in it and keep the last file (i.e. when evemu-record was cancelled). Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
-rw-r--r--tools/evemu-record.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/tools/evemu-record.c b/tools/evemu-record.c
index 433e224..312254f 100644
--- a/tools/evemu-record.c
+++ b/tools/evemu-record.c
@@ -146,6 +146,7 @@ static bool record_device(int fd, unsigned int timeout, const char *prefix)
{
char *filename = NULL;
bool rc = false;
+ long ftell_start = 0 , ftell_end = 1;
assert(!autorestart || prefix != NULL);
@@ -178,12 +179,15 @@ static bool record_device(int fd, unsigned int timeout, const char *prefix)
fprintf(output, "################################\n");
fprintf(output, "# Waiting for events #\n");
fprintf(output, "################################\n");
- if (autorestart)
+ if (autorestart) {
fprintf(output, "# Autorestart timeout: %d\n", timeout);
+ ftell_start = ftell(output);
+ }
if (evemu_record(output, fd, timeout)) {
fprintf(stderr, "error: could not record device\n");
} else if (autorestart) {
+ ftell_end = ftell(output);
fprintf(output, "# Closing after %ds inactivity\n",
timeout/1000);
}
@@ -192,6 +196,9 @@ static bool record_device(int fd, unsigned int timeout, const char *prefix)
if (output != stdout) {
fclose(output);
output = stdout;
+
+ if (autorestart && ftell_start == ftell_end)
+ unlink(filename);
}
} while (autorestart);