Allow moving route for docker

This commit is contained in:
viandoxdev 2023-04-15 18:24:25 +02:00
parent 6f76aef797
commit 9d728679fb
No known key found for this signature in database
GPG Key ID: AF1410C5BC10AA25
5 changed files with 30 additions and 6 deletions

View File

@ -2,9 +2,21 @@ Q=@
CC=gcc CC=gcc
GCCCFLAGS=-Wno-format-truncation 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 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 BUILD_DIR=./objects
BIN=jsfw BIN=jsfw

View File

@ -103,6 +103,8 @@ static const JSONAdapter ConfigAdapter = {
.size = sizeof(ClientConfig), .size = sizeof(ClientConfig),
}; };
static void print_config() __attribute__((unused));
// Print the current config, for debugging purposes // Print the current config, for debugging purposes
static void print_config() { static void print_config() {
printf("CLIENT: Config\n"); printf("CLIENT: Config\n");
@ -282,7 +284,7 @@ void setup_devices(void) {
no_info.code = NoMessage; no_info.code = NoMessage;
for (int i = 0; i < config.slot_count; i++) { 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) { if (fd < 0) {
perror("CLIENT: Can't open /dev/uinput, aborting now"); perror("CLIENT: Can't open /dev/uinput, aborting now");
exit(1); exit(1);

View File

@ -4,6 +4,14 @@
#include <stdint.h> #include <stdint.h>
#include <time.h> #include <time.h>
#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 struct timespec POLL_DEVICE_INTERVAL;
extern const int REQUEST_TIMEOUT; extern const int REQUEST_TIMEOUT;
extern const char *DEVICE_DEFAULT_NAME; extern const char *DEVICE_DEFAULT_NAME;

8
hid.c
View File

@ -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 // Find all available devices and pick up on new ones
void poll_devices(void) { void poll_devices(void) {
// loop over all entries of /sys/class/input // 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; struct dirent *input;
while ((input = readdir(input_dir)) != NULL) { while ((input = readdir(input_dir)) != NULL) {
@ -298,7 +298,7 @@ void poll_devices(void) {
// Open /dev/input/eventXX // Open /dev/input/eventXX
{ {
char event_path[64]; 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); dev.event = open(event_path, O_RDONLY);
@ -372,7 +372,7 @@ void poll_devices(void) {
char hidraw_path[64]; char hidraw_path[64];
{ {
char hidraw_dir_path[256]; 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); DIR *hidraw_dir = opendir(hidraw_dir_path);
struct dirent *hidraw = NULL; struct dirent *hidraw = NULL;
@ -387,7 +387,7 @@ void poll_devices(void) {
goto skip; goto skip;
} }
snprintf(hidraw_path, 64, "/dev/%s", hidraw->d_name); snprintf(hidraw_path, 64, FSROOT "/dev/%s", hidraw->d_name);
closedir(hidraw_dir); closedir(hidraw_dir);
} }

View File

@ -88,6 +88,8 @@ static sigset_t empty_sigset;
if (sigaction(sig, &(struct sigaction){{SIG_IGN}}, NULL) != 0) \ if (sigaction(sig, &(struct sigaction){{SIG_IGN}}, NULL) != 0) \
printf("SERVER: can't ignore " #sig ".\n") printf("SERVER: can't ignore " #sig ".\n")
static void print_config() __attribute__((unused));
static void print_config() { static void print_config() {
printf("SERVER: Config\n"); printf("SERVER: Config\n");
printf(" retry_delay: %fs\n", (double)(config.request_timeout) / 1000.0); printf(" retry_delay: %fs\n", (double)(config.request_timeout) / 1000.0);