Skip to content

Commit

Permalink
Move layouts into /usr/share/keyd/layouts (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
rvaiya committed Jun 23, 2022
1 parent b7c09b3 commit 4396487
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 23 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,18 @@ install:
fi

mkdir -p $(DESTDIR)/etc/keyd
mkdir -p $(DESTDIR)/etc/keyd/layouts
mkdir -p $(DESTDIR)$(PREFIX)/bin/
mkdir -p $(DESTDIR)$(PREFIX)/share/keyd/
mkdir -p $(DESTDIR)$(PREFIX)/share/keyd/layouts/
mkdir -p $(DESTDIR)$(PREFIX)/share/man/man1/
mkdir -p $(DESTDIR)$(PREFIX)/share/doc/keyd/
mkdir -p $(DESTDIR)$(PREFIX)/share/doc/keyd/examples/

-groupadd keyd
install -m755 bin/* $(DESTDIR)$(PREFIX)/bin/
install -m644 layouts/* $(DESTDIR)/etc/keyd/layouts/
install -m644 docs/*.md $(DESTDIR)$(PREFIX)/share/doc/keyd/
install -m644 examples/* $(DESTDIR)$(PREFIX)/share/doc/keyd/examples/
install -m644 layouts/* $(DESTDIR)$(PREFIX)/share/keyd/layouts
install -m644 data/*.1.gz $(DESTDIR)$(PREFIX)/share/man/man1/
install -m644 data/keyd.compose $(DESTDIR)$(PREFIX)/share/keyd/

Expand Down
Binary file modified data/keyd-application-mapper.1.gz
Binary file not shown.
Binary file modified data/keyd.1.gz
Binary file not shown.
7 changes: 6 additions & 1 deletion docs/keyd.scdoc
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,11 @@ contents of the included file appear in place of the include statement.
Making strategic use of these statements makes it possible to share common
functionality between configs.

Include paths are relative and must be placed in one of the following
directories:
- /etc/keyd/
- /usr/share/keyd/

E.G

```
Expand Down Expand Up @@ -334,7 +339,7 @@ Limitations:


For convenience, keyd ships with a number of common letter layouts in
/etc/keyd/layouts. Before including these, it is instructive to inspect them.
/usr/share/keyd/layouts. Before including these, it is instructive to inspect them.
Non-english layouts include a dedicated shift layer (making order of inclusion
important) and *require the use of keyd's compose definitions* (see *Unicode
Support*)
Expand Down
50 changes: 31 additions & 19 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,30 @@
#define MAX_FILE_SZ 65536
#define MAX_LINE_LEN 256

static const char *resolve_include_path(const char *path, const char *include_path)
{
static char resolved_path[PATH_MAX];
char tmp[PATH_MAX];
const char *dir;

if (strstr(include_path, "."))
return NULL;

strcpy(tmp, path);
dir = dirname(tmp);
snprintf(resolved_path, sizeof resolved_path, "%s/%s", dir, include_path);

if (!access(resolved_path, F_OK))
return resolved_path;

snprintf(resolved_path, sizeof resolved_path, "/usr/share/keyd/%s", include_path);

if (!access(resolved_path, F_OK))
return resolved_path;

return NULL;
}

static char *read_file(const char *path)
{
const char include_prefix[] = "include ";
Expand Down Expand Up @@ -55,33 +79,21 @@ static char *read_file(const char *path)

if (strstr(line, include_prefix) == line) {
int fd;
char include_path[PATH_MAX];
char resolved_path[PATH_MAX];
const char *resolved_path;
char *include_path = line+sizeof(include_prefix)-1;

line[len-1] = 0;

char *tmp = strdup(path);
char *dir = dirname(tmp);

snprintf(include_path,
sizeof include_path,
"%s/%s", dir, line+sizeof(include_prefix)-1);
resolved_path = resolve_include_path(path, include_path);

if(!realpath(include_path, resolved_path)) {
if (!resolved_path) {
fprintf(stderr, "\tERROR: Failed to resolve include path: %s\n", include_path);
free(tmp);
continue;
}

if (strstr(resolved_path, dir) != resolved_path) {
fprintf(stderr, "\tERROR: Naughty path detected: %s\n", include_path);
free(tmp);
continue;
}

free(tmp);
dbg("Including %s from %s", resolved_path, path);

fd = open(include_path, O_RDONLY);
fd = open(resolved_path, O_RDONLY);

if (fd < 0) {
fprintf(stderr, "\tERROR: Failed to include %s\n", include_path);
Expand Down Expand Up @@ -408,7 +420,7 @@ static int config_check_match(const char *path, uint16_t vendor, uint16_t produc
case ' ':
break;
case '#':
while ((buf[i] != '\n') && (i < n))
while ((i < n) && (buf[i] != '\n'))
i++;
break;
case '[':
Expand Down
2 changes: 1 addition & 1 deletion src/layer.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ int create_layer(struct layer *layer, const char *desc, const struct config *cfg
}


dbg("created [%s] from \"%s\"", layer->name, desc);
dbg2("created [%s] from \"%s\"", layer->name, desc);
return 0;
}

0 comments on commit 4396487

Please sign in to comment.