LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Desktop (https://www.linuxquestions.org/questions/linux-desktop-74/)
-   -   shell not resizing window (https://www.linuxquestions.org/questions/linux-desktop-74/shell-not-resizing-window-600990/)

cormander 11-19-2007 09:48 PM

shell not resizing window
 
I downloaded / installed a shell wrapper program called 'rootsh':

http://sourceforge.net/projects/rootsh/

When I resize the window, rootsh doesn't properly handle things. From what I can tell by doing google searches, a window resize sends the SIGWINCH to the process.

Looking at the C code of rootsh, there's no handle for this signal. But I did find where it appears to be seeting the window characteristics when it launches the slave pty:

Code:

  if (winp == NULL) {
    ioctl(STDIN_FILENO, TIOCGWINSZ, (char *)&currentwinsize);
    winp->ws_row = currentwinsize.ws_row;
    winp->ws_col = currentwinsize.ws_col;
    winp->ws_xpixel = currentwinsize.ws_xpixel;
    winp->ws_ypixel = currentwinsize.ws_ypixel;
  }

I was wondering if anyone knew how to make the appropriate changes to this code so that when a SIGWINCH is recieved, it makes corrections to window sizes?

The main thing that buggs me about this is when I open a window, and then resize it to be bigger, and launch an editor (such as emacs or vi) the area of the editor is small (the origonal window size).

If anyone has any insight into this, please help!

Thanks

gilead 11-19-2007 10:29 PM

I haven't used rootsh, so this may not help - but I use the checkwinsize option for bash. You can set it with shopt -s checkwinsize either at the prompt or in your ~/.bashrc file. When it's set, bash checks the window size after each command and, if necessary, updates the values of LINES and COLUMNS.

cormander 11-19-2007 11:13 PM

That doesn't seem to work in this case.

cormander 11-22-2007 12:51 PM

Figured it out, if this helps anyone who has similiar problems. I got the logic flow from reading the source code of the bash shell, and was able to simplify it a bit for this case:

Code:

--- ../src_rpm/orig/rootsh-1.5.2/src/rootsh.c  2005-03-24 06:08:20.000000000 -0700
+++ rootsh-1.5.2/src/rootsh.c  2007-11-21 23:34:39.000000000 -0700
@@ -84,6 +84,7 @@
 char *setupshell(void);
 int setupusermode(void);
 void finish(int);
+void handle_sig_winch(int);
 int beginlogging(void);
 void dologging(char *, int);
 void endlogging(void);
@@ -179,6 +180,8 @@
 extern char **environ;
 extern int errno;
 
+volatile sig_atomic_t sigwinch_received;
+
 static char progName[MAXPATHLEN];
 static char sessionId[MAXPATHLEN + 11];
 static int logFile;
@@ -413,6 +416,9 @@
    signal(SIGINT, finish);
    signal(SIGQUIT, finish);
 #endif
+    signal(SIGWINCH, handle_sig_winch);
+    sigwinch_received = 0;
+
    newTty = termParams;
    /*
    //  Let read not return until at least 1 byte has been received.
@@ -458,11 +464,19 @@
      */
      n = select(masterPty + 1, &readmask, (fd_set *) 0, (fd_set *) 0,
        (struct timeval *) 0);
-      if (n < 0) {
+      if (n < 0 && sigwinch_received == 0) {
        perror("select");
        exit(EXIT_FAILURE);
      }
 
+      if(sigwinch_received) {
+      sigwinch_received = 0;
+      signal(SIGWINCH, handle_sig_winch);
+      ioctl(STDIN_FILENO, TIOCGWINSZ, (char *)&winSize);
+      ioctl(masterPty, TIOCSWINSZ, (char *)&winSize);
+      kill(childPid, SIGWINCH);
+      }
+
      /*
      //  The user typed something...
      //  Read it and pass it on to the pseudo-tty.
@@ -505,6 +519,11 @@
  exit(EXIT_SUCCESS);
 }
 
+void handle_sig_winch(int sig) {
+
+  sigwinch_received = 1;

+}
 
 /*
 //  Do some cleaning after the child exited.



All times are GMT -5. The time now is 09:18 AM.