Blame SOURCES/screen-reattach.patch

c18ec5
diff --git a/src/attacher.c b/src/attacher.c
c18ec5
index 460f1ea..5982a93 100644
c18ec5
--- a/src/attacher.c
c18ec5
+++ b/src/attacher.c
c18ec5
@@ -133,6 +133,48 @@ struct msg *m;
c18ec5
   return 0;
c18ec5
 }
c18ec5
 
c18ec5
+int
c18ec5
+WriteOldMessage(struct msg *m)
c18ec5
+{
c18ec5
+  sleep(1); /* give the server some time to reopen the pipe */
c18ec5
+  if (m->type == MSG_ATTACH && (m->m.attach.detachfirst == MSG_ATTACH ||
c18ec5
+				m->m.attach.detachfirst == MSG_DETACH ||
c18ec5
+				m->m.attach.detachfirst == MSG_POW_DETACH))
c18ec5
+    {
c18ec5
+      struct old_msg old_m;
c18ec5
+      int s;
c18ec5
+      int r, l = sizeof(old_m);
c18ec5
+
c18ec5
+      s = MakeClientSocket(0);
c18ec5
+      if (s < 0)
c18ec5
+	return 0;
c18ec5
+      old_m.protocol_revision = (('m'<<24) | ('s'<<16) | ('g'<<8) | 2);
c18ec5
+      old_m.type = m->type;
c18ec5
+      memcpy(old_m.m_tty, m->m_tty, sizeof(old_m.m_tty));
c18ec5
+      memcpy(old_m.m.attach.auser, m->m.attach.auser, sizeof(old_m.m.attach.auser));
c18ec5
+      old_m.m.attach.apid = m->m.attach.apid;
c18ec5
+      old_m.m.attach.adaptflag = m->m.attach.adaptflag;
c18ec5
+      old_m.m.attach.lines = m->m.attach.lines;
c18ec5
+      old_m.m.attach.columns = m->m.attach.columns;
c18ec5
+      memcpy(old_m.m.attach.preselect, m->m.attach.preselect, sizeof(old_m.m.attach.preselect));
c18ec5
+      old_m.m.attach.esc = m->m.attach.esc;
c18ec5
+      old_m.m.attach.meta_esc = m->m.attach.meta_esc;
c18ec5
+      memcpy(old_m.m.attach.envterm, m->m.attach.envterm, sizeof(old_m.m.attach.envterm));
c18ec5
+      old_m.m.attach.encoding = m->m.attach.encoding;
c18ec5
+      while(l > 0)
c18ec5
+        {
c18ec5
+          r = write(s, (char *)&old_m + (sizeof(struct old_msg) - l), l);
c18ec5
+          if (r == -1 && errno == EINTR)
c18ec5
+    	continue;
c18ec5
+          if (r == -1 || r == 0)
c18ec5
+    	return -1;
c18ec5
+          l -= r;
c18ec5
+        }
c18ec5
+      close(s);
c18ec5
+    }
c18ec5
+  return 0;
c18ec5
+}
c18ec5
+
c18ec5
 
c18ec5
 int
c18ec5
 Attach(how)
c18ec5
@@ -397,6 +439,7 @@ int how;
c18ec5
   if (WriteMessage(lasts, &m))
c18ec5
     Panic(errno, "WriteMessage");
c18ec5
   close(lasts);
c18ec5
+  WriteOldMessage(&m);
c18ec5
   debug1("Attach(%d): sent\n", m.type);
c18ec5
 #ifdef MULTIUSER
c18ec5
   if (multi && (how == MSG_ATTACH || how == MSG_CONT))
c18ec5
diff --git a/src/screen.h b/src/screen.h
c18ec5
index b95f8a2..fb4a8d4 100644
c18ec5
--- a/src/screen.h
c18ec5
+++ b/src/screen.h
c18ec5
@@ -240,6 +240,60 @@ struct msg
c18ec5
     } m;
c18ec5
 };
c18ec5
 
c18ec5
+struct old_msg
c18ec5
+{
c18ec5
+  int protocol_revision;	/* reduce harm done by incompatible messages */
c18ec5
+  int type;
c18ec5
+  char m_tty[MAXPATHLEN];	/* ttyname */
c18ec5
+  union
c18ec5
+    {
c18ec5
+      struct
c18ec5
+	{
c18ec5
+	  int lflag;
c18ec5
+	  int aflag;
c18ec5
+	  int flowflag;
c18ec5
+	  int hheight;		/* size of scrollback buffer */
c18ec5
+	  int nargs;
c18ec5
+	  char line[MAXPATHLEN];
c18ec5
+	  char dir[MAXPATHLEN];
c18ec5
+	  char screenterm[20];	/* is screen really "screen" ? */
c18ec5
+	}
c18ec5
+      create;
c18ec5
+      struct
c18ec5
+	{
c18ec5
+	  char auser[20 + 1];	/* username */
c18ec5
+	  int apid;		/* pid of frontend */
c18ec5
+	  int adaptflag;	/* adapt window size? */
c18ec5
+	  int lines, columns;	/* display size */
c18ec5
+	  char preselect[20];
c18ec5
+	  int esc;		/* his new escape character unless -1 */
c18ec5
+	  int meta_esc;		/* his new meta esc character unless -1 */
c18ec5
+	  char envterm[40 + 1];	/* terminal type */
c18ec5
+	  int encoding;		/* encoding of display */
c18ec5
+      int detachfirst;
c18ec5
+	}
c18ec5
+      attach;
c18ec5
+      struct 
c18ec5
+	{
c18ec5
+	  char duser[20 + 1];	/* username */
c18ec5
+	  int dpid;		/* pid of frontend */
c18ec5
+	}
c18ec5
+      detach;
c18ec5
+      struct 
c18ec5
+	{
c18ec5
+	  char auser[20 + 1];	/* username */
c18ec5
+	  int nargs;
c18ec5
+	  char cmd[MAXPATHLEN];	/* command */
c18ec5
+	  int apid;		/* pid of frontend */
c18ec5
+	  char preselect[20];
c18ec5
+      char writeback[MAXPATHLEN];
c18ec5
+	}
c18ec5
+      command;
c18ec5
+      char message[MAXPATHLEN * 2];
c18ec5
+    } m;
c18ec5
+};
c18ec5
+
c18ec5
+
c18ec5
 /*
c18ec5
  * And the signals the attacher receives from the backend
c18ec5
  */
c18ec5
diff --git a/src/socket.c b/src/socket.c
c18ec5
index 32c5047..d5a3d74 100644
c18ec5
--- a/src/socket.c
c18ec5
+++ b/src/socket.c
c18ec5
@@ -1067,7 +1067,9 @@ ReceiveMsg()
c18ec5
     }
c18ec5
   if (left > 0)
c18ec5
     {
c18ec5
-      if (left != sizeof(m))
c18ec5
+      if (left == sizeof(struct msg) - sizeof(struct old_msg))
c18ec5
+	    ;/* old format message, ignore */
c18ec5
+      else if (left != sizeof(m))
c18ec5
         Msg(0, "Message %d of %d bytes too small", left, (int)sizeof(m));
c18ec5
       else
c18ec5
 	debug("No data on socket.\n");