comgt: Use TCGETS and TCSETS ioctls for struct termios
[openwrt/svn-archive/archive.git] / package / network / utils / comgt / patches / 004-check_tty.patch
1 --- a/comgt.c
2 +++ b/comgt.c
3 @@ -91,6 +91,7 @@ unsigned long hstart,hset;
4 char NullString[]={ "" };
5 BOOL lastcharnl=1; /* Indicate that last char printed from getonebyte
6 was a nl, so no new one is needed */
7 +BOOL tty=1;
8
9
10 //"open com \"/dev/modem\"\nset com 38400n81\nset senddelay 0.05\nsend \"ATi^m\"\nget 2 \" ^m\" $s\nprint \"Response : \",$s,\"\\n\"\nget 2 \" ^m\" $s\nprint \"Response :\",$s,\"\\n\"\nget 2 \" ^m\" $s\nprint \"Response : \",$s,\"\\n\"\n\n";
11 @@ -920,7 +921,7 @@ BOOL getonoroff(void) {
12 void setcom(void) {
13 stbuf.c_cflag &= ~(CBAUD | CSIZE | CSTOPB | CLOCAL | PARENB);
14 stbuf.c_cflag |= (speed | bits | CREAD | clocal | parity | stopbits );
15 - if (ioctl(comfd, TCSETS, &stbuf) < 0) {
16 + if (tty && ioctl(comfd, TCSETS, &stbuf) < 0) {
17 serror("Can't ioctl set device",1);
18 }
19 }
20 @@ -1224,7 +1225,7 @@ void doclose(void) {
21 if(strcmp(token,"hardcom")==0) {
22 if(comfd== -1) serror("Com device not open",1);
23 vmsg("Closing device");
24 - if (ioctl(comfd, TCSETS, &svbuf) < 0) {
25 + if (tty && ioctl(comfd, TCSETS, &svbuf) < 0) {
26 sprintf(msg,"Can't ioctl set device %s.\n",device);
27 serror(msg,1);
28 }
29 @@ -1266,12 +1267,17 @@ void opengt(void) {
30 ext(1);
31 }
32 }
33 - if (ioctl (comfd, TCGETS, &svbuf) < 0) {
34 + if (isatty (comfd))
35 + tty=1;
36 + else
37 + tty=0;
38 + if (tty && ioctl (comfd, TCGETS, &svbuf) < 0) {
39 sprintf(msg,"Can't control %s, please try again.\n",device);
40 serror(msg,1);
41 }
42 setenv("COMGTDEVICE",device,1);
43 - ioctl(comfd, TCGETS, &stbuf);
44 + if (tty)
45 + ioctl(comfd, TCGETS, &stbuf);
46 speed=stbuf.c_cflag & CBAUD;
47 if (high_speed == 0) strcpy(cspeed,"115200");
48 else strcpy(cspeed,"57600");
49 @@ -1302,12 +1308,16 @@ void opendevice(void) {
50 }
51 }
52 else comfd=0;
53 -
54 - if (ioctl (comfd, TCGETS, &svbuf) < 0) {
55 + if (isatty (comfd))
56 + tty=1;
57 + else
58 + tty=0;
59 + if (tty && ioctl (comfd, TCGETS, &svbuf) < 0) {
60 sprintf(msg,"Can't ioctl get device %s.\n",device);
61 serror(msg,1);
62 }
63 - ioctl(comfd, TCGETS, &stbuf);
64 + if (tty)
65 + ioctl(comfd, TCGETS, &stbuf);
66 speed=stbuf.c_cflag & CBAUD;
67 switch(speed) {
68 case B0: strcpy(cspeed,"0");break;