I have been getting some problems with my systems during startup if the
modem cannot synchronize. I have added a timeout to the master side of
the modem _run code to get round this. The timeout is controllable from
the command line with a -T flag. Feeding in -T 0 gets the old behaviour
back (by a side effect on the alarm signal call).
I still need to add some code to reap the child when the timeout happens
but for now at least the boxen do not hang.
My long term intention is to add a mechanism like daemontools to our
systems and keep the adsl service restarting when it fails. Using the
timeout to assure that it does return to the master program.
Patch is against the 1.2_beta2 release.
Regards,
--
Howard Wilkinson
Email:
[EMAIL PROTECTED]
Coherent Technology Limited
Tel:
+44(20)7690-7075
33 Belgrade Road, Stoke Newington
Fax:
+44(20)7923-0110
London N16 8DH, United Kingdom
Mobile:
+44(7980)639379
-- Attached file included as plaintext by Listar --
-- File: speedtouch-1.2-coherent.patch
diff -ruN speedtouch-1.2_beta2-save/doc-linux/man/modem_run.1
speedtouch-1.2_beta2/doc-linux/man/modem_run.1
--- speedtouch-1.2_beta2-save/doc-linux/man/modem_run.1 2003-08-13 19:02:06.000000000
+0100
+++ speedtouch-1.2_beta2/doc-linux/man/modem_run.1 2003-11-13 17:43:26.000000000
+0000
@@ -25,6 +25,9 @@
- 0 Error messages
- 1 level 0 + State messages
- 2 level 1 + USB packet dumping
+.TP
+\fB-T number\fR
+sets the sychronization timeout. The default is 30 seconds.
.SH RETURN VALUES
.TP
Normally, exit status is 0 if the firmware file has been successfully loaded into
SpeedTouch USB modem and adsl link has gone up.
diff -ruN speedtouch-1.2_beta2-save/src/modem_run.c
speedtouch-1.2_beta2/src/modem_run.c
--- speedtouch-1.2_beta2-save/src/modem_run.c 2003-08-13 19:02:06.000000000 +0100
+++ speedtouch-1.2_beta2/src/modem_run.c 2003-11-13 17:47:18.000000000 +0000
@@ -29,6 +29,10 @@
* timeout errors.
*
* $Id: modem_run.c,v 1.31 2003/06/27 22:00:55 edgomez Exp $
+*
+* Modified: 13th November 2003 - Howard Wilkinson <[EMAIL PROTECTED]>
+* Added a timeout to the synchronisation negotiation
+* needed to allow a startup to complete.
*/
#ifndef _MODEM_RUN_C_
@@ -94,6 +98,7 @@
static int dl_512_first = 1; /* Try to download 512 bytes before first op */
static int link_up = 0; /* Used to gives link state between 2 processes */
+static int timed_out = 0; /* Used to give a timeout signal inside the wait loop */
static int sb = 0; /* Software buffering */
static int signal_kernel = 0;/* Kernel driver notification */
@@ -368,6 +373,7 @@
static unsigned char give_char(unsigned char c);
static void signal_usr2(int signal);
+static void signal_alrm(int signal);
/*****************************************************************************
* Main function
@@ -388,6 +394,7 @@
const char * file = NULL;
char *devicename = NULL;
char *user;
+ int timeout = 30; /* Wait for 30 seconds before giving up */
/*
* Security stuff
@@ -432,6 +439,8 @@
file = argv[++i];
else if(strcmp(argv[i], "-d") == 0 && i + 1 < argc)
devicename = argv[++i];
+ else if (strcmp(argv[i], "-T") == 0 && i + 1 < argc)
+ timeout = atoi(argv[++i]);
else if (strcmp(argv[i],"--help")==0)
usage();
else
@@ -558,6 +567,7 @@
* the up state of the link.
*/
signal(SIGUSR2 , signal_usr2);
+ signal(SIGALRM , signal_alrm);
/*
* Start a subprocess (the so called daemon) to make sure the
@@ -576,15 +586,23 @@
* New method : The child which reads the interrupt endpoint
* notices the parent process of the up link
*/
- while(!link_up)
+
+ alarm(timeout);
+
+ while(!link_up && !timed_out)
pause();
- /* The physical adsl link has been established */
- report(0, REPORT_INFO, "ADSL synchronization has been obtained\n");
+ alarm(0);
- /* We can print the adsl link state (speed) */
- get_state(fdusb,buf);
- print_state(buf);
+ if (timed_out) {
+ report(0, REPORT_ERROR, "ADSL synchronization failed - timed out\n");
+ } else {
+ /* The physical adsl link has been established */
+ report(0, REPORT_INFO, "ADSL synchronization has been obtained\n");
+ /* We can print the adsl link state (speed) */
+ get_state(fdusb,buf);
+ print_state(buf);
+ }
/* Close all */
if (pusb_release_interface(fdusb,0) < 0)
@@ -600,7 +618,7 @@
report_stop();
- return(0);
+ if(timed_out) return(-1); else return(0);
}
@@ -624,6 +642,7 @@
fprintf(stderr, " -f microcode : upload this microcode file first\n");
fprintf(stderr, " -d device : defines the device to use\n");
fprintf(stderr, " -k : using the kernel mode driver\n");
+ fprintf(stderr, " -T seconds : synchronization timeout\n");
fprintf(stderr, " --help : this message\n");
exit(-1);
@@ -1136,7 +1155,7 @@
/* Bad the line is down */
if(buf[OFFSET_7] != 0x20 && prevbuf[OFFSET_7]
== 0x20) {
report(1, REPORT_INFO, "ADSL link went
down\n");
- if(signal_kernel) {
+ if(signal_kernel) {
sleep(1);
pusb_ioctl(fdusb, 1, 2, NULL);
}
@@ -1160,7 +1179,16 @@
{
link_up = ~link_up;
+ if(link_up)alarm(0);
+}
+static void signal_alrm(int signal)
+{
+ /*
+ * Connection attempt timed out
+ */
+ link_up = 0;
+ timed_out = 1;
}
/*****************************************************************************
Liste de diffusion modem ALCATEL SpeedTouch USB
Pour se d�sinscrire : mailto:[EMAIL PROTECTED]