Merge pull request #66648 (improve xkbvalidate)

This allows xkbvalidate to be compiled via Clang and also has a few
other portability improvements, eg. it now can even be compiled on OS X,
even though it's probably not needed there.

In addition, I changed the binary name so that it matches the package
name.

I'm merging this in right now, because there is only the xserver NixOS
module where this is used, so the risk of a catastrophic breakage is
very low.

Checks and build done by ofborg also ran successfully and I also did a
few local tests (eg. running via valgrind to avoid leaks) to make sure
it's still working properly.
This commit is contained in:
aszlig 2019-08-15 01:32:01 +02:00
commit dc525e8b12
No known key found for this signature in database
GPG Key ID: 684089CE67EBB691
3 changed files with 22 additions and 7 deletions

View File

@ -714,7 +714,7 @@ in
nativeBuildInputs = [ pkgs.xkbvalidate ];
preferLocalBuild = true;
} ''
validate "$xkbModel" "$layout" "$xkbVariant" "$xkbOptions"
xkbvalidate "$xkbModel" "$layout" "$xkbVariant" "$xkbOptions"
touch "$out"
'');

View File

@ -5,11 +5,11 @@ runCommandCC "xkbvalidate" {
meta = {
description = "NixOS tool to validate X keyboard configuration";
license = lib.licenses.mit;
platforms = lib.platforms.linux;
platforms = lib.platforms.unix;
maintainers = [ lib.maintainers.aszlig ];
};
} ''
mkdir -p "$out/bin"
gcc -std=gnu11 -Wall -pedantic -lxkbcommon ${./xkbvalidate.c} \
-o "$out/bin/validate"
$CC -std=c11 -Wall -pedantic -lxkbcommon ${./xkbvalidate.c} \
-o "$out/bin/xkbvalidate"
''

View File

@ -1,4 +1,3 @@
#define _GNU_SOURCE
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
@ -14,6 +13,9 @@ static bool log_alloc_success = true;
static void add_log(struct xkb_context *ctx, enum xkb_log_level level,
const char *fmt, va_list args)
{
size_t buflen;
va_list tmpargs;
log_buffer_size++;
if (log_buffer == NULL)
@ -28,11 +30,24 @@ static void add_log(struct xkb_context *ctx, enum xkb_log_level level,
return;
}
if (vasprintf(&log_buffer[log_buffer_size - 1], fmt, args) == -1) {
/* Unfortunately, vasprintf() is a GNU extension and thus not very
* portable, so let's first get the required buffer size using a dummy
* vsnprintf and afterwards allocate the returned amount of bytes.
*
* We also need to make a copy of the args, because the value of the args
* will be indeterminate after the return.
*/
va_copy(tmpargs, args);
buflen = vsnprintf(NULL, 0, fmt, tmpargs);
va_end(tmpargs);
log_buffer[log_buffer_size - 1] = malloc(++buflen);
if (vsnprintf(log_buffer[log_buffer_size - 1], buflen, fmt, args) == -1) {
perror("log line alloc");
log_alloc_success = false;
return;
}
va_end(args);
}
static void print_logs(void)