commit bf5d4824d72931b1d699eb3ca65ce9685ca195c8
Author: Clark Wang <dearvoid@gmail.com>
Date:   Sat 2021-10-23 20:54:15 +0800

    new opt: -k sockdir

diff --git a/src/help.c b/src/help.c
index a8e35e2..a91acea 100644
--- a/src/help.c
+++ b/src/help.c
@@ -69,6 +69,7 @@ void exit_with_usage(char *myname, char *message, char *arg)
   printf("-a            Force all capabilities into each window's termcap.\n");
   printf("-A -[r|R]     Adapt all windows to the new display width & height.\n");
   printf("-c file       Read configuration file instead of '.screenrc'.\n");
+  printf("-k dir        Set the socket dir.\n");
 #ifdef REMOTE_DETACH
   printf("-d (-r)       Detach the elsewhere running screen (and reattach here).\n");
   printf("-dmS name     Start as daemon: Screen session in detached mode.\n");
diff --git a/src/screen.c b/src/screen.c
index 7dcb9af..accd9fb 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -370,7 +370,7 @@ int main(int ac, char** av)
   char socknamebuf[2 * MAXSTR];
   int mflag = 0;
   char *myname = (ac == 0) ? "screen" : av[0];
-  char *SockDir;
+  char *SockDir = NULL;
   struct stat st;
 #ifdef _MODE_T			/* (jw) */
   mode_t oumask;
@@ -634,6 +634,17 @@ int main(int ac, char** av)
             iflag = 1;
             break;
 
+          case 'k':
+            if (*++ap)
+              SockDir = ap;
+            else {
+              if (--ac == 0)
+                exit_with_usage(myname, "Specify the socket dir with -k", NULL);
+              SockDir = *++av;
+            }
+            ap = NULL;
+            break;
+
           case 't': /* title, the former AkA == -k */
             if (--ac == 0)
               exit_with_usage(myname, "Specify a new window-name with -t", NULL);
@@ -1041,15 +1052,17 @@ int main(int ac, char** av)
       Panic(errno, "Cannot change umask to zero");
 #endif
 
-    SockDir = getenv("SCREENDIR");
-    if (SockDir) {
-      if (strlen(SockDir) >= MAXPATHLEN - 1)
-        Panic(0, "Ridiculously long $SCREENDIR - try again.");
+    if (SockDir == NULL) {
+      SockDir = getenv("SCREENDIR");
+      if (SockDir) {
+        if (strlen(SockDir) >= MAXPATHLEN - 1)
+          Panic(0, "Ridiculously long $SCREENDIR - try again.");
 
 #ifdef MULTIUSER
-      if (multi)
-        Panic(0, "No $SCREENDIR with multi screens, please.");
+        if (multi)
+          Panic(0, "No $SCREENDIR with multi screens, please.");
 #endif
+      }
     }
 
 #ifdef MULTIUSER
