Unix plink now catches SIGWINCH and propagates local terminal
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Thu, 9 Jan 2003 18:28:01 +0000 (18:28 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Thu, 9 Jan 2003 18:28:01 +0000 (18:28 +0000)
resizes to the remote end.

git-svn-id: svn://svn.tartarus.org/sgt/putty@2515 cda61777-01e9-0310-a592-d414129be87e

Recipe
unix/uxplink.c

diff --git a/Recipe b/Recipe
index 3569fbe..e3443c0 100644 (file)
--- a/Recipe
+++ b/Recipe
@@ -145,7 +145,7 @@ puttygen : [G] puttygen sshrsag sshdssg sshprime sshdes sshbn sshmd5 version
 pterm    : [X] pterm terminal wcwidth uxucs uxmisc tree234 misc ldisc ldiscucs
          + logging uxprint settings pty be_none uxstore signal CHARSET
 
-plink    : [U] uxplink uxcons NONSSH UXSSH be_all logging UXMISC
+plink    : [U] uxplink uxcons NONSSH UXSSH be_all logging UXMISC signal
 
 PuTTY    : [M] terminal wcwidth ldiscucs logging be_all mac macdlg
          + macterm macucs mac_res.rsrc testback NONSSH MACSSH MACMISC CHARSET
index a005ce6..96d3f18 100644 (file)
@@ -4,8 +4,10 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <errno.h>
 #include <assert.h>
 #include <stdarg.h>
+#include <signal.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <termios.h>
@@ -208,6 +210,13 @@ int from_backend(void *frontend_handle, int is_stderr, char *data, int len)
     return osize + esize;
 }
 
+int signalpipe[2];
+
+void sigwinch(int signum)
+{
+    write(signalpipe[1], "x", 1);
+}
+
 /*
  * Short description of parameters.
  */
@@ -520,6 +529,15 @@ int main(int argc, char **argv)
     if (portnumber != -1)
        cfg.port = portnumber;
 
+    /*
+     * Set up the pipe we'll use to tell us about SIGWINCH.
+     */
+    if (pipe(signalpipe) < 0) {
+       perror("pipe");
+       exit(1);
+    }
+    putty_signal(SIGWINCH, sigwinch);
+
     sk_init();
 
     /*
@@ -565,6 +583,8 @@ int main(int argc, char **argv)
        FD_ZERO(&xset);
        maxfd = 0;
 
+       FD_SET_MAX(signalpipe[0], maxfd, rset);
+
        if (connopen && !sending &&
            back->socket(backhandle) != NULL &&
            back->sendok(backhandle) &&
@@ -610,7 +630,9 @@ int main(int argc, char **argv)
                FD_SET_MAX(socket, maxfd, xset);
        }
 
-       ret = select(maxfd, &rset, &wset, &xset, NULL);
+       do {
+           ret = select(maxfd, &rset, &wset, &xset, NULL);
+       } while (ret < 0 && errno == EINTR);
 
        if (ret < 0) {
            perror("select");
@@ -632,6 +654,14 @@ int main(int argc, char **argv)
                select_result(socket, 2);
        }
 
+       if (FD_ISSET(signalpipe[0], &rset)) {
+           char c[1];
+           struct winsize size;
+           read(signalpipe[0], c, 1); /* ignore its value; it'll be `x' */
+           if (ioctl(0, TIOCGWINSZ, (void *)&size) >= 0)
+               back->size(backhandle, size.ws_col, size.ws_row);
+       }
+
        if (FD_ISSET(0, &rset)) {
            char buf[4096];
            int ret;