6852921 Recycling the Xorg server runs out of file descriptors in the keyboard driver
authorAlan Coopersmith <Alan.Coopersmith@Sun.COM>
Mon, 17 Aug 2009 13:23:12 -0700
changeset 769 e3008b200834
parent 768 96c938e84747
child 770 de6710fc08fd
6852921 Recycling the Xorg server runs out of file descriptors in the keyboard driver
open-src/driver/xf86-input-keyboard/6852921.patch
open-src/driver/xf86-input-keyboard/Makefile
open-src/driver/xf86-input-keyboard/sun-kb-autodetect.patch
open-src/driver/xf86-input-keyboard/sun-kbd-vt.patch
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/open-src/driver/xf86-input-keyboard/6852921.patch	Mon Aug 17 13:23:12 2009 -0700
@@ -0,0 +1,120 @@
+# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, and/or sell copies of the Software, and to permit persons
+# to whom the Software is furnished to do so, provided that the above
+# copyright notice(s) and this permission notice appear in all copies of
+# the Software and that both the above copyright notice(s) and this
+# permission notice appear in supporting documentation.
+# 
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
+# OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+# HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
+# INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
+# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+# 
+# Except as contained in this notice, the name of a copyright holder
+# shall not be used in advertising or otherwise to promote the sale, use
+# or other dealings in this Software without prior written authorization
+# of the copyright holder.
+
+diff --git a/src/sun_kbd.c b/src/sun_kbd.c
+index b4ebc57..bb831c1 100644
+--- a/src/sun_kbd.c
++++ b/src/sun_kbd.c
+@@ -65,6 +65,8 @@
+ #include <sys/kbd.h>
+ 
+ static int KbdOn(InputInfoPtr pInfo, int what);
++static Bool OpenKeyboard(InputInfoPtr pInfo);
++static void CloseKeyboard(InputInfoPtr pInfo);
+ 
+ static void
+ sunKbdSetLeds(InputInfoPtr pInfo, int leds)
+@@ -171,6 +173,12 @@ KbdOn(InputInfoPtr pInfo, int what)
+ 	return Success;
+     }
+ 
++    if (pInfo->fd == -1) {
++	if (!OpenKeyboard(pInfo)) {
++	    return BadImplementation;
++	}
++    }
++
+     if (priv->strmod) {
+ 	SYSCALL(i = ioctl(pInfo->fd, I_PUSH, priv->strmod));
+ 	if (i < 0) {
+@@ -236,6 +244,11 @@ KbdOff(InputInfoPtr pInfo, int what)
+ 
+     int i;
+ 
++    if (priv->remove_timer) {
++	TimerFree(priv->remove_timer);
++	priv->remove_timer = NULL;
++    }
++
+     if (!priv->kbdActive) {
+ 	return Success;
+     }
+@@ -245,11 +258,6 @@ KbdOff(InputInfoPtr pInfo, int what)
+ 	return Success;
+     }
+ 
+-    if (priv->remove_timer) {
+-	TimerFree(priv->remove_timer);
+-	priv->remove_timer = NULL;
+-    }
+-
+     /* restore original state */
+ 
+     if (priv->oleds != -1) {
+@@ -288,7 +296,7 @@ KbdOff(InputInfoPtr pInfo, int what)
+ 	}
+     }
+ 
+-    priv->kbdActive = FALSE;
++    CloseKeyboard(pInfo);
+     return Success;
+ }
+ 
+@@ -385,20 +393,26 @@ SetKbdRepeat(InputInfoPtr pInfo, char rad)
+     /* Nothing to do */
+ }
+ 
+-/* Called from OsTimer callback, since removing a device from the device
+-   list or changing pInfo->fd while xf86Wakeup is looping through the list
+-   causes server crashes */
+-static CARD32
+-RemoveKeyboard(OsTimerPtr timer, CARD32 time, pointer arg)
++static void
++CloseKeyboard(InputInfoPtr pInfo)
+ {
+-    InputInfoPtr pInfo = (InputInfoPtr) arg;
+     KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
+     sunKbdPrivPtr priv = (sunKbdPrivPtr) pKbd->private;
+ 
+     close(pInfo->fd);
+     pInfo->fd = -1;
+     priv->kbdActive = FALSE;
++}
++
++/* Called from OsTimer callback, since removing a device from the device
++   list or changing pInfo->fd while xf86Wakeup is looping through the list
++   causes server crashes */
++static CARD32
++RemoveKeyboard(OsTimerPtr timer, CARD32 time, pointer arg)
++{
++    InputInfoPtr pInfo = (InputInfoPtr) arg;
+ 
++    CloseKeyboard(pInfo);
+     xf86DisableDevice(pInfo->dev, TRUE);
+ 
+     return 0;  /* All done, don't set to run again */
--- a/open-src/driver/xf86-input-keyboard/Makefile	Mon Aug 17 11:38:55 2009 -0700
+++ b/open-src/driver/xf86-input-keyboard/Makefile	Mon Aug 17 13:23:12 2009 -0700
@@ -3,7 +3,7 @@
 # xf86-input-keyboard 1.x Makefile
 #
 # Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
-# Use subject to license terms.
+# Use is subject to license terms.
 #
 # Permission is hereby granted, free of charge, to any person obtaining a
 # copy of this software and associated documentation files (the
@@ -30,7 +30,7 @@
 # or other dealings in this Software without prior written authorization
 # of the copyright holder.
 #
-# @(#)Makefile	1.9	09/08/14
+# ident	"@(#)Makefile	1.10	09/08/17 SMI"
 #
 
 # Package name used in tarballs
@@ -44,6 +44,7 @@
 	hal-man-page.patch,-p1 \
 	hal-hotplug.patch,-p1 \
 	sun-keymappings.patch,-p1 \
+	6852921.patch,-p1 \
 	sun-kb-autodetect.patch \
 	sun-kbd-vt.patch
 
--- a/open-src/driver/xf86-input-keyboard/sun-kb-autodetect.patch	Mon Aug 17 11:38:55 2009 -0700
+++ b/open-src/driver/xf86-input-keyboard/sun-kb-autodetect.patch	Mon Aug 17 13:23:12 2009 -0700
@@ -1,5 +1,5 @@
 # Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
-# Use subject to license terms.
+# Use is subject to license terms.
 #
 # Permission is hereby granted, free of charge, to any person obtaining a
 # copy of this software and associated documentation files (the
@@ -40,11 +40,11 @@
  if BSD
  kbd_drv_la_SOURCES += $(BSD_SRCS)
 diff -urp -x '*~' -x '*.orig' src/sun_kbd.c src/sun_kbd.c
---- src/sun_kbd.c	2009-05-01 14:17:10.638383000 -0700
-+++ src/sun_kbd.c	2009-05-01 14:17:11.512762000 -0700
-@@ -66,6 +66,10 @@
- 
- static int KbdOn(InputInfoPtr pInfo, int what);
+--- src/sun_kbd.c	2009-08-05 16:56:35.195954000 -0700
++++ src/sun_kbd.c	2009-08-05 16:56:35.982990000 -0700
+@@ -68,6 +68,10 @@ static int KbdOn(InputInfoPtr pInfo, int
+ static Bool OpenKeyboard(InputInfoPtr pInfo);
+ static void CloseKeyboard(InputInfoPtr pInfo);
  
 +#ifdef XKB
 +# include "sun_xkbtable.h"
@@ -53,7 +53,7 @@
  static void
  sunKbdSetLeds(InputInfoPtr pInfo, int leds)
  {
-@@ -100,6 +104,13 @@ sunKbdGetLeds(InputInfoPtr pInfo)
+@@ -102,6 +106,13 @@ sunKbdGetLeds(InputInfoPtr pInfo)
  static int
  KbdInit(InputInfoPtr pInfo, int what)
  {
@@ -67,7 +67,7 @@
      KbdDevPtr pKbd = (KbdDevPtr) pInfo->private;
      sunKbdPrivPtr priv = (sunKbdPrivPtr) pKbd->private;
      pointer options = pInfo->options;
-@@ -154,6 +165,7 @@ KbdInit(InputInfoPtr pInfo, int what)
+@@ -156,6 +167,7 @@ KbdInit(InputInfoPtr pInfo, int what)
      xf86Msg(X_PROBED, "%s: Keyboard layout: %d\n", pInfo->name, klayout);
  
      priv->ktype 	= ktype;
@@ -75,7 +75,7 @@
  
      return Success;
  }
-@@ -481,6 +493,61 @@ OpenKeyboard(InputInfoPtr pInfo)
+@@ -495,6 +507,61 @@ OpenKeyboard(InputInfoPtr pInfo)
      if (pInfo->fd == -1) {
  	return FALSE;
      } else {
--- a/open-src/driver/xf86-input-keyboard/sun-kbd-vt.patch	Mon Aug 17 11:38:55 2009 -0700
+++ b/open-src/driver/xf86-input-keyboard/sun-kbd-vt.patch	Mon Aug 17 13:23:12 2009 -0700
@@ -1,6 +1,6 @@
 diff -urp -x '*~' -x '*.orig' src/sun_kbd.c src/sun_kbd.c
---- src/sun_kbd.c	2009-08-13 13:19:37.444951000 +0800
-+++ src/sun_kbd.c	2009-08-13 13:19:37.668124000 +0800
+--- src/sun_kbd.c	2009-08-15 18:12:35.579394000 -0700
++++ src/sun_kbd.c	2009-08-15 18:12:36.475454000 -0700
 @@ -63,6 +63,7 @@
  #include <sys/stropts.h>
  #include <sys/vuid_event.h>
@@ -8,8 +8,8 @@
 +#include <sys/usb/clients/hid/hid.h>
  
  static int KbdOn(InputInfoPtr pInfo, int what);
- 
-@@ -178,6 +179,8 @@ KbdOn(InputInfoPtr pInfo, int what)
+ static Bool OpenKeyboard(InputInfoPtr pInfo);
+@@ -180,6 +181,8 @@ KbdOn(InputInfoPtr pInfo, int what)
      sunKbdPrivPtr priv = (sunKbdPrivPtr) pKbd->private;
  
      int	ktrans, kdirect, i;
@@ -18,7 +18,7 @@
  
      if (priv->kbdActive) {
  	return Success;
-@@ -190,9 +193,15 @@ KbdOn(InputInfoPtr pInfo, int what)
+@@ -198,9 +201,15 @@ KbdOn(InputInfoPtr pInfo, int what)
  		    "%s: cannot push module '%s' onto keyboard device: %s\n",
  		    pInfo->name, priv->strmod, strerror(errno));
  	}
@@ -35,7 +35,7 @@
      if (i < 0) {
  	xf86Msg(X_ERROR, 
  		"%s: Unable to determine keyboard direct setting: %s\n", 
-@@ -203,7 +212,7 @@ KbdOn(InputInfoPtr pInfo, int what)
+@@ -211,7 +220,7 @@ KbdOn(InputInfoPtr pInfo, int what)
      priv->odirect = kdirect;
      kdirect = 1;
  
@@ -44,15 +44,15 @@
      if (i < 0) {
  	xf86Msg(X_ERROR, "%s: Failed turning keyboard direct mode on: %s\n",
  			pInfo->name, strerror(errno));
-@@ -247,6 +256,7 @@ KbdOff(InputInfoPtr pInfo, int what)
+@@ -255,6 +264,7 @@ KbdOff(InputInfoPtr pInfo, int what)
      sunKbdPrivPtr priv = (sunKbdPrivPtr) pKbd->private;
  
      int i;
 +    int io_set_direct, kdirect;
  
-     if (!priv->kbdActive) {
- 	return Success;
-@@ -280,8 +290,16 @@ KbdOff(InputInfoPtr pInfo, int what)
+     if (priv->remove_timer) {
+ 	TimerFree(priv->remove_timer);
+@@ -288,8 +298,16 @@ KbdOff(InputInfoPtr pInfo, int what)
  	priv->otranslation = -1;
      }