diff --git a/Makefile b/Makefile index 0ee8cb4..fbb3d45 100644 --- a/Makefile +++ b/Makefile @@ -2,9 +2,21 @@ Q=@ CC=gcc GCCCFLAGS=-Wno-format-truncation -CFLAGS=-std=c11 -pedantic -g -Wall -pthread -D_GNU_SOURCE -DVERBOSE +CFLAGS=-std=c11 -pedantic -g -Wall -pthread -D_GNU_SOURCE LDFLAGS=-lm +# The root for /sys and /dev needs to be moved in docker, this should stay empty in most cases +FSROOT="" + +# enable VERBOSE if VERBOSE=1 +ifeq ($(VERBOSE),1) + CFLAGS+=-DVERBOSE +endif + +ifdef FSROOT + CFLAGS+=-D_FSROOT=$(FSROOT) +endif + BUILD_DIR=./objects BIN=jsfw diff --git a/client.c b/client.c index 3f47ebb..726c8d7 100644 --- a/client.c +++ b/client.c @@ -103,6 +103,8 @@ static const JSONAdapter ConfigAdapter = { .size = sizeof(ClientConfig), }; +static void print_config() __attribute__((unused)); + // Print the current config, for debugging purposes static void print_config() { printf("CLIENT: Config\n"); @@ -282,7 +284,7 @@ void setup_devices(void) { no_info.code = NoMessage; for (int i = 0; i < config.slot_count; i++) { - int fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK); + int fd = open(FSROOT "/dev/uinput", O_WRONLY | O_NONBLOCK); if (fd < 0) { perror("CLIENT: Can't open /dev/uinput, aborting now"); exit(1); diff --git a/const.h b/const.h index 93e9b67..c5da739 100644 --- a/const.h +++ b/const.h @@ -4,6 +4,14 @@ #include #include +#ifndef _FSROOT +#define FSROOT "" +#else +#define __str(a) #a +#define _str(a) __str(a) +#define FSROOT _str(_FSROOT) +#endif + extern const struct timespec POLL_DEVICE_INTERVAL; extern const int REQUEST_TIMEOUT; extern const char *DEVICE_DEFAULT_NAME; diff --git a/hid.c b/hid.c index 6d10aea..27c0050 100644 --- a/hid.c +++ b/hid.c @@ -281,7 +281,7 @@ uint64_t parse_event_name(const char *event) { return atol(event + 5); } // Find all available devices and pick up on new ones void poll_devices(void) { // loop over all entries of /sys/class/input - DIR *input_dir = opendir("/sys/class/input"); + DIR *input_dir = opendir(FSROOT "/sys/class/input"); struct dirent *input; while ((input = readdir(input_dir)) != NULL) { @@ -298,7 +298,7 @@ void poll_devices(void) { // Open /dev/input/eventXX { char event_path[64]; - snprintf(event_path, 64, "/dev/input/%s", input->d_name); + snprintf(event_path, 64, FSROOT "/dev/input/%s", input->d_name); dev.event = open(event_path, O_RDONLY); @@ -372,7 +372,7 @@ void poll_devices(void) { char hidraw_path[64]; { char hidraw_dir_path[256]; - snprintf(hidraw_dir_path, 256, "/sys/class/input/%s/device/device/hidraw", input->d_name); + snprintf(hidraw_dir_path, 256, FSROOT "/sys/class/input/%s/device/device/hidraw", input->d_name); DIR *hidraw_dir = opendir(hidraw_dir_path); struct dirent *hidraw = NULL; @@ -387,7 +387,7 @@ void poll_devices(void) { goto skip; } - snprintf(hidraw_path, 64, "/dev/%s", hidraw->d_name); + snprintf(hidraw_path, 64, FSROOT "/dev/%s", hidraw->d_name); closedir(hidraw_dir); } diff --git a/server.c b/server.c index de58dd9..8b0e689 100644 --- a/server.c +++ b/server.c @@ -88,6 +88,8 @@ static sigset_t empty_sigset; if (sigaction(sig, &(struct sigaction){{SIG_IGN}}, NULL) != 0) \ printf("SERVER: can't ignore " #sig ".\n") +static void print_config() __attribute__((unused)); + static void print_config() { printf("SERVER: Config\n"); printf(" retry_delay: %fs\n", (double)(config.request_timeout) / 1000.0);