comgt: Use TCGETS and TCSETS ioctls for struct termios
authorblogic <blogic@3c298f89-4303-0410-b956-a3cf2f4a3e73>
Sun, 22 Feb 2015 08:29:26 +0000 (08:29 +0000)
committerblogic <blogic@3c298f89-4303-0410-b956-a3cf2f4a3e73>
Sun, 22 Feb 2015 08:29:26 +0000 (08:29 +0000)
When passing struct termios to ioctl TCGETS and TCSETS should be
used instead of TCGETA and TCSETA, which are meant for the older
struct termio. Should fix https://dev.openwrt.org/ticket/19012

Signed-off-by: Matti Laakso <malaakso@elisanet.fi>
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@44506 3c298f89-4303-0410-b956-a3cf2f4a3e73

package/network/utils/comgt/Makefile
package/network/utils/comgt/patches/002-termios.patch
package/network/utils/comgt/patches/004-check_tty.patch

index 500365a..8fcf54e 100644 (file)
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=comgt
 PKG_VERSION:=0.32
-PKG_RELEASE:=24
+PKG_RELEASE:=25
 
 PKG_SOURCE:=$(PKG_NAME).$(PKG_VERSION).tgz
 PKG_SOURCE_URL:=@SF/comgt
index 3649f3c..08f22d1 100644 (file)
  int comfd=0; /* Communication file descriptor.  Defaults to stdin. */
  char msg[STRINGL]; /* Massage messages here */
  int preturn,returns[MAXGOSUBS];
-@@ -926,7 +926,7 @@ void setcom(void) {
+@@ -172,7 +172,7 @@ void dotestkey(void) {
+ /* Exit after resetting terminal settings */
+ void ext(long xtc) {
+-  ioctl(1, TCSETA, &cons);
++  ioctl(1, TCSETS, &cons);
+   exit(xtc);
+ }
+@@ -920,24 +920,24 @@ BOOL getonoroff(void) {
+ void setcom(void) {
+   stbuf.c_cflag &= ~(CBAUD | CSIZE | CSTOPB | CLOCAL | PARENB);
+   stbuf.c_cflag |= (speed | bits | CREAD | clocal | parity | stopbits );
+-  if (ioctl(comfd, TCSETA, &stbuf) < 0) {
++  if (ioctl(comfd, TCSETS, &stbuf) < 0) {
+     serror("Can't ioctl set device",1);
+   }
  }
  
  void doset(void) {
    int a,b;
    gettoken();
    if(strcmp(token,"echo")==0) {
+     a=0;
+     if(getonoroff()) a=ECHO|ECHOE;
+-    if(ioctl(0, TCGETA, &console)<0) {
++    if(ioctl(0, TCGETS, &console)<0) {
+       serror("Can't ioctl FD zero!\n",2);
+     }
+     console.c_lflag &= ~(ECHO | ECHOE);
+     console.c_lflag |= a;
+-    ioctl(0, TCSETA, &console);
++    ioctl(0, TCSETS, &console);
+   }
+   else if(strcmp(token,"senddelay")==0) {
+     senddelay=10000L*getdvalue();
+@@ -1224,7 +1224,7 @@ void doclose(void) {
+   if(strcmp(token,"hardcom")==0) {
+     if(comfd== -1) serror("Com device not open",1);
+     vmsg("Closing device");
+-    if (ioctl(comfd, TCSETA, &svbuf) < 0) {
++    if (ioctl(comfd, TCSETS, &svbuf) < 0) {
+       sprintf(msg,"Can't ioctl set device %s.\n",device);
+       serror(msg,1);
+     }
+@@ -1266,12 +1266,12 @@ void opengt(void) {
+       ext(1);
+     }
+   }
+-  if (ioctl (comfd, TCGETA, &svbuf) < 0) {
++  if (ioctl (comfd, TCGETS, &svbuf) < 0) {
+     sprintf(msg,"Can't control %s, please try again.\n",device);
+     serror(msg,1);
+   }
+   setenv("COMGTDEVICE",device,1);
+-  ioctl(comfd, TCGETA, &stbuf);
++  ioctl(comfd, TCGETS, &stbuf);
+   speed=stbuf.c_cflag & CBAUD;
+   if (high_speed == 0)  strcpy(cspeed,"115200");
+   else strcpy(cspeed,"57600");
+@@ -1303,11 +1303,11 @@ void opendevice(void) {
+   }
+   else comfd=0;
+-  if (ioctl (comfd, TCGETA, &svbuf) < 0) {
++  if (ioctl (comfd, TCGETS, &svbuf) < 0) {
+     sprintf(msg,"Can't ioctl get device %s.\n",device);
+     serror(msg,1);
+   }
+-  ioctl(comfd, TCGETA, &stbuf);
++  ioctl(comfd, TCGETS, &stbuf);
+   speed=stbuf.c_cflag & CBAUD;
+   switch(speed) {
+     case B0: strcpy(cspeed,"0");break;
+@@ -1553,7 +1553,7 @@ int main(int argc,char **argv) {
+   skip_default=0;
+   filep=NULL;
+   scriptspace=4096;
+-  ioctl(1, TCGETA, &cons);
++  ioctl(1, TCGETS, &cons);
+   if((script=( char *)malloc(scriptspace))==NULL) {
+     serror("Could not malloc()",3);
+   }
index b81b051..fb1d9af 100644 (file)
@@ -12,8 +12,8 @@
  void setcom(void) {
    stbuf.c_cflag &= ~(CBAUD | CSIZE | CSTOPB | CLOCAL | PARENB);
    stbuf.c_cflag |= (speed | bits | CREAD | clocal | parity | stopbits );
--  if (ioctl(comfd, TCSETA, &stbuf) < 0) {
-+  if (tty && ioctl(comfd, TCSETA, &stbuf) < 0) {
+-  if (ioctl(comfd, TCSETS, &stbuf) < 0) {
++  if (tty && ioctl(comfd, TCSETS, &stbuf) < 0) {
      serror("Can't ioctl set device",1);
    }
  }
@@ -21,8 +21,8 @@
    if(strcmp(token,"hardcom")==0) {
      if(comfd== -1) serror("Com device not open",1);
      vmsg("Closing device");
--    if (ioctl(comfd, TCSETA, &svbuf) < 0) {
-+    if (tty && ioctl(comfd, TCSETA, &svbuf) < 0) {
+-    if (ioctl(comfd, TCSETS, &svbuf) < 0) {
++    if (tty && ioctl(comfd, TCSETS, &svbuf) < 0) {
        sprintf(msg,"Can't ioctl set device %s.\n",device);
        serror(msg,1);
      }
        ext(1);
      }
    }
--  if (ioctl (comfd, TCGETA, &svbuf) < 0) {
+-  if (ioctl (comfd, TCGETS, &svbuf) < 0) {
 +  if (isatty (comfd))
 +    tty=1;
 +  else
 +    tty=0;
-+  if (tty && ioctl (comfd, TCGETA, &svbuf) < 0) {
++  if (tty && ioctl (comfd, TCGETS, &svbuf) < 0) {
      sprintf(msg,"Can't control %s, please try again.\n",device);
      serror(msg,1);
    }
    setenv("COMGTDEVICE",device,1);
--  ioctl(comfd, TCGETA, &stbuf);
+-  ioctl(comfd, TCGETS, &stbuf);
 +  if (tty)
-+    ioctl(comfd, TCGETA, &stbuf);
++    ioctl(comfd, TCGETS, &stbuf);
    speed=stbuf.c_cflag & CBAUD;
    if (high_speed == 0)  strcpy(cspeed,"115200");
    else strcpy(cspeed,"57600");
    }
    else comfd=0;
 -
--  if (ioctl (comfd, TCGETA, &svbuf) < 0) {
+-  if (ioctl (comfd, TCGETS, &svbuf) < 0) {
 +  if (isatty (comfd))
 +    tty=1;
 +  else
 +    tty=0;
-+  if (tty && ioctl (comfd, TCGETA, &svbuf) < 0) {
++  if (tty && ioctl (comfd, TCGETS, &svbuf) < 0) {
      sprintf(msg,"Can't ioctl get device %s.\n",device);
      serror(msg,1);
    }
--  ioctl(comfd, TCGETA, &stbuf);
+-  ioctl(comfd, TCGETS, &stbuf);
 +  if (tty)
-+    ioctl(comfd, TCGETA, &stbuf);
++    ioctl(comfd, TCGETS, &stbuf);
    speed=stbuf.c_cflag & CBAUD;
    switch(speed) {
      case B0: strcpy(cspeed,"0");break;