[gpm] [PATCH 16/18] remove-pts-console.patch

Dmitry Torokhov dtor_core@ameritech.net
Tue Aug 10 09:02:16 CEST 2004


===================================================================


ChangeSet@1.20, 2004-08-10 00:53:58-05:00, dtor_core@ameritech.net
  Remove GPM_PTS_CONSOLE and have Gpm_Open simply return -1 if local
  console (/dev/ttyX or /dev/vc/X) is not accessible and client is not
  running inside xterm.
  
  GPM services are only available locally, TIOCLINUX is not valid on
  /dev/pts/X and using it will cause GPM (server) to oops.


 headers/gpmInt.h |    1 
 lib/liblow.c     |   49 +++++++++++++++++++++++++-----------------------
 tools.c          |   56 +++++++++++++++++++------------------------------------
 3 files changed, 46 insertions(+), 60 deletions(-)


===================================================================



diff -Nru a/src/headers/gpmInt.h b/src/headers/gpmInt.h
--- a/src/headers/gpmInt.h	2004-08-10 01:18:01 -05:00
+++ b/src/headers/gpmInt.h	2004-08-10 01:18:01 -05:00
@@ -68,7 +68,6 @@
 #define GPM_NULL_DEV         "/dev/null"
 #define GPM_SYS_CONSOLE      "/dev/console"
 #define GPM_DEVFS_CONSOLE    "/dev/vc/0"
-#define GPM_PTS_CONSOLE      "/dev/pts/0"
 #define GPM_OLD_CONSOLE      "/dev/tty0"
 
 /*** mouse commands ***/ 
diff -Nru a/src/lib/liblow.c b/src/lib/liblow.c
--- a/src/lib/liblow.c	2004-08-10 01:18:01 -05:00
+++ b/src/lib/liblow.c	2004-08-10 01:18:01 -05:00
@@ -80,8 +80,6 @@
 int gpm_consolefd=-1;  /* used to invoke ioctl() */
 int gpm_morekeys=0;
 
-static char *consolename;
-
 int gpm_convert_event(unsigned char *mdata, Gpm_Event *ePtr);
 
 /*----------------------------------------------------------------------------*
@@ -191,10 +189,12 @@
  *----------------------------------------------------------------------------*/
 int Gpm_Open(Gpm_Connect *conn, int flag)
 {
+   static char *console_name;
+   static int console_queried;
+
    char *tty = NULL;
    char *term = NULL;
    int i;
-   static int checked_con = 0;
    struct sockaddr_un addr;
    struct winsize win;
    Gpm_Stst *new = NULL;
@@ -214,10 +214,17 @@
    /*....................................... No xterm, go on */
 
    /* check whether we know what name the console is: what's with the lib??? */
-   if(checked_con == 0) {
-      consolename = Gpm_get_console();
-      checked_con++;
-   }   
+   if (!console_queried) {
+      console_name = Gpm_get_console();
+      console_queried = 1;
+   }
+
+   /*
+    * If console is not set just bail out - GPM is not available unless
+    * client is running on local console
+    */
+   if (!console_name)
+      return -1;
 
    /*
     * So I chose to use the current tty, instead of /dev/console, which
@@ -236,38 +243,34 @@
    new->next=gpm_stack;
    gpm_stack=new;
 
-   conn->pid=getpid(); /* fill obvious values */
+   conn->pid =getpid(); /* fill obvious values */
 
    if (new->next)
       conn->vc=new->next->info.vc; /* inherit */
    else {
-      if (consolename) {
-         gpm_report(GPM_PR_ERR, "consolename is null");
-         goto err;
-      }
       conn->vc=0;                 /* default handler */
       if (flag > 0) {  /* forced vc number */
          conn->vc=flag;
-         if((tty = malloc(strlen(consolename)+Gpm_cnt_digits(flag))) == NULL)
-            gpm_report(GPM_PR_OOPS,GPM_MESS_NO_MEM);
-         memcpy(tty,consolename,strlen(consolename)-1);
-         sprintf(&tty[strlen(consolename)-1],"%i",flag);
-      } else { /* use your current vc */ 
+         if ((tty = malloc(strlen(console_name) + Gpm_cnt_digits(flag))) == NULL)
+            gpm_report(GPM_PR_OOPS, GPM_MESS_NO_MEM);
+         memcpy(tty, console_name, strlen(console_name)-1);
+         sprintf(&tty[strlen(console_name) - 1], "%i", flag);
+      } else { /* use your current vc */
          if (isatty(0)) tty = ttyname(0);             /* stdin */
          if (!tty && isatty(1)) tty = ttyname(1);     /* stdout */
          if (!tty && isatty(2)) tty = ttyname(2);     /* stderr */
          if (tty == NULL) {
             gpm_report(GPM_PR_ERR,"checking tty name failed");
             goto err;
-         }   
+         }
          /* do we really need this check ? */
-         if(strncmp(tty,consolename,strlen(consolename)-1)
-            || !isdigit(tty[strlen(consolename)-1])) {
-            gpm_report(GPM_PR_ERR,"strncmp/isdigit/consolename failed");
+         if (strncmp(tty, console_name, strlen(console_name) - 1)
+            || !isdigit(tty[strlen(console_name) - 1])) {
+            gpm_report(GPM_PR_ERR, "strncmp/isdigit/consolename failed");
             goto err;
          }
-          
-         conn->vc=atoi(&tty[strlen(consolename)-1]);
+
+         conn->vc = atoi(&tty[strlen(console_name) - 1]);
       }
 
       if (gpm_consolefd == -1)
diff -Nru a/src/tools.c b/src/tools.c
--- a/src/tools.c	2004-08-10 01:18:01 -05:00
+++ b/src/tools.c	2004-08-10 01:18:01 -05:00
@@ -26,55 +26,44 @@
 #include <unistd.h>     /* stat() */
 
 #include "headers/gpmInt.h"   /* only used for some defines */
-#include "headers/message.h"
 
 /*****************************************************************************
  * check, whether devfs is used or not.
  * See /usr/src/linux/Documentation/filesystems/devfs/ for details.
  * Returns: the name of the console (/dev/tty0 or /dev/vc/0)
  *****************************************************************************/
-char *Gpm_get_console( void )
+char *Gpm_get_console(void)
 {
-
-   char *back = NULL, *tmp = NULL;
    struct stat buf;
 
    /* first try the devfs device, because in the next time this will be
     * the preferred one. If that fails, take the old console */
-   
+
    /* Check for open new console */
-   if (stat(GPM_DEVFS_CONSOLE,&buf) == 0)
-      tmp = GPM_DEVFS_CONSOLE;
-  
-   /* May it be that we are on the network console? */
-   else if(stat(GPM_PTS_CONSOLE,&buf) == 0)
-      tmp = GPM_PTS_CONSOLE;
-  
+   if (stat(GPM_DEVFS_CONSOLE, &buf) == 0)
+      return strdup(GPM_DEVFS_CONSOLE);
+
    /* Failed, try OLD console */
-   else if(stat(GPM_OLD_CONSOLE,&buf) == 0)
-      tmp = GPM_OLD_CONSOLE;
-  
-   if(tmp != NULL)
-      if((back = malloc(strlen(tmp) + sizeof(char)) ) != NULL)
-         strcpy(back,tmp);
+   else if (stat(GPM_OLD_CONSOLE, &buf) == 0)
+      return strdup(GPM_OLD_CONSOLE);
 
-   return(back);
+   return NULL;
 }
 
 /* what's the english name for potenz ? */
 int Gpm_x_high_y(int base, int pot_y)
 {
    int val = 1;
-   
-   if(pot_y == 0) val = 1;
-   else if(pot_y  < 0) val = 0;     /* ugly hack ;) */
+
+   if (pot_y == 0) val = 1;
+   else if (pot_y  < 0) val = 0;     /* ugly hack ;) */
    else while(pot_y > 0) {
       val = val * base;
       pot_y--;
-   }   
+   }
    return val;
-}   
-      
+}
+
 /* return characters needed to display int */
 int Gpm_cnt_digits(int number)
 {
@@ -82,16 +71,11 @@
     * 10 - 99 = 2    10^1 <-> (10^2)-1
     * 100 - 999 = 3  10^2 <-> (10^3)-1
     * 1000 - 9999 = 4 ...  */
-   
-   int ret = 0, num = 0;
 
-   /* non negative, please */
-   if(number < 0) number *= -1;
-   else if(number == 0) ret = 1;
-   else while(number > num) {
-      ret++;
-      num = (Gpm_x_high_y(10,ret) - 1);
-   }   
+   int digits = 1;
 
-   return(ret);
-}      
+   while ((number /= 10))
+      digits++;
+
+   return digits;
+}


More information about the gpm mailing list