xkbcommon / libxkbcommon

keymap handling library for toolkits and window systems
https://xkbcommon.org
Other
286 stars 125 forks source link

Fatal error when $XDG_CONFIG_HOME/XCompose is a directory #436

Closed Janno closed 9 months ago

Janno commented 10 months ago

I am getting this error message from software that uses xkbcommon:

xkbcommon: ERROR: Couldn't read Compose file /home/janno/.config/XCompose: No such device

~/.config/XCompose is a directory in my case and what is failing here is a call to mmap on that directory. I don't think mmap should be called on directories?

strace reports:

[pid 567663] openat(AT_FDCWD, "/home/janno/.config/XCompose", O_RDONLY) = 4
[pid 567663] newfstatat(4, "", {st_mode=S_IFDIR|0755, st_size=10, ...}, AT_EMPTY_PATH) = 0
[pid 567663] mmap(NULL, 10, PROT_READ, MAP_SHARED, 4, 0) = -1 ENODEV (No such device)
[pid 567663] write(2, "xkbcommon: ERROR: ", 18xkbcommon: ERROR: ) = 18
[pid 567663] write(2, "Couldn't read Compose file /home/janno/.config/XCompose: No such device\n", 72Couldn't read Compose file /home/janno/.config/XCompose: No such device
) = 72

I am not 100% sure that this is xkbcommon's fault but I did check the documentation and the docs for xkb_compose_table_new_from_locale make it sound like xkbcommon is the one that decides to open this file.

wismill commented 10 months ago

Indeed, this is one of the paths that are checked. We do not check whether it is a regular file though. A temporary workaround is to rename your directory.

MR welcome!

whot commented 10 months ago

Maybe the easiest fix here is to open() and then on success fdopen().

wismill commented 9 months ago

Maybe the easiest fix here is to open() and then on success fdopen().

@whot how would you do that?

I opened #441 with another approach.

whot commented 9 months ago

/me types code /me reads man page

nevermind, what I had in mind (catching EISDIR) won't work since we only open readonly. So your stat approach is the correct one, see my comment re: race condition there though please.