aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
blob: f41ccfbf3ee6ceaba6d84eafa60d091b32abbeef (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
39
40
41
42
43
// WTFPL

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>

#include "consts.h"
#include "config.h"

extern void light_thread(void);
extern void keypress_thread(pid_t _light_pid);

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();

	pid_t keypress_pid = getpid();
	pid_t light_pid = fork();

	if (light_pid == 0) light_thread();
	else				keypress_thread(light_pid);

	return -1;
}