summaryrefslogtreecommitdiff
path: root/src/context.c
Commit message (Collapse)AuthorAgeFilesLines
* context: add XKB_CONTEXT_NO_SECURE_GETENV flag (#312)Ronan Pigott2022-12-161-8/+9
| | | | | | | | | This flag is useful for clients that may have relatively benign capabilities set, like CAP_SYS_NICE, that also want to use the xkb configuration from the environment and user configs in XDG_CONFIG_HOME. Fixes: https://github.com/xkbcommon/libxkbcommon/issues/308 Fixes: https://github.com/xkbcommon/libxkbcommon/issues/129 Signed-off-by: Ran Benita <ran@unusedvar.com>
* utils: move some MSVC compat stuff to common placeRan Benita2022-09-241-9/+0
| | | | Signed-off-by: Ran Benita <ran@unusedvar.com>
* x11: cache X11 atomsRan Benita2020-11-201-0/+3
| | | | | | | | | | | | | | | | | | | | On every keymap notify event, the keymap should be refreshed, which fetches the required X11 atoms. A big keymap might have a few hundred of atoms. A profile by a user has shown this *might* be slow when some intensive amount of keymap activity is occurring. It might also be slow on a remote X server. While I'm not really sure this is the actual bottleneck, caching the atoms is easy enough and only needs a couple kb of memory, so do that. On the added bench-x11: Before: retrieved 2500 keymaps from X in 11.233237s After : retrieved 2500 keymaps from X in 1.592339s Signed-off-by: Ran Benita <ran@unusedvar.com>
* context: fix a compiler warningPeter Hutterer2020-09-071-1/+1
| | | | | | | ../src/context.c:57:9: warning: variable 'err' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized] Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* Add /etc/xkb as extra lookup path for system data filesPeter Hutterer2020-08-301-1/+10
| | | | | | | | | | | | | | | This completes the usual triplet of configuration locations available for most processes: - vendor-provided data files in /usr/share/X11/xkb - system-specific data files in /etc/xkb - user-specific data files in $XDG_CONFIG_HOME/xkb The default lookup order user, system, vendor, just like everything else that uses these conventions. For include directives in rules files, the '%E' resolves to that path. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* Add asprintf_safe helper functionPeter Hutterer2020-07-131-7/+6
| | | | | | | We only ever care about whether we error out or not, so let's wrap this into something more sane. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* context: log include paths for debuggingPeter Hutterer2020-07-081-3/+12
| | | | | | | Now that we're relying on various different include paths, let's log that ones we use and the ones we failed to use. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* Factor the access check for paths outPeter Hutterer2020-07-061-6/+1
| | | | | | Easier to re-use without having to duplicate ifdefs. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* MSVC: Use <io.h> as an alternative for <unistd.h>Adrian Perez de Castro2019-12-281-1/+9
| | | | | | | | | Only the input/output functions from <unistd.h> options are used, so using <io.h> when building with MSVC should be enough. The inclusion of the header in context-priv.c does not seem to be needed (tested on GNU/Linux) and so it is removed. Signed-off-by: Ran Benita <ran@unusedvar.com>
* build: include config.h manuallyRan Benita2019-12-271-0/+2
| | | | | | | | | Previously we included it with an `-include` compiler directive. But that's not portable. And it's better to be explicit anyway. Every .c file should have `include "config.h"` first thing. Signed-off-by: Ran Benita <ran@unusedvar.com>
* context: add a helper function to return the default system include pathPeter Hutterer2019-12-241-5/+9
| | | | | | | No functional changes but we'll need that same lookup in the rules file include handling in a future patch. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* Use XDG_CONFIG_HOME as first XKB search pathPeter Hutterer2019-10-311-1/+18
| | | | | | | | | | | | | Use $XDG_CONFIG_HOME/xkb as the primary lookup path for XKB rules. Same motivation as in 3a91788d9254b, however the XDG directories are more standard and recommended these days than application-specific dotfiles. The XDG spec says to fall back to $HOME/.config where XDG_CONFIG_HOME is not set so we implement that behavior as well. Fixes #112 Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* context: Don't fail to create the context if HOME isn't availableJan Alexander Steffens (heftig)2019-10-201-7/+7
| | | | | | | | | E.g. when Mutter has CAP_SYS_NICE and thus secure_getenv returns NULL. Fixes https://bugs.archlinux.org/task/64191 [ran: changed to ignore error] Signed-off-by: Ran Benita <ran@unusedvar.com>
* context: move ~/.xkb to before XKB_CONFIG_ROOT in the default include pathRan Benita2019-10-031-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, the default include path was XKB_CONFIG_ROOT:~/.xkb. The ~/.xkb include path is intended to allow the local user to customize their keymaps without having to modify system paths. But usually, the user only wants to customize specific parts. When XKB_CONFIG_ROOT is first, the user can only customize through the "entry point" (the RMLVO). When ~/.xkb is first, the user can drop in a file and it will override the system one. The impetus for this change is the rules file. "evdev" is hard-coded everywhere, so it not often not possible to change to something else. And the rules files determines how the rest of the RMLVO is interpreted. So, to enable customization, we have these options: A: System includes user. B: User includes system. C: Library goes over both in one or the other order. Option A is problematic due to backward compatibility and is also unnatural. Option B gives the user control and is backward compatible, so that's what we choose. This is also how Compose files are handled, and that seems to work fine in the wild. Option C is actually less flexible than B, and more complicated. (The rules file format doesn't have an include statement yet, but it's planned). Signed-off-by: Ran Benita <ran@unusedvar.com>
* Add XKB_CONFIG_ROOT environmentMichael Vogt2015-07-201-2/+6
| | | | | The XKB_CONFIG_ROOT environment allows overrding the build time DFLT_XKB_CONFIG_ROOT path.
* Use secure_getenv when availableRan Benita2014-02-041-3/+3
| | | | | | | | | We probably don't want to get a privileged process to compile arbitrary keymaps. So we should be careful about the envvars which control include paths or default RMLVOs. But then secure_getenv is more sensible for everything we do. Signed-off-by: Ran Benita <ran234@gmail.com>
* context: split private functions to context-priv.cRan Benita2014-01-131-161/+0
| | | | | | (Same as keymap-priv.c). Signed-off-by: Ran Benita <ran234@gmail.com>
* context: remove mostly useless log wrappersRan Benita2014-01-121-1/+4
| | | | | | Just use xkb_log directly. Signed-off-by: Ran Benita <ran234@gmail.com>
* atom: drop {xkb_,}atom_strdupRan Benita2013-12-021-6/+0
| | | | | | | Even though in 112cccb18ad1bc877b3c4a87fa536ea085c761b5 I said it might be useful, it's not. So remove it. Signed-off-by: Ran Benita <ran234@gmail.com>
* Replace ctype.h functions with ascii onesRan Benita2013-10-141-2/+1
| | | | | | | ctype.h is locale-dependent, so using it in our scanners is not optimal. Let's be deterministic with our own simple functions. Signed-off-by: Ran Benita <ran234@gmail.com>
* log: change the log prefixes to be more library-likeRan Benita2013-07-311-6/+6
| | | | | | | | "Error: " is not very informative when intermingled with other logs. The format that seems most suitable is: "xkbcommon: ERROR: %s" Signed-off-by: Ran Benita <ran234@gmail.com>
* ctx: adapt to the len-aware atom functionsRan Benita2013-07-211-2/+2
| | | | | | | | | xkb_atom_intern now takes a len parameter. Turns out though that almost all of our xkb_atom_intern calls are called on string literals, the length of which we know statically. So we add a macro to micro-optimize this case. Signed-off-by: Ran Benita <ran234@gmail.com>
* atom: allow interning non-NUL-terminated stringsRan Benita2013-07-211-3/+3
| | | | | | We need this later. The strlen was calculated anyway, so no loss here. Signed-off-by: Ran Benita <ran234@gmail.com>
* Add environment overrides for default RMLVODaniel Stone2013-03-191-0/+72
| | | | | | | You can now set default values in the environment, as well as a context option to ignore the environment, e.g. for tests. Signed-off-by: Daniel Stone <daniel@fooishbar.org>
* Remove file_id entirelyRan Benita2013-03-181-9/+0
| | | | | | It is not used anymore. Signed-off-by: Ran Benita <ran234@gmail.com>
* text: clean up and fix the *MaskText functionsRan Benita2013-03-181-1/+1
| | | | | | | | | | | | | | The snprintf trick that LedStateText and ControlMaskText do cannot work, because you can't use the buffer as an argument to write to itself! (posix at least has 'restrict' there). So those two actually never worked for more than one value (i.e. with a +). Fix that, and do the same cleanup to ModMaskText. Now we have 3 functions which look exactly the same, oh well. Also increase the context text buffer size, you never know. Signed-off-by: Ran Benita <ran234@gmail.com>
* state, context: allow passing NULL to *_unref()Ran Benita2012-10-291-1/+1
| | | | | | | | | | For error handling code, it's nice to be able to pass NULL to these function without worrying about segfaults ensuing. free() sets the precedent here. Also document this fact. Signed-off-by: Ran Benita <ran234@gmail.com>
* Contextualize GetBuffer()Ran Benita2012-10-181-0/+21
| | | | | | | Instead storing the buffer in a non-thread-safe static array, we move it to the context. Signed-off-by: Ran Benita <ran234@gmail.com>
* Change log env vars to XKB_LOG_LEVEL/VERBOSITYRan Benita2012-10-121-2/+2
| | | | | | A bit more consistent and descriptive. Signed-off-by: Ran Benita <ran234@gmail.com>
* API: add _context prefix to log-related functionsRan Benita2012-09-241-12/+12
| | | | | | | | | This is to follow the general scheme set by all of the other API functions. Since no one is using these functions yet, we don't (actually better not) add the old names to xkbcommon-compat.h. Signed-off-by: Ran Benita <ran234@gmail.com>
* Organize src/ and test/ headersRan Benita2012-09-161-4/+22
| | | | | | | | | | | | - Add context.h and move context-related functions from xkb-priv.h to it. - Move xkb_context definition back to context.c. - Add keysym.h and move keysym upper/lower/keypad from xkb-priv.h to it. - Rename xkb-priv.h to map.h since it only contains keymap-related definitions and declarations now. - Remove unnecessary includes and some and some other small cleanups. Signed-off-by: Ran Benita <ran234@gmail.com>
* include: improve file-not-found error reportingRan Benita2012-09-161-0/+16
| | | | | | Only report it once, and not only for rules. Signed-off-by: Ran Benita <ran234@gmail.com>
* Copyright updatesDaniel Stone2012-09-121-0/+1
| | | | | | | | | | | | With Dan Nicholson's permission (via email), update his copyright and license statements to the standard X.Org boilerplate MIT license, as both myself and Ran have been using. Clean up my copyright declarations (in some cases to correct ownership), and add copyright/license statements from myself and/or Ran where appropriate. Signed-off-by: Daniel Stone <daniel@fooishbar.org>
* atom: add xkb_atom_lookupRan Benita2012-09-031-0/+6
| | | | | | | | This will only lookup the string and return the atom if found; it will not intern it if not. This is useful when e.g. getting a string from the user (which may be arbitrary) and comparing against atoms. Signed-off-by: Ran Benita <ran234@gmail.com>
* log: replace "priority" by "level" everywhereRan Benita2012-09-031-23/+27
| | | | | | | | | Now that we don't use syslog, "level" does sound more commonplace. We should change it while there is still nobody using it. Also leave some space between the integers of the xkb_log_level enum values, if we ever need to shove more in between. Signed-off-by: Ran Benita <ran234@gmail.com>
* vmod: remove outdated commentsRan Benita2012-09-021-1/+1
| | | | Signed-off-by: Ran Benita <ran234@gmail.com>
* Add xkb_log_level enum rather than using syslogDaniel Stone2012-08-081-17/+14
| | | | | | | Instead of relying on people including syslog.h, add our own XKB_LOG_LEVEL_* defines. Signed-off-by: Daniel Stone <daniel@fooishbar.org>
* Move xkb_context struct to xkb-priv.hDaniel Stone2012-08-081-18/+0
| | | | | | | So we can print more intelligent debugging messages without needing helper functions for the failed_includes array. Signed-off-by: Daniel Stone <daniel@fooishbar.org>
* context: Maintain list of failed include pathsDaniel Stone2012-08-081-10/+18
| | | | | | Keep around a list of paths we tried to add but couldn't. Signed-off-by: Daniel Stone <daniel@fooishbar.org>
* log: allow to resore default log functionRan Benita2012-08-071-1/+1
| | | | Signed-off-by: Ran Benita <ran234@gmail.com>
* Don't create contexts with no include pathsDaniel Stone2012-07-271-5/+8
| | | | | | | | | | Clean up the return code handling from xkb_context_add_include_paths_default, and thus fail context creation if we can't add any of the default include paths, but were asked to. If this happens, dump the DFLT_XKB_CONFIG_ROOT out in the log message, so at least we know what we aren't looking at. Signed-off-by: Daniel Stone <daniel@fooishbar.org>
* Some atom related optimizationsRan Benita2012-07-271-1/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | We often get a strdup'd string, just to pass it over the atom_intern and then immediately free it. But atom_intern then strdup's it again (if it's not interned already); so instead we can have the interning "steal" the memory instead of allocing a new one and freeing the old one. This is done by a new xkb_atom_steal function. It also turns out, that every time we strdup an atom, we don't actually modify it afterwards. Since we are guaranteed that the atom table will live as long as the context, we can just use xkb_atom_text instead. This removes a some more dynamic allocations. For this change we had to remove the ability to append two strings, e.g. "foo" + "bar" -> "foobar" which is only possible with string literals. This is unused and quite useless for our purposes. xkb_atom_strdup is left unused, as it may still be useful. Running rulescomp in valgrind, Before: ==7907== total heap usage: 173,698 allocs, 173,698 frees, 9,775,973 bytes allocated After: ==6348== total heap usage: 168,403 allocs, 168,403 frees, 9,732,648 bytes allocated Signed-off-by: Ran Benita <ran234@gmail.com>
* Remove old logging leftoversRan Benita2012-07-231-6/+2
| | | | | | Everything has been converted. Signed-off-by: Ran Benita <ran234@gmail.com>
* Add logging APIRan Benita2012-07-231-0/+149
| | | | | | | | | | | | | | | | | | | | | | | | | Add new public API to provide the library users with some options to control and customize the logging output from the library. It is based upon the skeleton from the libabc demo libray: https://git.kernel.org/?p=linux/kernel/git/kay/libabc.git which is public domain and works pretty well. This requires passing in the context object in every logging call, and thus the conversion is done file by file. We also remove the global warningLevel variable in favor of a verbosity level in the context, which can be set by the user and is silent by default. One issue is the ACTION calls, which, while nice, do not play very well with line- and priority-based logging, and would require some line continuation handling or keeping state or some other compromise. So instead remove these and just inline them with their respective warning/error. So instead of: ERROR("Memory allocation failed\n") ACTION("Removing all files on hardisk\n") its something like that: log_err("Memory allocation failed; Removing all files on harddisk\n") Signed-off-by: Ran Benita <ran234@gmail.com>
* utils: remove Xfuncproto.h and use our own macrosRan Benita2012-07-231-9/+9
| | | | | | | Add XKB_EXPORT to replace _X_EXPORT, and copy the definitions of _X_ATTRIBUTE_FOO as ATTR_FOO. Signed-off-by: Ran Benita <ran234@gmail.com>
* Run source tree through uncrustifyDaniel Stone2012-07-171-1/+1
| | | | | | | .uncrustify.cfg committed for future reference also, but had to manually fix up a few things: it really likes justifying struct initialisers. Signed-off-by: Daniel Stone <daniel@fooishbar.org>
* Fix fileID messRan Benita2012-07-141-2/+2
| | | | | | | | | | | | | | | | | A few problems here: * In e.g. keycodes.c the fileID field of the Info struct was never initialized to the id of the appropriate file, so it was always 0. There's some code which uses it, mostly for warnings. * Some of the fileID fields were unsigned char, which overflows several times, seeing as the ID in some of our tests can get > 1000 (because we reuse the context). * Some sign mismatches. * fileID vs file_id. Hopefully this fixes everything. I doubt this stuff had ever worked as intended, in xkbcomp or otherwise. Signed-off-by: Ran Benita <ran234@gmail.com>
* context: use darray for include pathsRan Benita2012-05-221-30/+12
| | | | Signed-off-by: Ran Benita <ran234@gmail.com>
* Various static analyzer fixesRan Benita2012-05-181-1/+1
| | | | Signed-off-by: Ran Benita <ran234@gmail.com>
* Use eaccess() only if availablePekka Paalanen2012-05-181-0/+6
| | | | | | Fixes build on Android. Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>