aboutsummaryrefslogtreecommitdiffstats
path: root/package/network/utils/comgt/patches/004-check_tty.patch
blob: fb1d9af4bb1699d72a3ba1d535e00b797bcd6498 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
--- a/comgt.c
+++ b/comgt.c
@@ -91,6 +91,7 @@ unsigned long hstart,hset;
 char NullString[]={ "" };
 BOOL lastcharnl=1; /* Indicate that last char printed from getonebyte
                                was a nl, so no new one is needed */
+BOOL tty=1;
 
 
 //"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";
@@ -920,7 +921,7 @@ 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, TCSETS, &stbuf) < 0) {
+  if (tty && ioctl(comfd, TCSETS, &stbuf) < 0) {
     serror("Can't ioctl set device",1);
   }
 }
@@ -1224,7 +1225,7 @@ void doclose(void) {
   if(strcmp(token,"hardcom")==0) {
     if(comfd== -1) serror("Com device not open",1);
     vmsg("Closing device");
-    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);
     }
@@ -1266,12 +1267,17 @@ void opengt(void) {
       ext(1);
     }
   }
-  if (ioctl (comfd, TCGETS, &svbuf) < 0) {
+  if (isatty (comfd))
+    tty=1;
+  else
+    tty=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, TCGETS, &stbuf);
+  if (tty)
+    ioctl(comfd, TCGETS, &stbuf);
   speed=stbuf.c_cflag & CBAUD;
   if (high_speed == 0)  strcpy(cspeed,"115200");
   else strcpy(cspeed,"57600");
@@ -1302,12 +1308,16 @@ void opendevice(void) {
     }
   }
   else comfd=0;
-
-  if (ioctl (comfd, TCGETS, &svbuf) < 0) {
+  if (isatty (comfd))
+    tty=1;
+  else
+    tty=0;
+  if (tty && ioctl (comfd, TCGETS, &svbuf) < 0) {
     sprintf(msg,"Can't ioctl get device %s.\n",device);
     serror(msg,1);
   }
-  ioctl(comfd, TCGETS, &stbuf);
+  if (tty)
+    ioctl(comfd, TCGETS, &stbuf);
   speed=stbuf.c_cflag & CBAUD;
   switch(speed) {
     case B0: strcpy(cspeed,"0");break;