blob: 4c0956357d779c5a3cdbd6be24ba22517196150c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
// WTFPL
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>
#include "consts.h"
#include "config.h"
extern int light_thread(void);
extern int keypress_thread(void);
struct timeval* last_press;
void daemonize(void) {
daemon(0, 0);
}
int shared_mem_setup(void) {
last_press = mmap(NULL, sizeof(last_press), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
return 0; // XXX error handling
}
int setup(void) {
daemonize();
shared_mem_setup();
return 0;
}
int main(int argc, const char* argv[]) {
setup();
if (fork() == 0) return light_thread();
else return keypress_thread();
}
|