File: debian-changes

package info (click to toggle)
xtel 3.3.0-30
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 4,140 kB
  • sloc: ansic: 15,773; sh: 224; makefile: 29
file content (1273 lines) | stat: -rw-r--r-- 38,558 bytes parent folder | download | duplicates (2)
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
diff --git a/README_IMINITEL.txt b/README_IMINITEL.txt
index 9f06964..4fb6765 100644
--- a/README_IMINITEL.txt
+++ b/README_IMINITEL.txt
@@ -38,7 +38,7 @@ connexion effective au service Minitel (le plus souvent par modem).
 
 Dans le cas de I-Minitel, la connexion au service est TCP/IP d'un bout 
 l'autre et la machine supportant xteld aura un role de routeur d'accs aux
-services I-Minitel. En particuliers:
+services I-Minitel. En particulier:
 
    * Le premier client xtel initialise la connexion PPP de xteld vers le
      serveur 3622. xteld mets alors en place la route vers le serveur
@@ -64,11 +64,12 @@ la connexion PPP. Ce script est localis
 xtel.services (rpertoire /usr/X11R6/lib/X11/xtel). Les fichiers de
 configuration pppd sont les suivants:
 
- /etc/ppp/ip-up.iminitel  Script d'initialisation de la route I-Minitel,
+ /etc/ppp/ip-up.d/iminitel  Script d'initialisation de la route I-Minitel,
                           excut  la connexion
 
- /etc/ppp/ip-down.iminitelScript excut lors de la coupure de connexion
+ /etc/ppp/ip-down.d/iminitel Script excut lors de la coupure de connexion
                           I-Minitel
+
                           Chat-script de composition, contient le numro
  /etc/ppp/chat-iminitel   d'appel 3622 et les caractristiques
                           de la connexion PPP (login/password)
diff --git a/config.c b/config.c
index 50cbfba..187e0fa 100644
--- a/config.c
+++ b/config.c
@@ -25,6 +25,7 @@ static char rcsid[] = "$Id: config.c,v 1.14 1998/10/16 08:49:01 pierre Exp $";
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <ctype.h>
 #ifdef USE_SYSLOG
 #include <syslog.h>
 #endif /* USE_SYSLOG */
@@ -205,7 +206,7 @@ lecture_configuration_lignes ()
 {	
     FILE *fp;
     register int i;
-    char *p, sep[2] = {0, 0};
+    char *p, sep[3] = {0, 0, 0};
 
     if ((fp = fopen (FICHIER_DEFINITION_LIGNES, "r")) == NULL) {
       sprintf (buf, "Erreur a l'ouverture du fichier %s", FICHIER_DEFINITION_LIGNES);
@@ -300,11 +301,27 @@ lecture_configuration_lignes ()
 	    definition_lignes[i].type_dialer = DIALER_MODEM;	    
 	}
 
-	definition_lignes[i].delai = atoi (next_token (NULL, "\n"));
+	/*
+	 * Ajoute NL  la liste des sparateurs pour autoriser une fin de ligne
+	 * aprs le champ dlai
+	 */
+	sep[1] = '\n';
+	definition_lignes[i].delai = atoi (next_token (NULL, sep));
 
-#ifdef DEBUG_XTELD1
+	/*
+	 * colonne 8 = tempo entre 2 ioctls (pour vieux modems)
+	 * 0 par dfaut, i.e. colonne non prsente.
+	 * saisie en millisecondes, stockage en microsecondes.
+	 */
+	p = next_token (NULL, "\n");
+	if (isdigit(*p))
+	    definition_lignes[i].tempo = atoi(p)*1000;
+	else
+	    definition_lignes[i].tempo = 0;
+
+#ifdef DEBUG_XTELD
 	if (!flag_old_config)
-	    log_debug ("LIGNES: %s %s %d %d %d >%s< %d", definition_lignes[i].device, definition_lignes[i].nom, definition_lignes[i].speed, definition_lignes[i].cs, definition_lignes[i].parity, definition_lignes[i].chat, definition_lignes[i].delai);
+	    log_debug ("LIGNES: %s %s %d %d %d >%s< %d (%d)", definition_lignes[i].device, definition_lignes[i].nom, definition_lignes[i].speed, definition_lignes[i].cs, definition_lignes[i].parity, definition_lignes[i].chat, definition_lignes[i].delai, definition_lignes[i].tempo);
 	else
 	    log_debug ("LIGNES: %s %s %d", definition_lignes[i].nom, definition_lignes[i].chat, definition_lignes[i].delai);
 #endif
diff --git a/demon.h b/demon.h
index 98acd1b..6759eb5 100644
--- a/demon.h
+++ b/demon.h
@@ -96,6 +96,7 @@ struct definition_ligne {
     char *chat;			/* chat-script */
     char type_dialer;		/* type du dialer */
     int delai;			/* timeout du dialogue Modem */
+    int tempo;			/* tempos entre ioctl (pour vieux modems) en s */
 };
 
 /*
@@ -132,8 +133,10 @@ struct definition_ligne {
 #endif /* NO_NETWORK */
 
 /* Fichier d'tat I-Minitel */
-#define IMINITEL_FILE            "/tmp/.iminitel"
+#define IMINITEL_FILE            "/var/run/iminitel"
 #define IMINITEL_TIMEOUT         45
+/* Fichier de lock de la session PPP I-Minitel */
+#define IMINITEL_LOCKFILE        "/var/run/ppp-iminitel.pid"
 
 /* Base /proc */
 #define PROC_BASE                "/proc"
diff --git a/dial.c b/dial.c
index b70e9ab..6b4d35c 100644
--- a/dial.c
+++ b/dial.c
@@ -58,6 +58,8 @@ static char rcsid[] = "$Id: dial.c,v 1.17 1998/10/02 15:00:49 pierre Exp $";
 static char nom_lck[256];
 extern char type_client;
 
+static int try_lock (char *lock_file);
+
 /*
  * fonction UNDIAL
  */
@@ -81,7 +83,7 @@ char *telno, *device;
 {
     char buf[80], erreur;
     struct stat statb;
-    int fdlck, fd;
+    int fd;
 
     for (numero_ligne = 0 ; numero_ligne != nb_lignes && definition_lignes[numero_ligne].type_dialer != DIALER_M1 ; numero_ligne++) 
 	;
@@ -96,7 +98,7 @@ char *telno, *device;
         /*
 	 * Recherche la premiere ligne non deja utilise par un programme UUCP
 	 */
-	for (;;) {
+	while (numero_ligne < nb_lignes) {
 #ifdef SVR4
 	    if (stat (definition_lignes[numero_ligne].nom, &statb) != 0) {
 		erreur_a_xtel ("mydial()", errno);
@@ -109,19 +111,9 @@ char *telno, *device;
 #ifdef DEBUG_XTELD
 	    log_debug( "ligne= %s, device= %s, lock= %s", definition_lignes[numero_ligne].nom, definition_lignes[numero_ligne].device, nom_lck);
 #endif
-	    /* Si le lock existe */
-	    if (stat (nom_lck, &statb) == 0) {
-		if (numero_ligne == nb_lignes-1) {
-		    /* Dommage, c'etait la derniere :-( */
-		    erreur_a_xtel ("[0] Aucun MODEM disponible !", 0);
-		    return (-1);
-		}
-	    }
-	    else {
-	      /* Sinon, on verifie que le device corresponde */
-	      if (device == NULL || strcmp (device, definition_lignes[numero_ligne].device) == 0)
-		break;
-	      else {
+	    /* On verifie que le device corresponde */
+	    if (device != NULL && strcmp (device, definition_lignes[numero_ligne].device) != 0) {
+		/* sinon on passe  la ligne suivante */
 		if (numero_ligne == nb_lignes - 1) {
 #ifdef DEBUG_XTELD
 		  log_debug ("%s != %s", device, definition_lignes[numero_ligne].device);
@@ -129,32 +121,39 @@ char *telno, *device;
 		  erreur_a_xtel ("[2] Pas de device correspondant !", 0);
 		  return -1;
 		}
-	      }
+		numero_ligne++;
+		continue;
+	    }
+	    /* Si c'est le bon device, on tente du poser le lock */
+	    if (try_lock( nom_lck ) < 0) {
+		/* le modem est occup... on passe au suivant */
+		numero_ligne++;
+	    }
+	    else {
+		break;
 	    }
-	    
-	  once_again:
-	    numero_ligne++;
 	}
-	
-#ifdef DEBUG_XTELD
-	log_debug ("creation de %s", nom_lck);
-#endif
-
-	/* on cree un fichier semaphore LCK..ttyxx */
-	if ((fdlck = open (nom_lck, O_WRONLY|O_EXCL|O_CREAT, 0644)) < 0) {
-	    erreur_a_xtel (nom_lck, errno);
+	if (numero_ligne >= nb_lignes) {
+	    /* Dommage, c'etait la derniere :-( */
+	    erreur_a_xtel ("[0] Aucun MODEM disponible !", 0);
 	    return (-1);
 	}
 	
-	/* on ecrit le PID dedans */
-	sprintf (buf, "%10d\n", getpid ());
-	write (fdlck, buf, strlen (buf));
-	close (fdlck);
-	
 #ifdef DEBUG_XTELD
 	log_debug ("Ouverture de la ligne %s", definition_lignes[numero_ligne].nom);
 #endif
 	/* ouvre la ligne */
+	if (definition_lignes[numero_ligne].tempo > 0) {
+	    /*
+	     * Pour les vieux modems, dans certains cas, il faut rinitialiser le
+	     * port srie avant de pouvoir communiquer avec le modem.
+	     * Ceci est effectu en ouvrant puis refermant le device avec un certain
+	     * dlai entre chaque opration.
+	     */
+	    fd = open (definition_lignes[numero_ligne].nom, O_RDWR|O_NDELAY);
+	    usleep(definition_lignes[numero_ligne].tempo);
+	    close(fd);
+	}
 	if ((fd = open (definition_lignes[numero_ligne].nom, O_RDWR|O_NDELAY)) < 0) {
 	    /* Derniere ligne, on passe l'erreur */
 	    if (numero_ligne == nb_lignes-1) {
@@ -169,13 +168,13 @@ char *telno, *device;
 	}
 
 	/* Init des parametres de la ligne */
-	init_tty (fd, definition_lignes[numero_ligne].speed, definition_lignes[numero_ligne].cs, definition_lignes[numero_ligne].parity, definition_lignes[numero_ligne].flags, definition_lignes[numero_ligne].type_dialer);
+	init_tty (fd, definition_lignes[numero_ligne].speed, definition_lignes[numero_ligne].cs, definition_lignes[numero_ligne].parity, definition_lignes[numero_ligne].flags, definition_lignes[numero_ligne].type_dialer, definition_lignes[numero_ligne].tempo);
 
 #ifdef DEBUG_XTELD
 	log_debug ("Dialogue Modem...");
 #endif
 
-	erreur = do_chat (fd, definition_lignes[numero_ligne].chat, (unsigned long)definition_lignes[numero_ligne].delai, telno, NULL, 0);
+	erreur = do_chat (fd, definition_lignes[numero_ligne].chat, (unsigned long)definition_lignes[numero_ligne].delai, definition_lignes[numero_ligne].tempo, telno, NULL, 0);
 
 	/*
 	 * Test de l'erreur en sortie
@@ -196,8 +195,10 @@ char *telno, *device;
 		erreur_a_xtel (nom_lck, errno);
 	    }
 	    close (fd);
-	    numero_ligne++;
 	}
+
+    once_again:
+	numero_ligne++;
     }
 
     /*
@@ -208,3 +209,93 @@ char *telno, *device;
 
     return (-1);
 }
+
+/* Verrouille la ligne serie (retourne 0 si ok, -1 si erreur) */
+static int try_lock (char *lock_file)
+{
+  char buf[256];
+  struct stat statb;
+  int fd, n;
+  pid_t pid;
+
+  /* Test du lock */
+  do {
+      fd = open( lock_file, O_CREAT | O_EXCL | O_WRONLY, 0644 );
+      if (fd < 0) {
+	  /* erreur lors de la cration du fichier de lock */
+	  if (errno == EEXIST) {
+	      /* le fichier existe : voir si le programme qui l'a cr existe toujours */
+	      fd = open( lock_file, O_RDONLY );
+	      if (fd >= 0) {
+		  n = read( fd, buf, 11 );
+		  close( fd );
+		  if (n > 0) {
+		      buf[n] = '\0';
+		      pid = atoi(buf);
+		      /* teste l'existence du processus ayant cr le fichier */
+		      if (pid == 0 || kill(pid,0) == -1 && errno == ESRCH) {
+			  if (unlink(lock_file) == 0) {
+#ifdef DEBUG_XTELD
+			      log_debug ("Removed stale lock %s (pid %d)", lock_file, pid);
+#endif
+			      /* et on retente la cration dudit fichier */
+			      fd = -1;
+			  }
+			  else {
+#ifdef DEBUG_XTELD
+			      log_debug ("Can't remove stale lock %s", lock_file);
+#endif
+			      return -1;
+			  }
+		      }
+		      else {
+#ifdef DEBUG_XTELD
+			  char *line = strrchr( lock_file, '/' )+6; /* aprs le /LCK.. */
+			  log_debug ("Device %s is already locked by pid %d", line, pid);
+#endif
+			  return -1;
+		      }
+		  }
+		  else {
+#ifdef DEBUG_XTELD
+		      log_debug ("Can't read pid from lock file %s", lock_file);
+#endif
+		      return -1;
+		  }
+	      }
+	      else if (errno != ENOENT) {
+		  /* il ne vient pas d'tre effac par un autre programme */
+		  /* c'est donc un vrai problme */
+#ifdef DEBUG_XTELD
+		  log_debug ("%s: %s", lock_file, strerror(errno));
+#endif
+		  return -1;
+	      }
+	  }
+	  else {
+	      /* fichier impossible  crer */
+#ifdef DEBUG_XTELD
+	      log_debug ("Can't create lock file %s (%s)", lock_file, strerror(errno));
+#endif
+	      return -1;
+	  }
+      }
+  } while (fd < 0);
+
+  /* Le lock est pos ; il faut y inscrire le pid de ce programme */
+  sprintf (buf, "%10d\n", getpid());
+  if (write (fd, buf, 11) != 11) {
+#ifdef DEBUG_XTELD
+      log_debug ("Error writing to file %s (%s)", lock_file, strerror(errno));
+#endif
+      close (fd);
+      return -1;
+  }
+#ifdef DEBUG_XTELD
+  log_debug ("fichier lock %s cree", nom_lck);
+#endif
+
+  close (fd);
+  return 0;
+}
+
diff --git a/globald.h b/globald.h
index 5c34446..c3864c3 100644
--- a/globald.h
+++ b/globald.h
@@ -74,9 +74,9 @@ int ian_valide (int, char);
 void ian_init (char*);
 
 /* modem.c */
-void init_tty (int, int, int, int, int, int);
+void init_tty (int, int, int, int, int, int, int);
 void restore_tty (int);
-int do_chat (int, char*, unsigned long, char*, char*, int);
+int do_chat (int, char*, unsigned long, int, char*, char*, int);
 void init_debug (char*);
 void close_debug (void);
 #else
diff --git a/iminitel/connect_iminitel.sh b/iminitel/connect_iminitel.sh
index 0680e50..b829f03 100755
--- a/iminitel/connect_iminitel.sh
+++ b/iminitel/connect_iminitel.sh
@@ -1,17 +1,8 @@
 #!/bin/sh
 # $Id: connect_iminitel.sh,v 1.2 2001/02/11 00:16:52 pierre Exp $
-IMINITEL_FILE=/tmp/.iminitel
 
 case "$1" in
     start)
-	# Test lock
-	if [ -r ${IMINITEL_FILE} ]; then
-	    exit 1
-	fi
-
-	# Pose le lock
-	echo -n > ${IMINITEL_FILE}
-
 	# Appel serveur 3622
 	/usr/sbin/pppd call iminitel ipparam iminitel
 	exit $?
@@ -19,10 +10,9 @@ case "$1" in
 
     stop)
 	# Si ppp est encore actif, on coupe
-	if [ -r ${IMINITEL_FILE} ]; then
-	    . ${IMINITEL_FILE}
-	    # Tue de demon pppd
-	    kill `cat /var/run/${IMINITEL_INTERFACE}.pid`
+	if [ -r /var/run/ppp-iminitel.pid ]; then
+	    # Tue le demon pppd
+	    kill `head -1 /var/run/ppp-iminitel.pid`
 	fi    
 	;;
 
diff --git a/iminitel/iminitel b/iminitel/iminitel
index faaadb8..390285c 100644
--- a/iminitel/iminitel
+++ b/iminitel/iminitel
@@ -3,3 +3,4 @@ connect '/usr/sbin/chat -v -f /etc/ppp/chat-iminitel'
 noauth
 lock
 idle 120
+linkname iminitel
diff --git a/iminitel/ip-down.iminitel b/iminitel/ip-down.iminitel
index 7ad8d86..cc6ef4f 100755
--- a/iminitel/ip-down.iminitel
+++ b/iminitel/ip-down.iminitel
@@ -2,6 +2,6 @@
 # $Id: ip-down.iminitel,v 1.1 2001/02/05 09:34:59 pierre Exp $
 # I-Minitel
 if [ "$6" = "iminitel" ]; then
-    rm -f /tmp/.iminitel
+    rm -f /var/run/iminitel
 fi
 
diff --git a/iminitel/ip-up.iminitel b/iminitel/ip-up.iminitel
index 10718c1..2a93654 100755
--- a/iminitel/ip-up.iminitel
+++ b/iminitel/ip-up.iminitel
@@ -19,10 +19,14 @@ if [ "$6" = "iminitel" ]; then
 	shift
 	i=`expr $i + 1`
     done
-    /sbin/route add -host $1 gw ${IMINITEL_ADDR}
-    cat <<EOF > /tmp/.iminitel
-IMINITEL_SERVER=$1
+    /sbin/route add -host ${1} gw ${IMINITEL_ADDR}
+    # cre le fichier d'tat I-Minitel.
+    # Utilise un nommage temporaire pour tre sr que tout son contenu sera
+    # disponible lors de la lecture (asynchrone) par xteld.
+    cat <<EOF > /var/run/iminitel.tmp
+IMINITEL_SERVER=${1}
 IMINITEL_INTERFACE=${IMINITEL_INTERFACE}
 EOF
+    mv /var/run/iminitel.tmp /var/run/iminitel
 fi
 
diff --git a/imprime.c b/imprime.c
index 7a545d7..cd0b8d3 100644
--- a/imprime.c
+++ b/imprime.c
@@ -28,26 +28,37 @@ static void imprime_page_courante (mode)
 int mode;
 {
     FILE *fp;
-    char cmd[256], n[256];
+    int fd = -1;
+    char cmd[256];
+    char n[] = "/var/tmp/xtelXXXXXX";
+    /* cre le fichier de telle faon qu'il soit impossible de le dtourner
+     * avec un lien symbolique pralablement tabli.
+     */
+    if (mktemp(n) != NULL)
+	fd = open (n, O_CREAT | O_EXCL | O_WRONLY, 0600);
 
-    sprintf (n, "/tmp/xtel%d.ppm", getpid());
-    if ((fp = fopen (n, "w")) == NULL) {
+    if (fd < 0) {
 	perror (n);
-	exit (1);
     }
-
-    if (mode == VIDEOTEX) {
-	videotexDumpScreen (ecran_minitel, fp);
-	sprintf (cmd, rsc_xtel.commandeImpression, n);
-    }
-    else { /* ASCII */
-	videotexConversionAscii (ecran_minitel, fp);
-	sprintf (cmd, rsc_xtel.commandeImpressionAscii, n);
+    else if ((fp = fdopen( fd, "wb" )) == NULL) {
+	close (fd);
+	unlink (n);
+	perror (n);
     }
+    else {
+	if (mode == VIDEOTEX) {
+	    videotexDumpScreen (ecran_minitel, fp);
+	    sprintf (cmd, rsc_xtel.commandeImpression, n);
+	}
+	else { /* ASCII */
+	    videotexConversionAscii (ecran_minitel, fp);
+	    sprintf (cmd, rsc_xtel.commandeImpressionAscii, n);
+	}
 
-    fclose (fp);
-    system (cmd);
-    unlink (n);
+	fclose (fp);
+	system (cmd);
+	unlink (n);
+    }
 }
 
 void imprime_page_courante_ascii (w, client_data, call_data)
diff --git a/make_xtel_lignes.sh b/make_xtel_lignes.sh
index 608beb3..5fa371c 100644
--- a/make_xtel_lignes.sh
+++ b/make_xtel_lignes.sh
@@ -27,10 +27,8 @@ if [ "$M" = "" ]; then
     exit 1
 fi
 
-if [ -r $XTEL_LIGNES ]; then
-    echo "Copie de l'ancien $XTEL_LIGNES sur ${XTEL_LIGNES}.$$"
-    mv $XTEL_LIGNES ${XTEL_LIGNES}.$$
-fi
+NEW_XTEL_LIGNES=$XTEL_LIGNES.$$
+rm -f $NEW_XTEL_LIGNES
 
 j=0
 for i in 0 1 2 3
@@ -111,9 +109,9 @@ do
 		echo -n "Quel votre prfixe d'appel (exemple: 0w) ? "
 		read c < /dev/tty	
 		    
-		echo "# $m $MDM" >> $XTEL_LIGNES
-		echo "modem${j}${2}/dev/${TTYLINE}${2}$3${2}7${2}E${2}$4 atdt$c\\T\\r CONNECT${2}30" | sed -e 's/-/ /g' >> $XTEL_LIGNES
-		echo >> $XTEL_LIGNES
+		echo "# $m $MDM" >> $NEW_XTEL_LIGNES
+		echo "modem${j}${2}/dev/${TTYLINE}${2}$3${2}7${2}E${2}$4 atdt$c\\T\\r CONNECT${2}30" | sed -e 's/-/ /g' >> $NEW_XTEL_LIGNES
+		echo >> $NEW_XTEL_LIGNES
 		j=`expr $j + 1`
 	    else
 		sleep 1
@@ -121,7 +119,11 @@ do
 	fi
 done
 
-if [ ! -r $XTEL_LIGNES -a -r ${XTEL_LIGNES}.$$ ]; then
-    echo "Aucun modem dtect, restauration du $XTEL_LIGNES"
-    mv ${XTEL_LIGNES}.$$ $XTEL_LIGNES
+if [ ! -r $NEW_XTEL_LIGNES ]; then
+    echo "Aucun modem dtect."
+else
+    if [ $j -gt 1 ]; then s="s"; fi
+    echo "$j modem$s dtect$s, cration du $XTEL_LIGNES"
+    if [ -f $XTEL_LIGNES ]; then mv ${XTEL_LIGNES} $XTEL_LIGNES.old ; fi
+    mv $NEW_XTEL_LIGNES $XTEL_LIGNES
 fi
diff --git a/mdmdetect.c b/mdmdetect.c
index 4c72c59..871b886 100644
--- a/mdmdetect.c
+++ b/mdmdetect.c
@@ -43,6 +43,7 @@ static char rcsid[] = "$Id: mdmdetect.c,v 1.3 2001/02/11 00:02:58 pierre Exp $";
 #endif /* SVR4 */
 
 #define TIMEOUT_READ		5
+#define TEMPO			1000000
 
 #ifndef __FreeBSD__
 #ifndef __GLIBC__
@@ -100,7 +101,8 @@ static void check_and_lock (char *line)
 {
   char buf[256];
   struct stat statb;
-  FILE *fplock;
+  int fd, n;
+  pid_t pid;
 
   /* A la mode UUCP... */
 #ifdef SVR4
@@ -116,19 +118,64 @@ static void check_and_lock (char *line)
 #endif /* SVR4 */
 
   /* Test du lock */
-  if (stat (lock_file, &statb) == 0) {
-    fprintf (stderr, "Lock file %s already exists, exiting.\n", lock_file);
-    the_end (1);
-  }
+  do {
+      fd = open( lock_file, O_CREAT | O_EXCL | O_WRONLY, 0644 );
+      if (fd < 0) {
+	  /* erreur lors de la cration du fichier de lock */
+	  if (errno == EEXIST) {
+	      /* le fichier existe : voir si le programme qui l'a cr existe toujours */
+	      fd = open( lock_file, O_RDONLY );
+	      if (fd >= 0) {
+		  n = read( fd, buf, 11 );
+		  close( fd );
+		  if (n > 0) {
+		      buf[n] = '\0';
+		      pid = atoi(buf);
+		      /* teste l'existence du processus ayant cr le fichier */
+		      if (pid == 0 || kill(pid,0) == -1 && errno == ESRCH) {
+			  if (unlink(lock_file) == 0) {
+			      fprintf (stderr, "Removed stale lock %s (pid %d)\n", lock_file, pid);
+			      /* et on retente la cration dudit fichier */
+			      fd = -1;
+			  }
+			  else {
+			      fprintf (stderr, "Can't remove stale lock %s\n", lock_file);
+			      the_end (1);
+			  }
+		      }
+		      else {
+			  fprintf (stderr, "Device %s is already locked by pid %d\n", line, pid);
+			  the_end (1);
+		      }
+		  }
+		  else {
+		      fprintf (stderr, "Can't read pid from lock file %s\n", lock_file);
+		      the_end (1);
+		  }
+	      }
+	      else if (errno != ENOENT) {
+		  /* il ne vient pas d'tre effac par un autre programme */
+		  /* c'est donc un vrai problme */
+		  fprintf (stderr, "%s: %s\n", lock_file, sys_errlist[errno]);
+		  the_end (1);
+	      }
+	  }
+	  else {
+	      /* fichier impossible  crer */
+	      fprintf (stderr, "Can't create lock file %s (%s)\n", lock_file, sys_errlist[errno]);
+	      the_end (1);
+	  }
+      }
+  } while (fd < 0);
 
-  /* Pose le lock */
-  if (!(fplock = fopen (lock_file, "w"))) {
-      fprintf (stderr, "%s: %s\n", lock_file, sys_errlist[errno]);
+  /* Le lock est pos ; il faut y inscrire le pid de ce programme */
+  sprintf (buf, "%10d\n", getpid());
+  if (write (fd, buf, 11) != 11) {
+      fprintf (stderr, "Error writing to file %s (%s)\n", lock_file, sys_errlist[errno]);
+      close (fd);
       the_end (1);
   }
-  
-  fprintf (fplock, "%10d\n", getpid());
-  fclose (fplock);
+  close (fd);
 }
 
 /* Lecture d'une ligne terminee par '\n' */
@@ -191,27 +238,20 @@ int port;
 }
 
 /* Recherche de mot-cle */
-static int check_for_kw (int fd, char *builder, char *kw, char *s)
+static char* check_for_kw (int fd, char *s)
 {
-  char modem_string[4096], chat_script[256];
+  static char modem_string[4096], chat_script[256];
 
   fprintf (stderr, "."); fflush (stderr);
 
   sprintf (chat_script, "%s\r OK", s);
-  if (do_chat (fd, chat_script, TIMEOUT_READ, NULL, modem_string, sizeof(modem_string)) != 0)
-    return 0;
+  if (do_chat (fd, chat_script, TIMEOUT_READ, TEMPO, NULL, modem_string, sizeof(modem_string)) != 0)
+    return NULL;
 
   if (debug)
-    log_debug ("[%s] check_for_kw %s: reponse= %s", builder, kw, modem_string);
-
-  if (strstr (modem_string, kw)) {
-      if (debug)
-	log_debug ("%s trouve !", kw);
+    log_debug ("reponse= %s", modem_string);
 
-      return 1;
-  }
-      
-  return 0;
+  return modem_string;
 }
 
 
@@ -219,7 +259,8 @@ main (ac, av)
 int ac;
 char **av;
 {
-  char *cp, *str1, *str2;
+  char cmd[6];
+  char *cp, *fab, *modem_string, *reponse;
   register int i;
   int found = 0;
 #ifdef DEBUG_XTELD
@@ -285,7 +326,29 @@ char **av;
     }
   }
 
-  if (!query) {
+  if (query) {
+    /* Lecture de la liste des modems */
+    while (read_a_line (fdl, buf, sizeof(buf)) > 0) {
+
+      if (debug)
+	log_debug ("(%s)", buf);
+
+      if (buf[0] == '#' || buf[0] == '\n')
+	continue;
+
+      /* Fabricant */
+      if (buf[0] == '[') {
+	fab = strdup (&buf[1]);
+	fab[strlen(fab)-2] = 0;
+	if (query)
+	  printf ("%s\n", fab);
+
+	continue;
+      }
+    }
+  }
+
+  else {
     /* Test et lock de la ligne */
     check_and_lock (cp);
 
@@ -296,65 +359,53 @@ char **av;
     }
 
     /* Ligne en mode 'raw' */
-    init_tty (fd, B9600, CS8, 2, 0, 0);
+    init_tty (fd, B9600, CS8, 2, 0, 0, TEMPO);
 
     /* Test de presence de modem */
-    if (do_chat (fd, "AT\r OK", 3, NULL, NULL, 0)) {
+    if (do_chat (fd, "AT\r OK", 3, TEMPO, NULL, NULL, 0)) {
       /* On insiste un peu */
-      if (do_chat (fd, "AT\r OK", 3, NULL, NULL, 0)) {
+      if (do_chat (fd, "AT\r OK", TEMPO, 3, NULL, NULL, 0)) {
 	fprintf (stderr, "Pas de modem prsent !\n");
 	the_end (1);
       }
     }
-  }
-
-  /* Lecture de la liste des modems */
-  while (read_a_line (fdl, buf, sizeof(buf)) > 0) {
-
-    if (debug)
-      log_debug ("(%s)", buf);
-
-    if (buf[0] == '#' || buf[0] == '\n')
-      continue;
-
-    /* Fabricant */
-    if (buf[0] == '[') {
-      str1 = strdup (&buf[1]);
-      str1[strlen(str1)-2] = 0;
-      if (query)
-	printf ("%s\n", str1);
-
-      continue;
-    }
-
-    /* Si on a specifie un fabricant, teste le nom */
-    if (query || (builder && strcmp (str1, builder)))
-      continue;
-      
-    /* Mot-cle a tester */
-    str2 = next_token (buf, ":");
-
-    if (!str2) {
-      fprintf (stderr, "Erreur de lecture %s\n", modem_list);
-      the_end (1);
-    }
-
-    /* Interrogation par ATI puis ATIx */
-    found = 0;
-    if ((found = check_for_kw (fd, str1, str2, "ATI")) == 0) {
-      for (i = '0' ; i <= '9' ; i++) {
-	char cmd[6];
 
-	sprintf (cmd, "ATI%c", i);
-	if ((found = check_for_kw (fd, str1, str2, cmd)) > 0) {
-	  break;
+    /* interrogation du modem sur l'ensemble des registres de configuration */
+    strcpy (cmd, "ATI");
+    for (i = -1 ; !found && i <= 9 ; i++) {
+      if (i >= 0)
+	sprintf (cmd, "ATI%d", i);
+      if ((reponse = check_for_kw (fd, cmd)) != NULL) {
+	/* on a une rponse : rechercher dans la base */
+	lseek (fdl, 0, 0);
+	found = 0;
+	while (!found && read_a_line (fdl, buf, sizeof(buf)) > 0) {
+	  if (debug)
+	    log_debug ("(%s)", buf);
+	  if (buf[0] == '#' || buf[0] == '\n') {
+	    /* commentaire ou ligne blanche */
+	  }
+	  else if (buf[0] == '[') {
+	    /* Fabricant */
+	    fab = strdup (&buf[1]);
+	    fab[strlen(fab)-2] = 0;
+	  }
+	  else if (!builder || strcmp (builder, fab)==0) {
+	    /* description d'un modem */
+	    modem_string = next_token (buf, ":");   /* Mot-cl  tester */
+	    if (strstr (reponse, modem_string)) {
+	      if (debug)
+		log_debug ("%s trouve !", modem_string);
+	      found = 1;
+	    }
+	  }
 	}
       }
     }
 
     if (found) {
       if (debug)
-	log_debug ("str2= %s buf= %s", str2, buf);
+	log_debug ("builder= %s modem id= %s", fab, modem_string);
 
       puts ("\n");
 
diff --git a/modem.c b/modem.c
index 3652484..3e0e63f 100644
--- a/modem.c
+++ b/modem.c
@@ -61,7 +61,7 @@ static struct termio term_sauve, term;
 static struct termiox termx;
 #endif /* lectra && SVR4 && !sun || hpux */
 
-#ifndef SYSLOG
+#ifndef USE_SYSLOG
 static FILE *fp_console;
 #endif
 static char prefix[256];
@@ -89,13 +89,13 @@ void close_debug ()
 
 /* Syslog or not syslog ? */
 #ifdef USE_SYSLOG
-void log_debug (fmt, p1, p2, p3, p4, p5, p6, p7)
+void log_debug (fmt, p1, p2, p3, p4, p5, p6, p7, p8)
 char *fmt;
-int  p1, p2, p3, p4, p5, p6, p7;
+int  p1, p2, p3, p4, p5, p6, p7, p8;
 {
     char msg[256];
 
-    sprintf (msg, fmt, p1, p2, p3, p4, p5, p6, p7);
+    sprintf (msg, fmt, p1, p2, p3, p4, p5, p6, p7, p8);
     syslog (LOG_INFO, msg);
 }
 
@@ -105,12 +105,12 @@ char *s;
     syslog (LOG_ERR, s);
 }
 #else
-void log_debug (fmt, p1, p2, p3, p4, p5, p6, p7)
+void log_debug (fmt, p1, p2, p3, p4, p5, p6, p7, p8)
 char *fmt;
-int  p1, p2, p3, p4, p5, p6, p7;
+int  p1, p2, p3, p4, p5, p6, p7, p8;
 {
     fprintf (fp_console, "%s[%d] ", prefix, getpid());
-    fprintf (fp_console, fmt, p1, p2, p3, p4, p5, p6, p7);
+    fprintf (fp_console, fmt, p1, p2, p3, p4, p5, p6, p7, p8);
     fprintf (fp_console, "\n\r");
 }
 
@@ -151,13 +151,15 @@ int n;
 }
 
 /* Init des parametres de ligne */
-void init_tty (int fd, int speed, int csize, int parity, int flags, int dialer)
+void init_tty (int fd, int speed, int csize, int parity, int flags, int dialer, int tempo)
 {
 #ifdef NO_TERMIO
   ioctl (fd, TIOCGETP, &term);
+  usleep(tempo);
   memcpy ((char *)&term_sauve, (char *)&term, sizeof(struct sgttyb));
   term.sg_flags |= RAW;
   ioctl (fd, TIOCSETP, &term);
+  usleep(tempo);
 	
   /* Flags, pour l'instant RTS/CTS */
   /* FIXME: comment passer la ligne en RTS/CTS sans termio ? */
@@ -166,9 +168,11 @@ void init_tty (int fd, int speed, int csize, int parity, int flags, int dialer)
 
 #ifdef USE_TERMIOS
   ioctl (fd, TIOCGETA, &term);
+  usleep(tempo);
   memcpy ((char *)&term_sauve, (char *)&term, sizeof(struct termios));
 #else
   ioctl (fd, TCGETA, &term);
+  usleep(tempo);
   memcpy ((char *)&term_sauve, (char *)&term, sizeof(struct termio));
 #endif /* USE_TERMIOS */
 	
@@ -185,7 +189,8 @@ void init_tty (int fd, int speed, int csize, int parity, int flags, int dialer)
    */
   term.c_cflag &= ~(CSIZE|CSTOPB);
   term.c_cflag |= (CREAD|HUPCL);
-  term.c_ispeed = term.c_ospeed = speed;
+  cfsetispeed (&term, speed);
+  cfsetospeed (&term, speed);
 #else
   term.c_cflag &= ~(CSIZE|CBAUD|CLOCAL);
 
@@ -236,35 +241,44 @@ void init_tty (int fd, int speed, int csize, int parity, int flags, int dialer)
   /* Affectation des parametres */
 #ifdef USE_TERMIOS
   ioctl (fd, TIOCSETA, &term);
+  usleep(tempo);
 #else
   ioctl (fd, TCSETA, &term);
+  usleep(tempo);
 #endif /* USE_TERMIOS */
 #endif /* NO_TERMIO */
 }
 
 /* Restauration des parametres */
-void restore_tty (fd)
+void restore_tty (int fd)
 {
 #ifdef ultrix
   int temp = 0;
 #endif
+  int tempo = 0;
  
    /* remet la ligne en l'etat */
 #ifdef NO_TERMIO
   term.sg_ispeed = term.sg_ospeed = B0;
   ioctl (fd, TIOCSETP, &term);
+  usleep(tempo);
   ioctl (fd, TIOCSETP, &term_sauve);
+  usleep(tempo);
 #else
 #ifdef USE_TERMIOS
-  term.c_ispeed = B0;
-  term.c_ospeed = B0;
+  cfsetispeed (&term, B0);
+  cfsetospeed (&term, B0);
   ioctl (fd, TIOCSETAW, &term);
+  usleep(tempo);
   ioctl (fd, TIOCSETA, &term_sauve);
+  usleep(tempo);
 #else
   term.c_cflag &= ~CBAUD;
   term.c_cflag |= B0;
   ioctl (fd, TCSETAW, &term);
+  usleep(tempo);
   ioctl (fd, TCSETA, &term_sauve);
+  usleep(tempo);
 #endif /* USE_TERMIOS */
 #endif /* NO_TERMIO */
 #ifdef ultrix
@@ -277,10 +291,11 @@ void restore_tty (fd)
 /* 
  * Dialogue avec le Modem (chatons, chatons...)
  */
-int do_chat (fd, chat_script, tmax, telno, reply_buf, reply_size)
+int do_chat (fd, chat_script, tmax, tempo, telno, reply_buf, reply_size)
 int fd;
 char *chat_script;
 unsigned long tmax;
+int tempo;
 char *telno, *reply_buf;
 int reply_size;
 {
@@ -288,7 +303,6 @@ int reply_size;
     int i, erreur, fin, nbread, cmodem;
     char *pt_chat, c, *q;
 
-    delai_maxi.tv_sec = tmax;
     erreur = 0;
     pt_chat = chat_script;
     fin = 0;
@@ -307,16 +321,20 @@ int reply_size;
      *  (comme le Hayes Optima par exemple)...
      */
 #ifdef USE_TERMIOS
-    ioctl (fd, TCIOCGETA, &term);
+    ioctl (fd, TIOCGETA, &term);
+    usleep(tempo);
 #else
     ioctl (fd, TCGETA, &term);
+    usleep(tempo);
 #endif /* USE_TERMIOS */
     if ((term.c_cflag | CLOCAL) == 0) {
 	term.c_cflag |= CLOCAL;
 #ifdef USE_TERMIOS
-	ioctl (fd, TCIOCSETA, &term);
+	ioctl (fd, TIOCSETA, &term);
+	usleep(tempo);
 #else
 	ioctl (fd, TCSETA, &term);
+	usleep(tempo);
 #endif /* USE_TERMIOS */
 	cmodem = 1;
     }
@@ -475,6 +493,7 @@ int reply_size;
 	for (;;) {
 	    
 	    t_a_lire = a_lire;
+	    delai_maxi.tv_sec = tmax;
 	    nbread = select (32, &t_a_lire, NULL, NULL, &delai_maxi);
 
 	    /* Si il y a qque chose a lire */
@@ -565,9 +584,10 @@ int reply_size;
 		/* erreur read */
 		else {
 #ifdef DEBUG_XTELD
-		    log_debug ("Erreur read !");
+		    log_debug ("Erreur read ! (errno=%d)",errno);
 #endif
-		    erreur = 1;
+		    /*erreur = 1;*/
+		    if (++erreur > 10)
 		    break;
 		}
 	    }
@@ -592,9 +612,11 @@ int reply_size;
     if (cmodem) {
 	term.c_cflag &= ~CLOCAL;
 #ifdef USE_TERMIOS
-	ioctl (fd, TCIOCSETA, &term);
+	ioctl (fd, TIOCSETA, &term);
+	usleep(tempo);
 #else
 	ioctl (fd, TCSETA, &term);
+	usleep(tempo);
 #endif /* USE_TERMIOS */
     }
 #endif
diff --git a/modem.list b/modem.list
index e277e50..85af66b 100644
--- a/modem.list
+++ b/modem.list
@@ -41,3 +41,7 @@ KORTEX 336:Novafax-336:|:38400:\dATZ\r-OK-ATM2\r-OK-AT+MS=3\x2C0\x2C1200\x2C1200
 ACCURA:ACCURA-288/336:,:38400:\datm1&k3\r-OK-atb2\r-OK
 RCV56:Accura-56K:,:38400:\dat&fm1e0&k3f3\r-OK
 SMO14400:OPTIMA-144:,:38400:\datm1&k3\r-OK-atb2\r-OK
+
+[SAGEM]
+TELSAT 14402:TelSat 14402:,:38400:\dATZ0\r-OK
+
diff --git a/xtel.lignes b/xtel.lignes
index e25c5c0..d637670 100644
--- a/xtel.lignes
+++ b/xtel.lignes
@@ -17,7 +17,10 @@ modem0,/dev/modem,1200,7,E,\dat\r OK atm1b2\r OK atdt\T\r CONNECT,30
 #modem0,/dev/modem,1200,7,E,\dat\r OK ATM1S27=16&N2S40=1S9=100&N2\r OK atdt\T\r CONNECT,30
 
 # Modem USR Sporter 56K
-#modem0,/dev/modem,1200,7,E,\dat\r OK AT&F1M1S27=16S34=8S40=6&N2S9=100&B2 OK atdt\T\r CONNECT,30
+#modem0,/dev/modem,1200,7,E,\dat\r OK AT&F1M1S27=16S34=8S40=6&N2S9=100&B2\r OK atdt\T\r CONNECT,30
+
+#Modem USR Courier I-modem externe bios 2.50
+#modem0,/dev/modem,38400,7,E,\dat\r OK AT&f1m1l1b0*v2=3s34=8&n2s27=16s40=1s9=100&b2\r OK atdt\T\r CONNECT,30
 
 # Minitel 1
 #modem0,/dev/modem,1200,7,E,minitel1,30
diff --git a/xtel.man b/xtel.man
index 27c867e..2780c01 100644
--- a/xtel.man
+++ b/xtel.man
@@ -1,6 +1,6 @@
 .\" Copyright (c) 1991-98 Lectra-Systemes
 .\" $Id: xtel.man,v 1.10 1998/10/02 15:09:58 pierre Exp $
-.TH XTEL n "Lectra-Systemes" "10/98"
+.TH XTEL 1 "Lectra-Systemes" "10/98"
 .UC 5
 .SH NOM
 xtel \- Emulateur MINITEL 
diff --git a/xteld.c b/xteld.c
index 6a20893..f55599c 100644
--- a/xteld.c
+++ b/xteld.c
@@ -64,6 +64,7 @@ static char rcsid[] = "$Id: xteld.c,v 1.33 2001/02/13 09:40:49 pierre Exp $";
 #include <time.h>
 #include <signal.h>
 #include <string.h>
+#include <fcntl.h>
 
 #ifdef NO_TERMIO
 #include <sgtty.h>
@@ -204,9 +205,13 @@ static int read_iminitel_file ()
   char buf[256];
 
   if (stat (IMINITEL_FILE, &statb) < 0) {
-    /* Ne devrait pas arriver */
-    erreur_a_xtel (IMINITEL_FILE, errno);
-    exit (1);
+    if (errno != ENOENT) {
+      /* Ne devrait pas arriver */
+      erreur_a_xtel (IMINITEL_FILE, errno);
+      exit (1);
+    }
+    else
+      return 0;
   }
 
   /* Fichier non vide, on lit les parametres */
@@ -435,10 +440,12 @@ static void deconnexion ()
 	/* signal a XTEL la deconnexion */
 	write (XTELD_OUTPUT, CHAINE_REPONSE_DECONNEXION, 1);
 	
+#if 0 /* symlink attack vulnerability */
 	/* supprime le fichier de log */
 	sprintf (buf, "/tmp/.xtel-%s", utilisateur);
 	unlink (buf);
-	
+#endif
+
 	if ((fplog= fopen(FICHIER_LOG, "a")) != NULL) {
 	    long t= time(0), duree;
 	    char *at= ctime(&t);
@@ -696,7 +703,7 @@ char *service_teletel;
       if (!strncmp (device_associe, "@tcp", 4) || !strncmp (device_associe, "@imi", 4)) {
 	char *tcp_port;
 	int maxtime;
-	struct stat statb;
+	int fd;
 
 	/* Valide la saisie */
 	saisie_active = 1;
@@ -708,17 +715,63 @@ char *service_teletel;
 	if (!strncmp (device_associe, "@imi", 4)) {
 	  strcpy (iminitel_script, code_teletel);
 
+	  /* On vrifie si dj connect (i.e. existence du fichier lock
+	   * /var/run/ppp-iminitel.pid qui contient le pid du processus ppp
+	   * normalement encore actif) */
+	  fd = open( IMINITEL_LOCKFILE, O_RDONLY );
+	  if (fd >= 0) {
+	      /* le fichier existe : voir si le programme qui l'a cr existe toujours */
+	      char buf[20];
+	      int n;
+	      /* lit la premire ligne contenant le PID du processus qui l'a cr */
+	      n = read( fd, buf, sizeof(buf) );
+	      close( fd );
+	      if (n > 0) {
+		  /* rcupre le PID */
+		  pid_t pid;
+		  buf[n] = '\0';
+		  pid = (pid_t)atoi( buf );
+		  /* teste l'existence du processus ayant cr le fichier */
+		  if (pid == 0 || (kill(pid,0) == -1 && errno == ESRCH)) {
+		      if (unlink(IMINITEL_LOCKFILE) == 0) {
+#ifdef DEBUG_XTELD
+			  log_debug ("Removed stale lock %s (pid %d)", IMINITEL_LOCKFILE, pid);
+#endif
+			  /* et on redmarrera la connexion ppp */
+			  fd = -1;
+		      }
+		      else {
+			  erreur_a_xtel (IMINITEL_LOCKFILE, errno);
+			  return;
+		      }
+		  }
+		  else {
+		      /* le processus existe encore -> connexion suppose active */
+		  }
+	      }
+	  }
+	  else if (errno != ENOENT) {
+	      /* il ne vient pas d'tre effac par un autre programme */
+	      /* c'est donc un vrai problme */
+	      erreur_a_xtel (IMINITEL_LOCKFILE, errno);
+	      return;
+	  }
 	  /* Si pas deja connecte, on lance la connexion */
-	  if (stat (IMINITEL_FILE, &statb) < 0) {
-	    /* Execution du script de connexion avec option 'start' */
-	    sprintf (buf, "%s/%s start", XTEL_LIBDIR, iminitel_script);
+	  if (fd < 0) {
+	      /* Effacer ventuellement le fichier d'tat I-Minitel */
+	      if (unlink( IMINITEL_FILE ) < 0 && errno != ENOENT) {
+		  erreur_a_xtel( IMINITEL_FILE, errno );
+		  return;
+	      }
+	      /* Execution du script de connexion avec option 'start' */
+	      sprintf (buf, "%s/%s start", XTEL_LIBDIR, iminitel_script);
 #ifdef DEBUG_XTELD
-	    log_debug ("execute: %s", buf);
+	      log_debug ("execute: %s", buf);
 #endif
-	    if (system (buf) != 0) {
-	      erreur_a_xtel (buf, errno);
-	      exit (1);
-	    }
+	      if (system (buf) != 0) {
+		  erreur_a_xtel (buf, errno);
+		  exit (1);
+	      }
 	  }
 
 	  /* Temps maxi d'attente de connexion */
@@ -1006,6 +1059,7 @@ char *service_teletel;
     signal(SIGTERM, SIG_DFL);
 
     /* creation du fichier de log */
+#if 0 /* symlink attack vulnerability */
     sprintf (buf, "/tmp/.xtel-%s", utilisateur);
     if ((fplog = fopen (buf, "w"))) {
 #ifdef DEBUG_XTELD
@@ -1019,6 +1073,7 @@ char *service_teletel;
 	fprintf (fplog, "SERVICE = %s\n", service);
 	fclose (fplog);
     }
+#endif
     
     if ((fplog= fopen(FICHIER_LOG, "a")) != NULL) {
 	char *at;
diff --git a/xteld.man b/xteld.man
index 68b45a9..8fc1b18 100644
--- a/xteld.man
+++ b/xteld.man
@@ -1,6 +1,6 @@
 .\" Copyright (c) 1991-98 Lectra-Systemes
 .\" $Id: xteld.man,v 1.10 2001/02/11 00:11:35 pierre Exp $
-.TH XTELD n "Lectra-Systemes" "10/98"
+.TH XTELD 8 "Lectra-Systemes" "10/98"
 .UC 5
 .SH NOM
 xteld \- dmon de l'mulateur Minitel XTEL
@@ -23,7 +23,7 @@ Edition) comment client 
 
 .SH UTILISATION
 .LP
-\fIxteld\fP utilise le fichier \fB"/usr/X11R6/lib/X11/xtel/xtel\.services"\fP
+\fIxteld\fP utilise le fichier \fB"/usr/X11R6/lib/X11/xtel/xtel.services"\fP
 (sous Xfree86) qui contient la liste des services disponibles sous la forme :
 .sp
 .I "[Nom du device,]"
@@ -116,7 +116,7 @@ La derni
 (mot\-cl \fIDirect\fP), l'utilisateur saisira directement le numro lors de la 
 composition dans \fIxtel\fP.
 .LP
-On utilise galement le fichier \fB"/usr/X11R6/lib/X11/xtel/xtel\.lignes"\fP
+On utilise galement le fichier \fB"/usr/X11R6/lib/X11/xtel/xtel.lignes"\fP
 qui dfinit les lignes disponibles et la procdure de composition. Ce fichier est de
 la forme :
 .sp
@@ -128,7 +128,8 @@ la forme :
 .I "[Parit,]"
 .I "chat-script avec le modem"
 ,
-.I "delai maxi de rponse du modem en secondes."
+.I "delai maxi de rponse du modem en secondes"
+.I "[,temporisation entre commandes en millisecondes.]"
 .sp
 Et ce pour chaque ligne utilisable. Si le premier champs (nom du device) est rpt
 sur plusieurs lignes, cela signifie que plusieurs modem physiques sont associs au
@@ -157,15 +158,21 @@ Si le chat-script est remplace par la chaine \fIminitel2\fP, la ligne est defini
 comme utilisant un \fBMinitel 2\fP comme modem.
 .sp
 Si le chat-script est remplace par la chaine \fIminitel1\fP, la ligne est dfinie
-comme utilisant un \fBMinitel 1/1B\fI comme modem. A ce moment la, le menu "Services"
+comme utilisant un \fBMinitel 1/1B\fP comme modem. A ce moment la, le menu "Services"
 ne sera pas affich dans xtel et l'utilisateur devra composer son numro  la main
 (le M1/M1B ne sachant thoriquement pas composer de numro).
+.sp
+Le champ temporisation est optionnel et peut contenir une dure (en ms)
+d'attente entre l'envoi de chaque commande au modem dans la phase
+d'initialisation.  Il permet un meilleur support de certains anciens modems qui
+n'acceptaient pas de recevoir un flot de commande trop rapide.  S'il n'est pas
+prcis, aucune temporisation n'est effectue (c'est le comportement standard de \fIxteld\fP).
 .sp 2
 .B "Exemples :"
 .in +10
 .nf
 /dev/cua0,\\dat\\r OK atdt\\T\\r CONNECT,30
-v23,/dev/cua1,1200,7,E,\\dat\\r OK atdt\\T\\r CONNECT,30
+v23,/dev/cua1,1200,7,E,\\dat\\r OK atdt\\T\\r CONNECT,30,250
 tvr,/dev/cua2:rtscts,9600,8,N,\\dat\\r OK atdt\\T\\r CONNECT,30
 .fi
 .in -10
@@ -188,6 +195,12 @@ Le d
 secondes maxi. Si le dlai est dpass, \fIxteld\fP essayera sur la ligne suivante du fichier
 jusqu' un succs ou la fin du fichier.
 .sp
+La ligne
+.I v23
+dclare aussi une temporisation de
+.I 250ms
+entre chaque commande transmise au modem.
+.sp
 .B "Remarques :"
 .sp
 Le format du chat-script accepte les squences suivantes :