Blame SOURCES/screen-reattach.patch

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