[PATCH evemu 3/3] evemu-record: if we have no events, delete the autorestarted file

Peter Hutterer peter.hutterer at who-t.net
Fri Feb 26 02:53:01 UTC 2016


The last file (when evemu-record was cancelled) remains.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 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 8a78cd1..4346bc9 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