From 3da2c84c6eafcb3aa69cf35c5255dcb163b7135d Mon Sep 17 00:00:00 2001 From: mrbesen Date: Sat, 9 Jan 2021 16:47:17 +0100 Subject: [PATCH] initial --- .gitignore | 2 ++ activity.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 .gitignore create mode 100755 activity.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d048bad --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.log +activity \ No newline at end of file diff --git a/activity.c b/activity.c new file mode 100755 index 0000000..0aec3a6 --- /dev/null +++ b/activity.c @@ -0,0 +1,51 @@ +//#!/usr/local/bin/tcc -run + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +const int BUFFSIZE = 128; +bool shouldrun = true; + +void sighand(int sig) { + shouldrun = false; +} + +int main(int argc, char** argv) { + if(argc != 2) { + printf("Usage: %s logfile\n", argv[0]); + return 1; + } + + int log = 1; + if(strcmp(argv[1], "-")) + log = open(argv[1], O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR); + + signal(SIGINT, sighand); + + int dev = open("/dev/input/mice", O_RDONLY); + + time_t last = 0; + + while(shouldrun) { + char buff[BUFFSIZE]; + int r = read(dev, buff, BUFFSIZE); + time_t curr = time(NULL); + if(curr != last) { + //dprintf(log, "%ld\n", curr); + write(log, &curr, sizeof(curr)); + last = curr; + } + } + + close(dev); + if(log != 1) + close(log); + return 0; +} \ No newline at end of file