2009-06-03 00:58:26 +02:00
|
|
|
From 0f70ba9d3412b17ac4e08e33e1be3c226c06ea54 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Yan Li <yan.i.li@intel.com>
|
|
|
|
Date: Tue, 12 May 2009 17:49:07 +0800
|
|
|
|
Subject: [PATCH] XKB: cache xkbcomp output for fast start-up v5 for 1.6.1
|
|
|
|
Organization: Intel
|
|
|
|
|
|
|
|
xkbcomp outputs will be cached in files with hashed keymap as
|
|
|
|
names. This saves boot time for around 1s on commodity netbooks.
|
|
|
|
|
|
|
|
Signed-off-by: Yan Li <yan.i.li@intel.com>
|
2010-01-18 14:04:02 +01:00
|
|
|
================================================================================
|
2010-03-20 03:42:15 +01:00
|
|
|
--- xorg-server-1.7.99/configure.ac
|
|
|
|
+++ xorg-server-1.7.99/configure.ac
|
|
|
|
@@ -527,9 +527,9 @@
|
2009-06-03 00:58:26 +02:00
|
|
|
AC_ARG_WITH(xkb-path, AS_HELP_STRING([--with-xkb-path=PATH], [Path to XKB base dir (default: ${datadir}/X11/xkb)]),
|
|
|
|
[ XKBPATH="$withval" ],
|
|
|
|
[ XKBPATH="${datadir}/X11/xkb" ])
|
|
|
|
-AC_ARG_WITH(xkb-output, AS_HELP_STRING([--with-xkb-output=PATH], [Path to XKB output dir (default: ${datadir}/X11/xkb/compiled)]),
|
|
|
|
+AC_ARG_WITH(xkb-output, AS_HELP_STRING([--with-xkb-output=PATH], [Path to XKB output dir (default: ${localstatedir}/cache/xkb)]),
|
|
|
|
[ XKBOUTPUT="$withval" ],
|
|
|
|
- [ XKBOUTPUT="compiled" ])
|
|
|
|
+ [ XKBOUTPUT="${localstatedir}/cache/xkb" ])
|
2010-01-18 14:04:02 +01:00
|
|
|
AC_ARG_WITH(default-xkb-rules, AS_HELP_STRING([--with-default-xkb-rules=RULES],
|
|
|
|
[Keyboard ruleset (default: base/evdev)]),
|
|
|
|
[ XKB_DFLT_RULES="$withval" ],
|
2010-03-20 03:42:15 +01:00
|
|
|
@@ -1160,7 +1160,7 @@
|
2010-01-18 14:04:02 +01:00
|
|
|
dnl Make sure XKM_OUTPUT_DIR is an absolute path
|
2009-06-03 00:58:26 +02:00
|
|
|
XKBOUTPUT_FIRSTCHAR=`echo $XKBOUTPUT | cut -b 1`
|
2010-01-18 14:04:02 +01:00
|
|
|
if [[ x$XKBOUTPUT_FIRSTCHAR != x/ -a x$XKBOUTPUT_FIRSTCHAR != 'x$' ]] ; then
|
2009-06-03 00:58:26 +02:00
|
|
|
- XKBOUTPUT="$XKB_BASE_DIRECTORY/$XKBOUTPUT"
|
|
|
|
+ AC_MSG_ERROR([xkb-output must be an absolute path.])
|
|
|
|
fi
|
|
|
|
|
2010-01-18 14:04:02 +01:00
|
|
|
dnl XKM_OUTPUT_DIR (used in code) must end in / or file names get hosed
|
2010-03-20 03:42:15 +01:00
|
|
|
--- xorg-server-1.7.99/xkb/README.compiled
|
|
|
|
+++ xorg-server-1.7.99/xkb/README.compiled
|
2010-01-18 14:04:02 +01:00
|
|
|
@@ -4,10 +4,10 @@
|
2009-06-03 00:58:26 +02:00
|
|
|
or some other tool might destroy or replace the files in this directory,
|
|
|
|
so it is not a safe place to store compiled keymaps for long periods of
|
|
|
|
time. The default keymap for any server is usually stored in:
|
|
|
|
- X<num>-default.xkm
|
|
|
|
-where <num> is the display number of the server in question, which makes
|
|
|
|
-it possible for several servers *on the same host* to share the same
|
|
|
|
-directory.
|
|
|
|
+ server-<SHA1>.xkm
|
|
|
|
+
|
|
|
|
+where <SHA1> is the SHA1 hash of keymap source, so that compiled
|
|
|
|
+keymap of different keymap sources are stored in different files.
|
|
|
|
|
|
|
|
Unless the X server is modified, sharing this directory between servers on
|
|
|
|
different hosts could cause problems.
|
2010-03-20 03:42:15 +01:00
|
|
|
--- xorg-server-1.7.99/xkb/ddxLoad.c
|
|
|
|
+++ xorg-server-1.7.99/xkb/ddxLoad.c
|
|
|
|
@@ -30,6 +30,12 @@
|
|
|
|
|
2009-06-03 00:58:26 +02:00
|
|
|
#include <xkb-config.h>
|
|
|
|
|
|
|
|
+#ifdef HAVE_SHA1_IN_LIBMD /* Use libmd for SHA1 */
|
|
|
|
+# include <sha1.h>
|
|
|
|
+#else /* Use OpenSSL's libcrypto */
|
|
|
|
+# include <stddef.h> /* buggy openssl/sha.h wants size_t */
|
|
|
|
+# include <openssl/sha.h>
|
|
|
|
+#endif
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ctype.h>
|
2010-01-18 14:04:02 +01:00
|
|
|
#include <X11/X.h>
|
2010-03-20 03:42:15 +01:00
|
|
|
@@ -43,24 +49,13 @@
|
2009-06-03 00:58:26 +02:00
|
|
|
#define XKBSRV_NEED_FILE_FUNCS
|
|
|
|
#include <xkbsrv.h>
|
|
|
|
#include <X11/extensions/XI.h>
|
|
|
|
+#include <errno.h>
|
|
|
|
#include "xkb.h"
|
|
|
|
|
|
|
|
#if defined(CSRG_BASED) || defined(linux) || defined(__GNU__)
|
|
|
|
#include <paths.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
- /*
|
|
|
|
- * If XKM_OUTPUT_DIR specifies a path without a leading slash, it is
|
|
|
|
- * relative to the top-level XKB configuration directory.
|
|
|
|
- * Making the server write to a subdirectory of that directory
|
|
|
|
- * requires some work in the general case (install procedure
|
|
|
|
- * has to create links to /var or somesuch on many machines),
|
|
|
|
- * so we just compile into /usr/tmp for now.
|
|
|
|
- */
|
|
|
|
-#ifndef XKM_OUTPUT_DIR
|
|
|
|
-#define XKM_OUTPUT_DIR "compiled/"
|
|
|
|
-#endif
|
|
|
|
-
|
|
|
|
#define PRE_ERROR_MSG "\"The XKEYBOARD keymap compiler (xkbcomp) reports:\""
|
|
|
|
#define ERROR_PREFIX "\"> \""
|
|
|
|
#define POST_ERROR_MSG1 "\"Errors from xkbcomp are not fatal to the X server\""
|
2010-03-20 03:42:15 +01:00
|
|
|
@@ -175,6 +170,45 @@
|
2009-06-03 00:58:26 +02:00
|
|
|
}
|
|
|
|
|
2010-01-18 14:04:02 +01:00
|
|
|
static Bool
|
2009-06-03 00:58:26 +02:00
|
|
|
+Sha1Asc(char sha1Asc[SHA_DIGEST_LENGTH*2+1], const char * input)
|
|
|
|
+{
|
|
|
|
+ int i;
|
|
|
|
+ unsigned char sha1[SHA_DIGEST_LENGTH];
|
|
|
|
+
|
|
|
|
+#ifdef HAVE_SHA1_IN_LIBMD /* Use libmd for SHA1 */
|
|
|
|
+ SHA1_CTX ctx;
|
|
|
|
+
|
|
|
|
+ SHA1Init (&ctx);
|
|
|
|
+ SHA1Update (&ctx, input, strlen(input));
|
|
|
|
+ SHA1Final (sha1, &ctx);
|
|
|
|
+#else /* Use OpenSSL's libcrypto */
|
|
|
|
+ SHA_CTX ctx;
|
|
|
|
+ int success;
|
|
|
|
+
|
|
|
|
+ success = SHA1_Init (&ctx);
|
|
|
|
+ if (! success)
|
2010-01-18 14:04:02 +01:00
|
|
|
+ return BadAlloc;
|
2009-06-03 00:58:26 +02:00
|
|
|
+
|
|
|
|
+ success = SHA1_Update (&ctx, input, strlen(input));
|
|
|
|
+ if (! success)
|
2010-01-18 14:04:02 +01:00
|
|
|
+ return BadAlloc;
|
2009-06-03 00:58:26 +02:00
|
|
|
+
|
|
|
|
+ success = SHA1_Final (sha1, &ctx);
|
|
|
|
+ if (! success)
|
2010-01-18 14:04:02 +01:00
|
|
|
+ return BadAlloc;
|
2009-06-03 00:58:26 +02:00
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
+ /* convert sha1 to sha1_asc */
|
|
|
|
+ for(i=0; i<SHA_DIGEST_LENGTH; ++i) {
|
|
|
|
+ sprintf(sha1Asc+i*2, "%02X", sha1[i]);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return Success;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/* call xkbcomp and compile XKB keymap, return xkm file name in
|
|
|
|
+ nameRtrn */
|
|
|
|
+static Bool
|
|
|
|
XkbDDXCompileKeymapByNames( XkbDescPtr xkb,
|
|
|
|
XkbComponentNamesPtr names,
|
|
|
|
unsigned want,
|
2010-03-20 03:42:15 +01:00
|
|
|
@@ -183,7 +217,11 @@
|
2009-06-03 00:58:26 +02:00
|
|
|
int nameRtrnLen)
|
|
|
|
{
|
|
|
|
FILE * out;
|
|
|
|
- char *buf = NULL, keymap[PATH_MAX], xkm_output_dir[PATH_MAX];
|
|
|
|
+ char * buf = NULL, xkmfile[PATH_MAX], xkm_output_dir[PATH_MAX];
|
|
|
|
+ char * tmpXkmFile = NULL;
|
|
|
|
+ char * canonicalXkmFileName = NULL;
|
|
|
|
+ char sha1Asc[SHA_DIGEST_LENGTH*2+1], xkbKeyMapBuf[100*1024];
|
|
|
|
+ int ret, result;
|
|
|
|
|
|
|
|
const char *emptystring = "";
|
|
|
|
const char *xkbbasedirflag = emptystring;
|
2010-03-20 03:42:15 +01:00
|
|
|
@@ -194,15 +232,70 @@
|
2009-06-03 00:58:26 +02:00
|
|
|
/* WIN32 has no popen. The input must be stored in a file which is
|
|
|
|
used as input for xkbcomp. xkbcomp does not read from stdin. */
|
|
|
|
char tmpname[PATH_MAX];
|
|
|
|
- const char *xkmfile = tmpname;
|
|
|
|
+ const char *xkbfile = tmpname;
|
|
|
|
#else
|
|
|
|
- const char *xkmfile = "-";
|
|
|
|
+ const char *xkbfile = "-";
|
2009-08-04 21:52:16 +02:00
|
|
|
+#endif
|
|
|
|
+
|
2009-06-03 00:58:26 +02:00
|
|
|
+ /* Write keymap source (xkbfile) to memory buffer `xkbKeyMapBuf',
|
|
|
|
+ of which SHA1 is generated and used as result xkm file name */
|
|
|
|
+ memset(xkbKeyMapBuf, 0, sizeof(xkbKeyMapBuf));
|
|
|
|
+ out = fmemopen(xkbKeyMapBuf, sizeof(xkbKeyMapBuf), "w");
|
|
|
|
+ if (NULL == out) {
|
|
|
|
+ ErrorF("[xkb] Open xkbKeyMapBuf for writing failed\n");
|
2010-03-20 03:42:15 +01:00
|
|
|
+ return FALSE;
|
2009-06-03 00:58:26 +02:00
|
|
|
+ }
|
|
|
|
+ ret = XkbWriteXKBKeymapForNames(out, names, xkb, want, need);
|
|
|
|
+ if (fclose(out) !=0)
|
|
|
|
+ {
|
|
|
|
+ ErrorF("[xkb] XkbWriteXKBKeymapForNames error, perhaps xkbKeyMapBuf is too small\n");
|
2010-03-20 03:42:15 +01:00
|
|
|
+ return FALSE;
|
2009-06-03 00:58:26 +02:00
|
|
|
+ }
|
|
|
|
+#ifdef DEBUG
|
|
|
|
+ if (xkbDebugFlags) {
|
|
|
|
+ ErrorF("[xkb] XkbDDXCompileKeymapByNames compiling keymap:\n");
|
|
|
|
+ fputs(xkbKeyMapBuf, stderr);
|
|
|
|
+ }
|
2009-08-04 21:52:16 +02:00
|
|
|
#endif
|
2009-06-03 00:58:26 +02:00
|
|
|
+ if (!ret) {
|
|
|
|
+ ErrorF("[xkb] Generating XKB Keymap failed, giving up compiling keymap\n");
|
2010-03-20 03:42:15 +01:00
|
|
|
+ return FALSE;
|
2009-06-03 00:58:26 +02:00
|
|
|
+ }
|
2009-08-04 21:52:16 +02:00
|
|
|
|
|
|
|
- snprintf(keymap, sizeof(keymap), "server-%s", display);
|
2009-06-03 00:58:26 +02:00
|
|
|
+ DebugF("[xkb] computing SHA1 of keymap\n");
|
|
|
|
+ if (Success == Sha1Asc(sha1Asc, xkbKeyMapBuf)) {
|
|
|
|
+ snprintf(xkmfile, sizeof(xkmfile), "server-%s", sha1Asc);
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ ErrorF("[xkb] Computing SHA1 of keymap failed, "
|
|
|
|
+ "using display name instead as xkm file name\n");
|
|
|
|
+ snprintf(xkmfile, sizeof(xkmfile), "server-%s", display);
|
|
|
|
+ }
|
|
|
|
|
|
|
|
OutputDirectory(xkm_output_dir, sizeof(xkm_output_dir));
|
|
|
|
|
|
|
|
+ /* set nameRtrn, fail if it's too small */
|
|
|
|
+ if ((strlen(xkmfile)+1 > nameRtrnLen) && nameRtrn) {
|
|
|
|
+ ErrorF("[xkb] nameRtrn too small to hold xkmfile name\n");
|
2010-03-20 03:42:15 +01:00
|
|
|
+ return FALSE;
|
2009-06-03 00:58:26 +02:00
|
|
|
+ }
|
|
|
|
+ strncpy(nameRtrn, xkmfile, nameRtrnLen);
|
|
|
|
+
|
|
|
|
+ /* if the xkm file already exists, reuse it */
|
|
|
|
+ canonicalXkmFileName = Xprintf("%s%s.xkm", xkm_output_dir, xkmfile);
|
|
|
|
+ if (access(canonicalXkmFileName, R_OK) == 0) {
|
|
|
|
+ /* yes, we can reuse the old xkm file */
|
|
|
|
+ LogMessage(X_INFO, "XKB: reuse xkmfile %s\n", canonicalXkmFileName);
|
2010-03-20 03:42:15 +01:00
|
|
|
+ result = TRUE;
|
2009-06-03 00:58:26 +02:00
|
|
|
+ goto _ret;
|
|
|
|
+ }
|
|
|
|
+ LogMessage(X_INFO, "XKB: generating xkmfile %s\n", canonicalXkmFileName);
|
|
|
|
+
|
|
|
|
+ /* continue to call xkbcomp to compile the keymap. to avoid race
|
|
|
|
+ condition, we compile it to a tmpfile then rename it to
|
|
|
|
+ xkmfile */
|
2010-01-18 14:04:02 +01:00
|
|
|
+
|
2009-06-03 00:58:26 +02:00
|
|
|
+
|
|
|
|
#ifdef WIN32
|
|
|
|
strcpy(tmpname, Win32TempDir());
|
|
|
|
strcat(tmpname, "\\xkb_XXXXXX");
|
2010-03-20 03:42:15 +01:00
|
|
|
@@ -225,19 +318,30 @@
|
2009-06-03 00:58:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+ if ( (tmpXkmFile = tempnam(xkm_output_dir, NULL)) == NULL ) {
|
|
|
|
+ ErrorF("[xkb] Can't generate temp xkm file name");
|
2010-03-20 03:42:15 +01:00
|
|
|
+ result = FALSE;
|
2009-06-03 00:58:26 +02:00
|
|
|
+ goto _ret;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
buf = Xprintf("\"%s%sxkbcomp\" -w %d %s -xkm \"%s\" "
|
|
|
|
- "-em1 %s -emp %s -eml %s \"%s%s.xkm\"",
|
|
|
|
+ "-em1 %s -emp %s -eml %s \"%s\"",
|
|
|
|
xkbbindir, xkbbindirsep,
|
|
|
|
( (xkbDebugFlags < 2) ? 1 :
|
|
|
|
((xkbDebugFlags > 10) ? 10 : (int)xkbDebugFlags) ),
|
|
|
|
- xkbbasedirflag, xkmfile,
|
|
|
|
+ xkbbasedirflag, xkbfile,
|
|
|
|
PRE_ERROR_MSG, ERROR_PREFIX, POST_ERROR_MSG1,
|
|
|
|
- xkm_output_dir, keymap);
|
|
|
|
+ tmpXkmFile);
|
|
|
|
|
|
|
|
if (xkbbasedirflag != emptystring) {
|
|
|
|
xfree(xkbbasedirflag);
|
|
|
|
}
|
|
|
|
|
|
|
|
+ /* there's a potential race condition between calling tempnam()
|
|
|
|
+ and invoking xkbcomp to write the result file (potential temp
|
|
|
|
+ file name conflicts), but since xkbcomp is a standalone
|
|
|
|
+ program, we have to live with this */
|
|
|
|
+
|
|
|
|
#ifndef WIN32
|
|
|
|
out= Popen(buf,"w");
|
|
|
|
#else
|
2010-03-20 03:42:15 +01:00
|
|
|
@@ -245,31 +349,42 @@
|
2009-06-03 00:58:26 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (out!=NULL) {
|
|
|
|
-#ifdef DEBUG
|
|
|
|
- if (xkbDebugFlags) {
|
|
|
|
- ErrorF("[xkb] XkbDDXCompileKeymapByNames compiling keymap:\n");
|
|
|
|
- XkbWriteXKBKeymapForNames(stderr,names,xkb,want,need);
|
2010-03-20 03:42:15 +01:00
|
|
|
- }
|
2009-06-03 00:58:26 +02:00
|
|
|
-#endif
|
|
|
|
- XkbWriteXKBKeymapForNames(out,names,xkb,want,need);
|
2010-03-20 03:42:15 +01:00
|
|
|
+ /* write XKBKeyMapBuf to xkbcomp */
|
|
|
|
+ if (EOF==fputs(xkbKeyMapBuf, out))
|
|
|
|
+ {
|
|
|
|
+ ErrorF("[xkb] Sending keymap to xkbcomp failed\n");
|
|
|
|
+ result = FALSE;
|
|
|
|
+ goto _ret;
|
|
|
|
+ }
|
2009-06-03 00:58:26 +02:00
|
|
|
#ifndef WIN32
|
|
|
|
if (Pclose(out)==0)
|
|
|
|
#else
|
|
|
|
if (fclose(out)==0 && System(buf) >= 0)
|
|
|
|
#endif
|
|
|
|
{
|
2010-03-20 03:42:15 +01:00
|
|
|
+ /* xkbcomp success */
|
2009-06-03 00:58:26 +02:00
|
|
|
if (xkbDebugFlags)
|
|
|
|
DebugF("[xkb] xkb executes: %s\n",buf);
|
|
|
|
- if (nameRtrn) {
|
|
|
|
- strncpy(nameRtrn,keymap,nameRtrnLen);
|
|
|
|
- nameRtrn[nameRtrnLen-1]= '\0';
|
2010-03-20 03:42:15 +01:00
|
|
|
- }
|
2009-06-03 00:58:26 +02:00
|
|
|
- if (buf != NULL)
|
|
|
|
- xfree (buf);
|
2010-03-20 03:42:15 +01:00
|
|
|
- return TRUE;
|
|
|
|
+ /* if canonicalXkmFileName already exists now, we simply
|
|
|
|
+ overwrite it, this is OK */
|
|
|
|
+ ret = rename(tmpXkmFile, canonicalXkmFileName);
|
|
|
|
+ if (0 != ret) {
|
|
|
|
+ ErrorF("[xkb] Can't rename %s to %s, error: %s\n",
|
|
|
|
+ tmpXkmFile, canonicalXkmFileName,
|
|
|
|
+ strerror(errno));
|
|
|
|
+
|
|
|
|
+ /* in case of error, don't unlink tmpXkmFile, leave it
|
|
|
|
+ for debugging */
|
2009-06-03 00:58:26 +02:00
|
|
|
+
|
2010-03-20 03:42:15 +01:00
|
|
|
+ result = FALSE;
|
|
|
|
+ goto _ret;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ result = TRUE;
|
|
|
|
+ goto _ret;
|
2009-06-03 00:58:26 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
- LogMessage(X_ERROR, "Error compiling keymap (%s)\n", keymap);
|
2010-03-20 03:42:15 +01:00
|
|
|
+ LogMessage(X_ERROR, "Error compiling keymap (%s)\n", xkbfile);
|
2009-06-03 00:58:26 +02:00
|
|
|
#ifdef WIN32
|
|
|
|
/* remove the temporary file */
|
|
|
|
unlink(tmpname);
|
2010-03-20 03:42:15 +01:00
|
|
|
@@ -286,7 +401,17 @@
|
2009-06-03 00:58:26 +02:00
|
|
|
nameRtrn[0]= '\0';
|
2010-03-20 03:42:15 +01:00
|
|
|
if (buf != NULL)
|
|
|
|
xfree (buf);
|
|
|
|
- return FALSE;
|
|
|
|
+ result = FALSE;
|
2009-06-03 00:58:26 +02:00
|
|
|
+
|
|
|
|
+_ret:
|
|
|
|
+ if (tmpXkmFile)
|
2010-03-20 03:42:15 +01:00
|
|
|
+ free(tmpXkmFile);
|
2009-06-03 00:58:26 +02:00
|
|
|
+ if (canonicalXkmFileName)
|
2010-03-20 03:42:15 +01:00
|
|
|
+ xfree(canonicalXkmFileName);
|
|
|
|
+ if (buf != NULL)
|
|
|
|
+ xfree (buf);
|
2009-06-03 00:58:26 +02:00
|
|
|
+
|
|
|
|
+ return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static FILE *
|
2010-03-20 03:42:15 +01:00
|
|
|
@@ -370,7 +495,6 @@
|
2009-06-03 00:58:26 +02:00
|
|
|
DebugF("Loaded XKB keymap %s, defined=0x%x\n",fileName,(*xkbRtrn)->defined);
|
|
|
|
}
|
|
|
|
fclose(file);
|
|
|
|
- (void) unlink (fileName);
|
|
|
|
return (need|want)&(~missing);
|
|
|
|
}
|
|
|
|
|