[PATCH v2 evemu 4/4] evemu-record: if we have no events, delete the autorestarted file
Peter Hutterer
peter.hutterer at who-t.net
Tue Mar 1 00:49:24 UTC 2016
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 at who-t.net>
---
Changes to v1:
- commit message reworded it was
tools/evemu-record.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
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);
--
2.5.0
More information about the Input-tools
mailing list