This commit is contained in:
mrbesen 2021-01-09 16:47:17 +01:00
commit 3da2c84c6e
Signed by: MrBesen
GPG Key ID: 596B2350DCD67504
2 changed files with 53 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.log
activity

51
activity.c Executable file
View File

@ -0,0 +1,51 @@
//#!/usr/local/bin/tcc -run
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <time.h>
#include <signal.h>
#include <string.h>
#include <stdbool.h>
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;
}