diff -ur screen-3.9.15/screen.c screen-3.9.15-foo/screen.c
--- screen-3.9.15/screen.c	2003-07-01 17:26:29.000000000 -0400
+++ screen-3.9.15-foo/screen.c	2003-07-01 18:06:08.000000000 -0400
@@ -270,6 +270,40 @@
 /********************************************************************/
 /********************************************************************/
 
+#include <sys/types.h>   /* NOT CLEAN */
+#include <sys/socket.h>
+#include <sys/un.h>
+static int
+test_sock_un(char *directory)
+{
+  register int s;
+  struct sockaddr_un a;
+
+
+  if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
+    Panic(errno, "socket");
+  a.sun_family = AF_UNIX;
+  snprintf(a.sun_path, sizeof(a.sun_path), "%s/testsock", directory);
+  a.sun_path[sizeof(a.sun_path) - 1] = 0;
+  if (access(directory, W_OK))
+    {
+      debug2("test_sock_un: access(%s): %d.\n", directory, errno);
+      close(s);
+      return -1;
+    }
+  (void)unlink(a.sun_path);
+  if (bind(s, (struct sockaddr *) &a, strlen(a.sun_path)+2) == -1)
+    {
+      debug("test_sock_un: bind failed.\n");
+      close(s);
+      return -1;
+    }
+  unlink(a.sun_path);
+  if (s != -1)
+    close(s);
+  return s;
+}
+
 
 static struct passwd *
 getpwbyname(name, ppp)
@@ -933,19 +967,18 @@
       SockDir = SockPath;
 # else
       SockDir = SOCKDIR;
-      sprintf(SockPath, "%s/S-%s", SockDir, multi);
+      sprintf(SockPath, "%s/screen-%s", SockDir, multi);
 # endif
     }
   else
 #endif
     {
-#ifndef SOCKDIR
+      /* lhh - Try ~/.screen first. */
       if (SockDir == 0)
 	{
 	  sprintf(SockPath, "%s/.screen", home);
 	  SockDir = SockPath;
 	}
-#endif
       if (SockDir)
 	{
 	  if (access(SockDir, F_OK))
@@ -960,15 +993,18 @@
 	      if (UserStatus() <= 0)
 		Panic(0, "Cannot make directory '%s'.", SockDir);
 	    }
-	  if (SockDir != SockPath)
+	  if (test_sock_un(SockDir) == -1)
+	    SockDir = NULL;
+ 	  else if (SockDir != SockPath)
 	    strcpy(SockPath, SockDir);
 	}
 #ifdef SOCKDIR
-      else
+      if (!SockDir)
 	{
 	  SockDir = SOCKDIR;
 	  if (lstat(SockDir, &st))
 	    {
+#if 0
 	      n = (eff_uid == 0 && (real_uid || eff_gid == real_gid)) ? 0755 :
 	          (eff_gid != real_gid) ? 0775 :
 #ifdef S_ISVTX
@@ -978,6 +1014,8 @@
 #endif
 	      if (mkdir(SockDir, n) == -1)
 		Panic(errno, "Cannot make directory '%s'", SockDir);
+#endif /* #if 0 */
+		Panic(errno, "Can not stat '%s'", SockDir);
 	    }
 	  else
 	    {
@@ -991,7 +1029,7 @@
 	      if ((st.st_mode & 0777) != n)
 		Panic(0, "Directory '%s' must have mode %03o.", SockDir, n);
 	    }
-	  sprintf(SockPath, "%s/S-%s", SockDir, LoginName);
+	  sprintf(SockPath, "%s/screen-%s", SockDir, LoginName);
 	  if (access(SockPath, F_OK))
 	    {
 	      if (mkdir(SockPath, 0700) == -1)
Only in screen-3.9.15-foo: screen.c.screendir
Only in screen-3.9.15-foo: .socket.c.swp
