xorg-server: reinclude faststart patch (with added libgcrypt support)

Signed-off-by: Stephan Raue <stephan@openelec.tv>
This commit is contained in:
Stephan Raue 2011-01-13 15:36:23 +01:00
parent b5f5818f22
commit c96bc4a0f3

View File

@ -1,25 +1,13 @@
From: Yan Li <yan.i.li@intel.com> Patch from Moblin to cache xkbcomp output for faster booting
Date: Wed, 10 Mar 2010 14:06:17 +0800
Subject: [PATCH] XKB: cache xkbcomp output for fast start-up v7 for 1.8.99.903
xkbcomp outputs will be cached in files with hashed keymap as Signed-off-by: Bryce Harrington <bryce@canonical.com>
names. This saves boot time for around 1s on commodity netbooks. ---
V7: reworked Li Yan's patch for v1.8.99.903 Index: xorg-server/configure.ac
===================================================================
v6: rebased to v1.7.99.901 --- xorg-server.orig/configure.ac 2010-07-14 14:02:00.000000000 +1000
+++ xorg-server/configure.ac 2010-07-14 14:18:57.201453001 +1000
v5: now using a much bigger xkbKeyMapBuf (100k) since the XKB to be @@ -540,9 +540,9 @@
complied may be very large (as seen with
gnome-keyboard-properties), rebased to v1.6.1
Signed-off-by: Yan Li <yan.i.li@intel.com>
Signed-off-by: Liu Xinyun <xinyun.liu@intel.com>
diff --git a/configure.ac b/configure.ac
index 1a1f2d3..7c3224a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -540,9 +540,9 @@ AC_MSG_RESULT([$FONTPATH])
AC_ARG_WITH(xkb-path, AS_HELP_STRING([--with-xkb-path=PATH], [Path to XKB base dir (default: ${datadir}/X11/xkb)]), AC_ARG_WITH(xkb-path, AS_HELP_STRING([--with-xkb-path=PATH], [Path to XKB base dir (default: ${datadir}/X11/xkb)]),
[ XKBPATH="$withval" ], [ XKBPATH="$withval" ],
[ XKBPATH="${datadir}/X11/xkb" ]) [ XKBPATH="${datadir}/X11/xkb" ])
@ -31,7 +19,7 @@ index 1a1f2d3..7c3224a 100644
AC_ARG_WITH(default-xkb-rules, AS_HELP_STRING([--with-default-xkb-rules=RULES], AC_ARG_WITH(default-xkb-rules, AS_HELP_STRING([--with-default-xkb-rules=RULES],
[Keyboard ruleset (default: base/evdev)]), [Keyboard ruleset (default: base/evdev)]),
[ XKB_DFLT_RULES="$withval" ], [ XKB_DFLT_RULES="$withval" ],
@@ -1175,7 +1175,7 @@ AC_DEFINE_DIR(XKB_BIN_DIRECTORY, XKB_BIN_DIRECTORY, [Path to XKB bin dir]) @@ -1175,7 +1175,7 @@
dnl Make sure XKM_OUTPUT_DIR is an absolute path dnl Make sure XKM_OUTPUT_DIR is an absolute path
XKBOUTPUT_FIRSTCHAR=`echo $XKBOUTPUT | cut -b 1` XKBOUTPUT_FIRSTCHAR=`echo $XKBOUTPUT | cut -b 1`
if [[ x$XKBOUTPUT_FIRSTCHAR != x/ -a x$XKBOUTPUT_FIRSTCHAR != 'x$' ]] ; then if [[ x$XKBOUTPUT_FIRSTCHAR != x/ -a x$XKBOUTPUT_FIRSTCHAR != 'x$' ]] ; then
@ -40,11 +28,11 @@ index 1a1f2d3..7c3224a 100644
fi fi
dnl XKM_OUTPUT_DIR (used in code) must end in / or file names get hosed dnl XKM_OUTPUT_DIR (used in code) must end in / or file names get hosed
diff --git a/xkb/README.compiled b/xkb/README.compiled Index: xorg-server/xkb/README.compiled
index 71caa2f..a4a2ae0 100644 ===================================================================
--- a/xkb/README.compiled --- xorg-server.orig/xkb/README.compiled 2010-06-18 12:58:19.000000000 +1000
+++ b/xkb/README.compiled +++ xorg-server/xkb/README.compiled 2010-07-14 14:18:57.201453001 +1000
@@ -4,10 +4,10 @@ current keymap and/or any scratch keymaps used by clients. The X server @@ -4,10 +4,10 @@
or some other tool might destroy or replace the files in this directory, 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 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: time. The default keymap for any server is usually stored in:
@ -59,24 +47,24 @@ index 71caa2f..a4a2ae0 100644
Unless the X server is modified, sharing this directory between servers on Unless the X server is modified, sharing this directory between servers on
different hosts could cause problems. different hosts could cause problems.
diff --git a/xkb/ddxLoad.c b/xkb/ddxLoad.c Index: xorg-server/xkb/ddxLoad.c
index 5e6ab87..dec3644 100644 ===================================================================
--- a/xkb/ddxLoad.c --- xorg-server.orig/xkb/ddxLoad.c 2010-07-14 13:21:02.000000000 +1000
+++ b/xkb/ddxLoad.c +++ xorg-server/xkb/ddxLoad.c 2010-07-14 14:51:09.761453001 +1000
@@ -30,6 +30,12 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. @@ -30,6 +30,12 @@
#include <xkb-config.h> #include <xkb-config.h>
+#ifdef HAVE_SHA1_IN_LIBMD /* Use libmd for SHA1 */ +#ifdef HAVE_SHA1_IN_LIBGCRYPT /* Use libgcrypt for SHA1 */
+# include <sha1.h> +# include <gcrypt.h>
+#else /* Use OpenSSL's libcrypto */ +#else /* Use OpenSSL's libcrypto */
+# include <stddef.h> /* buggy openssl/sha.h wants size_t */ +#warning "xkbcomp caching support disabled"
+# include <openssl/sha.h>
+#endif +#endif
+
#include <stdio.h> #include <stdio.h>
#include <ctype.h> #include <ctype.h>
#include <X11/X.h> #include <X11/X.h>
@@ -43,24 +49,13 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. @@ -43,24 +49,13 @@
#define XKBSRV_NEED_FILE_FUNCS #define XKBSRV_NEED_FILE_FUNCS
#include <xkbsrv.h> #include <xkbsrv.h>
#include <X11/extensions/XI.h> #include <X11/extensions/XI.h>
@ -102,36 +90,39 @@ index 5e6ab87..dec3644 100644
#define PRE_ERROR_MSG "\"The XKEYBOARD keymap compiler (xkbcomp) reports:\"" #define PRE_ERROR_MSG "\"The XKEYBOARD keymap compiler (xkbcomp) reports:\""
#define ERROR_PREFIX "\"> \"" #define ERROR_PREFIX "\"> \""
#define POST_ERROR_MSG1 "\"Errors from xkbcomp are not fatal to the X server\"" #define POST_ERROR_MSG1 "\"Errors from xkbcomp are not fatal to the X server\""
@@ -175,6 +170,45 @@ OutputDirectory( @@ -174,6 +169,47 @@
}
} }
static Bool +#ifndef SHA_DIGEST_LENGTH
+#define SHA_DIGEST_LENGTH 20
+#endif
+
+static Bool
+Sha1Asc(char sha1Asc[SHA_DIGEST_LENGTH*2+1], const char * input) +Sha1Asc(char sha1Asc[SHA_DIGEST_LENGTH*2+1], const char * input)
+{ +{
+ int i; + int i;
+ unsigned char sha1[SHA_DIGEST_LENGTH]; + unsigned char sha1[SHA_DIGEST_LENGTH];
+ +
+#ifdef HAVE_SHA1_IN_LIBMD /* Use libmd for SHA1 */ +#ifdef HAVE_SHA1_IN_LIBGCRYPT /* Use libgcrypt for SHA1 */
+ SHA1_CTX ctx; + static int init;
+ gcry_md_hd_t h;
+ gcry_error_t err;
+ +
+ SHA1Init (&ctx); + if (!init) {
+ SHA1Update (&ctx, input, strlen(input)); + if (!gcry_check_version(NULL))
+ SHA1Final (sha1, &ctx);
+#else /* Use OpenSSL's libcrypto */
+ SHA_CTX ctx;
+ int success;
+
+ success = SHA1_Init (&ctx);
+ if (! success)
+ return BadAlloc; + return BadAlloc;
+ gcry_control(GCRYCTL_DISABLE_SECMEM, 0);
+ gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0);
+ init = 1;
+ }
+ +
+ success = SHA1_Update (&ctx, input, strlen(input)); + err = gcry_md_open(&h, GCRY_MD_SHA1, 0);
+ if (! success) + if (err)
+ return BadAlloc;
+
+ success = SHA1_Final (sha1, &ctx);
+ if (! success)
+ return BadAlloc; + return BadAlloc;
+ gcry_md_write(h, input, strlen(input));
+ memcpy(sha1, gcry_md_read(h, GCRY_MD_SHA1), 20);
+ gcry_md_close(h);
+#endif +#endif
+ +
+ /* convert sha1 to sha1_asc */ + /* convert sha1 to sha1_asc */
@ -144,11 +135,10 @@ index 5e6ab87..dec3644 100644
+ +
+/* call xkbcomp and compile XKB keymap, return xkm file name in +/* call xkbcomp and compile XKB keymap, return xkm file name in
+ nameRtrn */ + nameRtrn */
+static Bool static Bool
XkbDDXCompileKeymapByNames( XkbDescPtr xkb, XkbDDXCompileKeymapByNames( XkbDescPtr xkb,
XkbComponentNamesPtr names, XkbComponentNamesPtr names,
unsigned want, @@ -183,7 +219,11 @@
@@ -183,10 +217,14 @@ XkbDDXCompileKeymapByNames( XkbDescPtr xkb,
int nameRtrnLen) int nameRtrnLen)
{ {
FILE * out; FILE * out;
@ -160,12 +150,8 @@ index 5e6ab87..dec3644 100644
+ int ret, result; + int ret, result;
const char *emptystring = ""; const char *emptystring = "";
- char *xkbbasedirflag = NULL; char *xkbbasedirflag = NULL;
+ char *xkbbasedirflag = NULL; @@ -194,14 +234,67 @@
const char *xkbbindir = emptystring;
const char *xkbbindirsep = emptystring;
@@ -194,15 +232,67 @@ XkbDDXCompileKeymapByNames( XkbDescPtr xkb,
/* WIN32 has no popen. The input must be stored in a file which is /* 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. */ used as input for xkbcomp. xkbcomp does not read from stdin. */
char tmpname[PATH_MAX]; char tmpname[PATH_MAX];
@ -185,7 +171,8 @@ index 5e6ab87..dec3644 100644
+ return FALSE; + return FALSE;
+ } + }
+ ret = XkbWriteXKBKeymapForNames(out, names, xkb, want, need); + ret = XkbWriteXKBKeymapForNames(out, names, xkb, want, need);
+ if (fclose(out) !=0) { + if (fclose(out) !=0)
+ {
+ ErrorF("[xkb] XkbWriteXKBKeymapForNames error, perhaps xkbKeyMapBuf is too small\n"); + ErrorF("[xkb] XkbWriteXKBKeymapForNames error, perhaps xkbKeyMapBuf is too small\n");
+ return FALSE; + return FALSE;
+ } + }
@ -204,14 +191,14 @@ index 5e6ab87..dec3644 100644
+ DebugF("[xkb] computing SHA1 of keymap\n"); + DebugF("[xkb] computing SHA1 of keymap\n");
+ if (Success == Sha1Asc(sha1Asc, xkbKeyMapBuf)) { + if (Success == Sha1Asc(sha1Asc, xkbKeyMapBuf)) {
+ snprintf(xkmfile, sizeof(xkmfile), "server-%s", sha1Asc); + snprintf(xkmfile, sizeof(xkmfile), "server-%s", sha1Asc);
+ } else { + }
+ else {
+ ErrorF("[xkb] Computing SHA1 of keymap failed, " + ErrorF("[xkb] Computing SHA1 of keymap failed, "
+ "using display name instead as xkm file name\n"); + "using display name instead as xkm file name\n");
+ snprintf(xkmfile, sizeof(xkmfile), "server-%s", display); + snprintf(xkmfile, sizeof(xkmfile), "server-%s", display);
+ } + }
OutputDirectory(xkm_output_dir, sizeof(xkm_output_dir)); OutputDirectory(xkm_output_dir, sizeof(xkm_output_dir));
+ /* set nameRtrn, fail if it's too small */ + /* set nameRtrn, fail if it's too small */
+ if ((strlen(xkmfile)+1 > nameRtrnLen) && nameRtrn) { + if ((strlen(xkmfile)+1 > nameRtrnLen) && nameRtrn) {
+ ErrorF("[xkb] nameRtrn too small to hold xkmfile name\n"); + ErrorF("[xkb] nameRtrn too small to hold xkmfile name\n");
@ -232,11 +219,10 @@ index 5e6ab87..dec3644 100644
+ /* continue to call xkbcomp to compile the keymap. to avoid race + /* continue to call xkbcomp to compile the keymap. to avoid race
+ condition, we compile it to a tmpfile then rename it to + condition, we compile it to a tmpfile then rename it to
+ xkmfile */ + xkmfile */
+
#ifdef WIN32 #ifdef WIN32
strcpy(tmpname, Win32TempDir()); strcpy(tmpname, Win32TempDir());
strcat(tmpname, "\\xkb_XXXXXX"); @@ -225,14 +318,20 @@
@@ -225,14 +315,20 @@ XkbDDXCompileKeymapByNames( XkbDescPtr xkb,
} }
} }
@ -260,7 +246,7 @@ index 5e6ab87..dec3644 100644
free(xkbbasedirflag); free(xkbbasedirflag);
@@ -241,6 +337,11 @@ XkbDDXCompileKeymapByNames( XkbDescPtr xkb, @@ -241,6 +340,11 @@
return FALSE; return FALSE;
} }
@ -272,7 +258,7 @@ index 5e6ab87..dec3644 100644
#ifndef WIN32 #ifndef WIN32
out= Popen(buf,"w"); out= Popen(buf,"w");
#else #else
@@ -248,31 +349,41 @@ XkbDDXCompileKeymapByNames( XkbDescPtr xkb, @@ -248,31 +352,42 @@
#endif #endif
if (out!=NULL) { if (out!=NULL) {
@ -302,6 +288,7 @@ index 5e6ab87..dec3644 100644
- if (nameRtrn) { - if (nameRtrn) {
- strncpy(nameRtrn,keymap,nameRtrnLen); - strncpy(nameRtrn,keymap,nameRtrnLen);
- nameRtrn[nameRtrnLen-1]= '\0'; - nameRtrn[nameRtrnLen-1]= '\0';
+
+ /* if canonicalXkmFileName already exists now, we simply + /* if canonicalXkmFileName already exists now, we simply
+ overwrite it, this is OK */ + overwrite it, this is OK */
+ ret = rename(tmpXkmFile, canonicalXkmFileName); + ret = rename(tmpXkmFile, canonicalXkmFileName);
@ -328,10 +315,13 @@ index 5e6ab87..dec3644 100644
#ifdef WIN32 #ifdef WIN32
/* remove the temporary file */ /* remove the temporary file */
unlink(tmpname); unlink(tmpname);
@@ -287,9 +398,16 @@ XkbDDXCompileKeymapByNames( XkbDescPtr xkb, @@ -287,9 +402,17 @@
} }
if (nameRtrn) if (nameRtrn)
nameRtrn[0]= '\0'; nameRtrn[0]= '\0';
- if (buf != NULL)
- free(buf);
- return FALSE;
+ result = FALSE; + result = FALSE;
+ +
+_ret: +_ret:
@ -339,15 +329,14 @@ index 5e6ab87..dec3644 100644
+ free(tmpXkmFile); + free(tmpXkmFile);
+ if (canonicalXkmFileName) + if (canonicalXkmFileName)
+ free(canonicalXkmFileName); + free(canonicalXkmFileName);
if (buf != NULL) + if (buf)
- free(buf); + free(buf);
- return FALSE; +
+ free (buf);
+ return result; + return result;
} }
static FILE * static FILE *
@@ -373,7 +491,6 @@ unsigned missing; @@ -373,7 +496,6 @@
DebugF("Loaded XKB keymap %s, defined=0x%x\n",fileName,(*xkbRtrn)->defined); DebugF("Loaded XKB keymap %s, defined=0x%x\n",fileName,(*xkbRtrn)->defined);
} }
fclose(file); fclose(file);