summaryrefslogtreecommitdiff
path: root/rcm-server-keymap.c
diff options
context:
space:
mode:
Diffstat (limited to 'rcm-server-keymap.c')
-rw-r--r--rcm-server-keymap.c40
1 files changed, 25 insertions, 15 deletions
diff --git a/rcm-server-keymap.c b/rcm-server-keymap.c
index 438b3f3..6e45570 100644
--- a/rcm-server-keymap.c
+++ b/rcm-server-keymap.c
@@ -319,7 +319,7 @@ keymap_parse(FILE *fp, char **line, size_t *buf_size, struct keymap *keymap,
}
static struct keymap *
-keymap_read(int dfd, const char *filename)
+keymap_read(int dfd, const char *path, const char *filename)
{
_cleanup_close_ int fd = -1;
_cleanup_fclose_ FILE *fp = NULL;
@@ -328,6 +328,7 @@ keymap_read(int dfd, const char *filename)
uint16_t cols, rows;
unsigned keycode_count;
size_t buf_size = 0;
+ char id[strlen(path) + strlen("/") + strlen(filename) + 1];
int r;
if (dfd < 0 || !filename)
@@ -342,7 +343,8 @@ keymap_read(int dfd, const char *filename)
goto out;
fd = -1;
- printf("Parsing keymap %s...\n", filename);
+ sprintf(id, "%s/%s", path, filename);
+ printf("Parsing keymap %s...\n", id);
r = keymap_parse(fp, &line, &buf_size, NULL, &rows, &cols, &keycode_count);
if (r < 0)
goto out;
@@ -351,7 +353,7 @@ keymap_read(int dfd, const char *filename)
if (!keymap)
goto out;
- keymap->id = strdup(filename);
+ keymap->id = strdup(id);
if (!keymap->id)
goto out;
@@ -378,20 +380,22 @@ out:
}
static int
-keymaps_load_dir(struct device *device, const char *path)
+keymaps_load_dir(struct device *device, int pfd, const char *path)
{
_cleanup_closedir_ DIR *dir = NULL;
int dfd;
struct dirent *dent;
struct keymap *keymap;
- dir = opendir(path);
- if (!dir)
- return -1;
-
- dfd = dirfd(dir);
+ dfd = openat(pfd, path, O_RDONLY | O_DIRECTORY);
if (dfd < 0)
- return -1;
+ return -errno;
+
+ dir = fdopendir(dfd);
+ if (!dir) {
+ close(dfd);
+ return -errno;
+ }
while ((dent = readdir(dir))) {
switch (dent->d_type) {
@@ -401,7 +405,7 @@ keymaps_load_dir(struct device *device, const char *path)
keymap = find_keymap_by_id(device, dent->d_name);
if (keymap)
continue;
- keymap = keymap_read(dfd, dent->d_name);
+ keymap = keymap_read(dfd, path, dent->d_name);
if (keymap)
list_add(&keymap->list, &device->keymaps);
break;
@@ -416,14 +420,20 @@ keymaps_load_dir(struct device *device, const char *path)
int
keymaps_load(struct device *device)
{
- char pdpath[strlen("./keymaps/per-device/") + strlen(device->name) + 1];
+ char pdpath[strlen("per-device/") + strlen(device->name) + 1];
+ _cleanup_close_ int dfd;
- sprintf(pdpath, "./keymaps/per-device/%s", device->name);
+ sprintf(pdpath, "per-device/%s", device->name);
+
+ /* FIXME: This is just a temporary location */
+ dfd = open("./keymaps", O_PATH | O_DIRECTORY);
+ if (dfd < 0)
+ return -errno;
printf("Loading per-device keymaps...\n");
- keymaps_load_dir(device, pdpath);
+ keymaps_load_dir(device, dfd, pdpath);
printf("Loading default keymaps...\n");
- keymaps_load_dir(device, "./keymaps/default");
+ keymaps_load_dir(device, dfd, "default");
return 0;
}