Bug#183029: PATCH: put X, XIM, Xfs unix sockets in /var/run/X11

2003-03-01 Thread Zack Weinberg
Package: xfree86
Version: unavailable; reported 2003-03-01
Severity: wishlist
Tags: patch

As requested I'm re-transmitting this as a wishlist bug.

I edited the change to debian/xfree86-common.README.Debian so that it
now says "4.3.0-1" instead of "4.2.1-6".  4.2.1-6 is already out the
door, and I'm guessing you'd rather look at this in the 4.3.x timeframe
anyway.



This patch moves the UNIX domain sockets created by the X server, the
font server, and XIM input methods from various .subdirs of /tmp to
/var/run/X11, which directory is created at boot time by the existing
xfree86-common init script.

This change naturally has backward compatibility implications.  There
are several cases to consider:

* New client, old server (for any of the above): logic exists in the
  Xtrans client code to try an old location if the socket is not found
  in the new one, so this is not a problem.

* New X server, old libX11: The boot script creates a symbolic link
  from /tmp/.X11-unix to /var/run/X11, which should prevent any
  trouble in this case.  (Users who know they don't need this can
  disable it.)

* New font server or input method, old X server: This is unlikely to
  come up, but the boot script can be edited to create more symlinks
  if necessary.  README.Debian documents this.

I did not move the socket directory for libICE, because those sockets
get created by arbitrary users.  The major point of moving sockets to
/var/run/X11 is that that directory can be mode 755.  I can think of a
couple ways to get around that but they're all messy enough not to be
worth it.

I also did not move /tmp/.X%d-lock as that would break cohabitation of
old and new X servers on the same host.

zw

--- xc/config/cf/linux.cf~  2003-02-06 23:42:21.0 -0800
+++ xc/config/cf/linux.cf   2003-02-14 14:17:55.0 -0800
@@ -125,7 +125,8 @@
 # define SharedLibGlu  YES
 # define NormalLibGlu  YES
 # define FSUseSyslog   YES
+# define UnixSocketsInVarRun   YES

 /*
  *
--- xc/config/cf/X11.tmpl~  2003-02-06 20:56:37.0 -0800
+++ xc/config/cf/X11.tmpl   2003-02-14 14:21:07.0 -0800
@@ -562,6 +562,10 @@
 #define InstallMiscManPagesNO
 #endif
 
+#ifndef UnixSocketsInVarRun
+#define UnixSocketsInVarRunNO
+#endif
+
 #ifndef FSUseSyslog
 #define FSUseSyslogNO
 #endif
@@ -704,8 +708,11 @@
 #if HasFchown
 FCHOWN_DEFINES = -DHAS_FCHOWN
 #endif
+#if UnixSocketsInVarRun
+USLOC_DEFINES = -DSOCKETS_IN_VAR_RUN
+#endif
 #ifndef ExtraConnectionDefs
-#define ExtraConnectionDefs $(STICKY_DEFINES) $(FCHOWN_DEFINES)
+#define ExtraConnectionDefs $(STICKY_DEFINES) $(FCHOWN_DEFINES) 
$(USLOC_DEFINES)
 #endif
 #ifndef ProjectThreadsDefines
 #define ProjectThreadsDefines -DXTHREADS
--- xc/lib/xtrans/Xtranssock.c~ 2001-12-14 11:57:06.0 -0800
+++ xc/lib/xtrans/Xtranssock.c  2003-02-14 14:46:14.0 -0800
@@ -228,7 +228,40 @@
 #define UNIX_DIR  "/usr/spool/sockets/X11"
 #endif
 
-#else /* !hpux */
+#elif defined(SOCKETS_IN_VAR_RUN)
+
+#if defined(X11_t)
+#define UNIX_PATH "/var/run/X11/X"
+#define UNIX_DIR "/var/run/X11"
+#define OLD_UNIX_PATH "/tmp/.X11-unix/X"
+#endif /* X11_t */
+#if defined(XIM_t)
+#define UNIX_PATH "/var/run/X11/XIM"
+#define UNIX_DIR "/var/run/X11"
+#define OLD_UNIX_PATH "/tmp/.XIM-unix/XIM"
+#endif /* XIM_t */
+#if defined(FS_t) || defined(FONT_t)
+#define UNIX_PATH "/var/run/X11/fs"
+#define UNIX_DIR "/var/run/X11"
+#define OLD_UNIX_PATH "/tmp/.font-unix/fs"
+#endif /* FS_t || FONT_t */
+#if defined(ICE_t)
+/* ICE sockets stay in /tmp since those are created by clients.  */
+#define UNIX_PATH "/tmp/.ICE-unix/"
+#define UNIX_DIR "/tmp/.ICE-unix"
+#endif /* ICE_t */
+#if defined(TEST_t)
+/* ??? Does not appear to be used for anything.  */
+#define UNIX_PATH "/tmp/.Test-unix/test"
+#define UNIX_DIR "/tmp/.Test-unix"
+#endif
+#if defined(LBXPROXY_t)
+#define UNIX_PATH "/var/run/X11/X"
+#define UNIX_DIR "/var/run/X11"
+#define OLD_UNIX_PATH "/tmp/.X11-unix/X"
+#endif
+
+#else /* not hpux and not /var/run/X11 */
 
 #if defined(X11_t)
 #define UNIX_PATH "/tmp/.X11-unix/X"
@@ -1552,7 +1585,7 @@
 struct sockaddr_un sockname;
 intnamelen;
 
-#if defined(hpux) && defined(X11_t)
+#ifdef OLD_UNIX_PATH
 struct sockaddr_un old_sockname;
 intold_namelen;
 #endif
@@ -1607,9 +1640,9 @@
 #endif
 
 
-#if defined(hpux) && defined(X11_t)
+#ifdef OLD_UNIX_PATH
 /*
- * This is gross, but it was in Xlib
+ * Support an older location for the socket.
  */
 old_sockname.sun_family = AF_UNIX;
 if (set_sun_path(port, OLD_UNIX_PATH, old_sockname.sun_path) != 0) {
@@ -1620,7 +1653,6 @@
sizeof (old_sockname.sun_family);
 #endif
 
-
 /*
  * Do the connect()
  */
@@ -1630,7 +1662,7 @@
int olderrno = errno;
int connected = 0;

-#if defined(hpux) && defined(X11_t)
+#ifdef OLD_UNIX_PATH
if (olderrno == ENOENT)
{
if (connect

Bug#183029: PATCH: put X, XIM, Xfs unix sockets in /var/run/X11

2003-03-01 Thread Zack Weinberg
Package: xfree86
Version: unavailable; reported 2003-03-01
Severity: wishlist
Tags: patch

As requested I'm re-transmitting this as a wishlist bug.

I edited the change to debian/xfree86-common.README.Debian so that it
now says "4.3.0-1" instead of "4.2.1-6".  4.2.1-6 is already out the
door, and I'm guessing you'd rather look at this in the 4.3.x timeframe
anyway.



This patch moves the UNIX domain sockets created by the X server, the
font server, and XIM input methods from various .subdirs of /tmp to
/var/run/X11, which directory is created at boot time by the existing
xfree86-common init script.

This change naturally has backward compatibility implications.  There
are several cases to consider:

* New client, old server (for any of the above): logic exists in the
  Xtrans client code to try an old location if the socket is not found
  in the new one, so this is not a problem.

* New X server, old libX11: The boot script creates a symbolic link
  from /tmp/.X11-unix to /var/run/X11, which should prevent any
  trouble in this case.  (Users who know they don't need this can
  disable it.)

* New font server or input method, old X server: This is unlikely to
  come up, but the boot script can be edited to create more symlinks
  if necessary.  README.Debian documents this.

I did not move the socket directory for libICE, because those sockets
get created by arbitrary users.  The major point of moving sockets to
/var/run/X11 is that that directory can be mode 755.  I can think of a
couple ways to get around that but they're all messy enough not to be
worth it.

I also did not move /tmp/.X%d-lock as that would break cohabitation of
old and new X servers on the same host.

zw

--- xc/config/cf/linux.cf~  2003-02-06 23:42:21.0 -0800
+++ xc/config/cf/linux.cf   2003-02-14 14:17:55.0 -0800
@@ -125,7 +125,8 @@
 # define SharedLibGlu  YES
 # define NormalLibGlu  YES
 # define FSUseSyslog   YES
+# define UnixSocketsInVarRun   YES

 /*
  *
--- xc/config/cf/X11.tmpl~  2003-02-06 20:56:37.0 -0800
+++ xc/config/cf/X11.tmpl   2003-02-14 14:21:07.0 -0800
@@ -562,6 +562,10 @@
 #define InstallMiscManPagesNO
 #endif
 
+#ifndef UnixSocketsInVarRun
+#define UnixSocketsInVarRunNO
+#endif
+
 #ifndef FSUseSyslog
 #define FSUseSyslogNO
 #endif
@@ -704,8 +708,11 @@
 #if HasFchown
 FCHOWN_DEFINES = -DHAS_FCHOWN
 #endif
+#if UnixSocketsInVarRun
+USLOC_DEFINES = -DSOCKETS_IN_VAR_RUN
+#endif
 #ifndef ExtraConnectionDefs
-#define ExtraConnectionDefs $(STICKY_DEFINES) $(FCHOWN_DEFINES)
+#define ExtraConnectionDefs $(STICKY_DEFINES) $(FCHOWN_DEFINES) $(USLOC_DEFINES)
 #endif
 #ifndef ProjectThreadsDefines
 #define ProjectThreadsDefines -DXTHREADS
--- xc/lib/xtrans/Xtranssock.c~ 2001-12-14 11:57:06.0 -0800
+++ xc/lib/xtrans/Xtranssock.c  2003-02-14 14:46:14.0 -0800
@@ -228,7 +228,40 @@
 #define UNIX_DIR  "/usr/spool/sockets/X11"
 #endif
 
-#else /* !hpux */
+#elif defined(SOCKETS_IN_VAR_RUN)
+
+#if defined(X11_t)
+#define UNIX_PATH "/var/run/X11/X"
+#define UNIX_DIR "/var/run/X11"
+#define OLD_UNIX_PATH "/tmp/.X11-unix/X"
+#endif /* X11_t */
+#if defined(XIM_t)
+#define UNIX_PATH "/var/run/X11/XIM"
+#define UNIX_DIR "/var/run/X11"
+#define OLD_UNIX_PATH "/tmp/.XIM-unix/XIM"
+#endif /* XIM_t */
+#if defined(FS_t) || defined(FONT_t)
+#define UNIX_PATH "/var/run/X11/fs"
+#define UNIX_DIR "/var/run/X11"
+#define OLD_UNIX_PATH "/tmp/.font-unix/fs"
+#endif /* FS_t || FONT_t */
+#if defined(ICE_t)
+/* ICE sockets stay in /tmp since those are created by clients.  */
+#define UNIX_PATH "/tmp/.ICE-unix/"
+#define UNIX_DIR "/tmp/.ICE-unix"
+#endif /* ICE_t */
+#if defined(TEST_t)
+/* ??? Does not appear to be used for anything.  */
+#define UNIX_PATH "/tmp/.Test-unix/test"
+#define UNIX_DIR "/tmp/.Test-unix"
+#endif
+#if defined(LBXPROXY_t)
+#define UNIX_PATH "/var/run/X11/X"
+#define UNIX_DIR "/var/run/X11"
+#define OLD_UNIX_PATH "/tmp/.X11-unix/X"
+#endif
+
+#else /* not hpux and not /var/run/X11 */
 
 #if defined(X11_t)
 #define UNIX_PATH "/tmp/.X11-unix/X"
@@ -1552,7 +1585,7 @@
 struct sockaddr_un sockname;
 intnamelen;
 
-#if defined(hpux) && defined(X11_t)
+#ifdef OLD_UNIX_PATH
 struct sockaddr_un old_sockname;
 intold_namelen;
 #endif
@@ -1607,9 +1640,9 @@
 #endif
 
 
-#if defined(hpux) && defined(X11_t)
+#ifdef OLD_UNIX_PATH
 /*
- * This is gross, but it was in Xlib
+ * Support an older location for the socket.
  */
 old_sockname.sun_family = AF_UNIX;
 if (set_sun_path(port, OLD_UNIX_PATH, old_sockname.sun_path) != 0) {
@@ -1620,7 +1653,6 @@
sizeof (old_sockname.sun_family);
 #endif
 
-
 /*
  * Do the connect()
  */
@@ -1630,7 +1662,7 @@
int olderrno = errno;
int connected = 0;

-#if defined(hpux) && defined(X11_t)
+#ifdef OLD_UNIX_PATH
if (olderrno == ENOENT)
{
if (connect