summaryrefslogtreecommitdiff
path: root/comms/xtel/patches/patch-af
blob: c4b24aa5a2370af7225c8cc5733ea07407487932 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
$NetBSD: patch-af,v 1.1.1.1 2002/01/12 18:34:56 bouyer Exp $

--- modem.c.orig	Tue Feb 13 10:39:23 2001
+++ modem.c	Sat Jan 12 19:27:52 2002
@@ -32,7 +32,6 @@
 #include <sgtty.h>
 #else
 #ifdef USE_TERMIOS
-#include <sys/ioctl.h>
 #include <termios.h>
 #else
 #include <termio.h>
@@ -44,6 +43,11 @@
 #ifdef USE_SYSLOG
 #include <syslog.h>
 #endif /* USE_SYSLOG */
+#ifdef __STDC__
+#include <stdarg.h>
+#else
+#include <varargs.h>
+#endif
 
 #include "demon.h"
 #include "globald.h"
@@ -87,55 +91,56 @@
 #endif
 }
 
-/* Syslog or not syslog ? */
-#ifdef USE_SYSLOG
-void log_debug (fmt, p1, p2, p3, p4, p5, p6, p7)
-char *fmt;
-int  p1, p2, p3, p4, p5, p6, p7;
-{
-    char msg[256];
-
-    sprintf (msg, fmt, p1, p2, p3, p4, p5, p6, p7);
-    syslog (LOG_INFO, msg);
-}
-
-void log_err (s)
-char *s;
-{
-    syslog (LOG_ERR, s);
-}
+#ifdef __STDC__
+void log_debug(const char *fmt, ...)
 #else
-void log_debug (fmt, p1, p2, p3, p4, p5, p6, p7)
-char *fmt;
-int  p1, p2, p3, p4, p5, p6, p7;
+void log_debug(va_alist)
+    va_dcl
+#endif
 {
+    va_list ap;
+#ifdef __STDC__
+    va_start(ap, fmt);
+#else
+    const char *fmt;
+    va_start(ap);
+    fmt = va_arg(ap, const char *);
+#endif
+#ifdef USE_SYSLOG
+    vsyslog(LOG_INFO, fmt, ap);
+#else
     fprintf (fp_console, "%s[%d] ", prefix, getpid());
-    fprintf (fp_console, fmt, p1, p2, p3, p4, p5, p6, p7);
+    vfprintf (fp_console, fmt, ap);
     fprintf (fp_console, "\n\r");
+#endif
+    va_end(ap);
 }
 
-void log_err (s)
-char *s;
+#ifdef __STDC__
+void log_err(const char *fmt, ...)
+#else
+void log_err(va_alist)
+    va_dcl
+#endif
 {
+    va_list ap;
+#ifdef __STDC__
+    va_start(ap, fmt);
+#else
+    const char *fmt;
+    va_start(ap);
+    fmt = va_arg(ap, const char *);
+#endif
+#ifdef USE_SYSLOG
+    vsyslog(LOG_ERR, fmt, ap);
+#else
     fprintf (fp_console, "%s[%d] ", prefix, getpid());
-
-    while (*s) {
-      if (*s != '%')
-	fputc (*s, fp_console);
-      else if (*(s+1) == 'm') {
-	fprintf (fp_console, "%s", sys_errlist[errno]);
-	s++;
-      }
-
-      s++;
-    }
-
+    vfprintf (fp_console, fmt, ap);
     fprintf (fp_console, "\n\r");
+#endif
+    va_end(ap);
 }
 
-#endif /* USE_SYSLOG */
-
-
 /*  Envoi d'une commande MODEM */
 static void writemodem (fd, buf, n)
 int fd;
@@ -165,8 +170,10 @@
 #else
 
 #ifdef USE_TERMIOS
-  ioctl (fd, TIOCGETA, &term);
-  memcpy ((char *)&term_sauve, (char *)&term, sizeof(struct termios));
+  if (tcgetattr(fd, &term) < 0) {
+	log_err("tcgetattr: %s", strerror(errno));
+	exit(1);
+  }
 #else
   ioctl (fd, TCGETA, &term);
   memcpy ((char *)&term_sauve, (char *)&term, sizeof(struct termio));
@@ -174,11 +181,21 @@
 	
   /* Parametrage de la ligne */
   term.c_cc[VMIN] = 1;
+#ifdef __NetBSD__
+  term.c_cc[VTIME] = term.c_cc[VKILL] = term.c_cc[VERASE] = 0;
+  term.c_iflag = IGNBRK | IGNPAR;
+  term.c_oflag = term.c_lflag = 0;
+#else
   term.c_cc[VTIME] = 0;
   term.c_iflag &= ~(IXON|IXOFF|ICRNL);
   term.c_lflag &= ~(ICANON|ISIG|ECHO|IEXTEN);
+#endif
 
 #ifdef USE_TERMIOS
+#ifdef __NetBSD__
+  term.c_cflag = (CREAD | HUPCL | CRTSCTS);
+  cfsetspeed( &term, speed);
+#else
   /*
    * FreeBSD 1.1 (Beta) n'a pas l'air d'apprecier qu'on mette clocal
    * a 0... (blocage au premier write sur /dev/cua01)
@@ -186,6 +203,7 @@
   term.c_cflag &= ~(CSIZE|CSTOPB);
   term.c_cflag |= (CREAD|HUPCL);
   term.c_ispeed = term.c_ospeed = speed;
+#endif /*  __NetBSD__ */
 #else
   term.c_cflag &= ~(CSIZE|CBAUD|CLOCAL);
 
@@ -223,10 +241,12 @@
 #endif /* sun */
 
 #ifdef USE_TERMIOS
+#ifndef __NetBSD__
   term.c_iflag &= ~(IGNCR|ICRNL|INLCR|IMAXBEL);
   term.c_iflag |= (ISTRIP|INPCK);
   term.c_lflag &= ~(ECHOCTL|IEXTEN);
   term.c_oflag &= ~OPOST;
+#endif /* __NetBSD__ */
 #endif /* USE_TERMIOS */
 
   /* Cas du Minitel 1/2 */
@@ -235,7 +255,10 @@
 
   /* Affectation des parametres */
 #ifdef USE_TERMIOS
-  ioctl (fd, TIOCSETA, &term);
+  if (tcsetattr (fd, TCSANOW, &term) < 0) {
+	log_err("tcsetattr(1):%s", strerror(errno));
+	exit(1);
+  }
 #else
   ioctl (fd, TCSETA, &term);
 #endif /* USE_TERMIOS */
@@ -256,10 +279,11 @@
   ioctl (fd, TIOCSETP, &term_sauve);
 #else
 #ifdef USE_TERMIOS
-  term.c_ispeed = B0;
-  term.c_ospeed = B0;
-  ioctl (fd, TIOCSETAW, &term);
-  ioctl (fd, TIOCSETA, &term_sauve);
+  cfsetspeed(&term_sauve, B0);
+  if (tcsetattr (fd, TCSADRAIN, &term_sauve) < 0) {
+	log_err("tcsetattr(2):%s", strerror(errno));
+	exit(1);
+  }
 #else
   term.c_cflag &= ~CBAUD;
   term.c_cflag |= B0;
@@ -285,7 +309,7 @@
 int reply_size;
 {
     fd_set a_lire, t_a_lire;
-    int i, erreur, fin, nbread, cmodem;
+    int i, erreur, fin, nbread, cmodem = 0;
     char *pt_chat, c, *q;
 
     delai_maxi.tv_sec = tmax;
@@ -307,14 +331,20 @@
      *  (comme le Hayes Optima par exemple)...
      */
 #ifdef USE_TERMIOS
-    ioctl (fd, TCIOCGETA, &term);
+    if (tcgetattr(fd, &term) < 0) {
+	log_err("tcgetattr: %s", strerror(errno));
+	exit(1);
+    }
 #else
     ioctl (fd, TCGETA, &term);
 #endif /* USE_TERMIOS */
-    if ((term.c_cflag | CLOCAL) == 0) {
+    if ((term.c_cflag & CLOCAL) == 0) {
 	term.c_cflag |= CLOCAL;
 #ifdef USE_TERMIOS
-	ioctl (fd, TCIOCSETA, &term);
+	if (tcsetattr (fd, TCSANOW, &term) < 0) {
+		log_err("tcsetattr(3):%s", strerror(errno));
+		exit(1);
+	}
 #else
 	ioctl (fd, TCSETA, &term);
 #endif /* USE_TERMIOS */
@@ -586,13 +616,17 @@
 	fin = ((erreur != 0 || *(pt_chat-1) == 0) ? 1 : 0);
 	usleep (30000);
     }
+    sleep(3);
 
 #ifndef NO_TERMIO
     /* Repasse en controle modem */
     if (cmodem) {
 	term.c_cflag &= ~CLOCAL;
 #ifdef USE_TERMIOS
-	ioctl (fd, TCIOCSETA, &term);
+	if (tcsetattr (fd, TCSANOW, &term) < 0) {
+		log_err("tcsetattr(4):%s", strerror(errno));
+		exit(1);
+	}
 #else
 	ioctl (fd, TCSETA, &term);
 #endif /* USE_TERMIOS */