From b0e399e3c44a7791ef48b094c79f2a145cb9ed53 Mon Sep 17 00:00:00 2001 From: "Andrey A. Chernov" Date: Thu, 5 Jan 1995 00:03:06 +0000 Subject: [PATCH] Fight agaist hanging modems: add new drainwait option. Reviewed by: Bruce --- sbin/comcontrol/comcontrol.8 | 11 +++++++++ sbin/comcontrol/comcontrol.c | 39 +++++++++++++++++++++---------- sbin/i386/comcontrol/comcontrol.8 | 11 +++++++++ sbin/i386/comcontrol/comcontrol.c | 39 +++++++++++++++++++++---------- 4 files changed, 76 insertions(+), 24 deletions(-) diff --git a/sbin/comcontrol/comcontrol.8 b/sbin/comcontrol/comcontrol.8 index 698d314d26a9..20bf4d5d026f 100644 --- a/sbin/comcontrol/comcontrol.8 +++ b/sbin/comcontrol/comcontrol.8 @@ -24,6 +24,17 @@ Set the time to wait after dropping DTR to the given number. The units are hundredths of a second. The default is 300 hundredths, i.e., 3 seconds. +This option needed mainly to set proper recover time after +modem reset. +.El +.Bl -tag -width Fl +.It Cm drainwait Ar number +Set the time to wait for output drain +to the given number. +The units are seconds. +The default is 0, i.e. wait forever. +This option needed mainly to specify upper limit of minutes +to prevent modem hanging. .El .Pp The standard way to use diff --git a/sbin/comcontrol/comcontrol.c b/sbin/comcontrol/comcontrol.c index 40cf8d25c8a8..cb65f18990a7 100644 --- a/sbin/comcontrol/comcontrol.c +++ b/sbin/comcontrol/comcontrol.c @@ -38,35 +38,38 @@ void usage(char *progname) { - fprintf(stderr, "usage: %s [dtrwait ]\n", progname); + fprintf(stderr, "usage: %s [dtrwait ] [drainwait ]\n", progname); exit(1); } int main(int argc, char *argv[]) { int fd; - int res; - int dtrwait; + int res = 0; + int dtrwait = -1, drainwait = -1; if ((argc < 2) || (argc > 5)) usage(argv[0]); fd = open(argv[1], O_RDONLY|O_NONBLOCK, 0); if (fd < 0) { - fprintf(stderr, "%s: couldn't open file %s\n", argv[0], argv[1]); perror("open"); - exit(1); + fprintf(stderr, "%s: couldn't open file %s\n", argv[0], argv[1]); + return 1; } if (argc == 2) { if (ioctl(fd, TIOCMGDTRWAIT, &dtrwait) < 0) { + res = 1; perror("TIOCMGDTRWAIT"); - exit(1); } - printf("dtrwait %d\n", dtrwait); + if (ioctl(fd, TIOCGDRAINWAIT, &drainwait) < 0) { + res = 1; + perror("TIOCGDRAINWAIT"); + } + printf("dtrwait %d drainwait %d\n", dtrwait, drainwait); } else { char *prg = argv[0]; - res = dtrwait = -1; while (argv[2] != NULL) { if (!strcmp(argv[2],"dtrwait")) { if (dtrwait >= 0) @@ -75,18 +78,30 @@ int main(int argc, char *argv[]) usage(prg); dtrwait = atoi(argv[3]); argv += 2; - } else { + } else if (!strcmp(argv[2],"drainwait")) { + if (drainwait >= 0) + usage(prg); + if (argv[3] == NULL || !isdigit(argv[3][0])) + usage(prg); + drainwait = atoi(argv[3]); + argv += 2; + } else usage(prg); - } } if (dtrwait >= 0) { if (ioctl(fd, TIOCMSDTRWAIT, &dtrwait) < 0) { + res = 1; perror("TIOCMSDTRWAIT"); - exit(1); + } + } + if (drainwait >= 0) { + if (ioctl(fd, TIOCSDRAINWAIT, &drainwait) < 0) { + res = 1; + perror("TIOCSDRAINWAIT"); } } } close(fd); - exit(0); + return res; } diff --git a/sbin/i386/comcontrol/comcontrol.8 b/sbin/i386/comcontrol/comcontrol.8 index 698d314d26a9..20bf4d5d026f 100644 --- a/sbin/i386/comcontrol/comcontrol.8 +++ b/sbin/i386/comcontrol/comcontrol.8 @@ -24,6 +24,17 @@ Set the time to wait after dropping DTR to the given number. The units are hundredths of a second. The default is 300 hundredths, i.e., 3 seconds. +This option needed mainly to set proper recover time after +modem reset. +.El +.Bl -tag -width Fl +.It Cm drainwait Ar number +Set the time to wait for output drain +to the given number. +The units are seconds. +The default is 0, i.e. wait forever. +This option needed mainly to specify upper limit of minutes +to prevent modem hanging. .El .Pp The standard way to use diff --git a/sbin/i386/comcontrol/comcontrol.c b/sbin/i386/comcontrol/comcontrol.c index 40cf8d25c8a8..cb65f18990a7 100644 --- a/sbin/i386/comcontrol/comcontrol.c +++ b/sbin/i386/comcontrol/comcontrol.c @@ -38,35 +38,38 @@ void usage(char *progname) { - fprintf(stderr, "usage: %s [dtrwait ]\n", progname); + fprintf(stderr, "usage: %s [dtrwait ] [drainwait ]\n", progname); exit(1); } int main(int argc, char *argv[]) { int fd; - int res; - int dtrwait; + int res = 0; + int dtrwait = -1, drainwait = -1; if ((argc < 2) || (argc > 5)) usage(argv[0]); fd = open(argv[1], O_RDONLY|O_NONBLOCK, 0); if (fd < 0) { - fprintf(stderr, "%s: couldn't open file %s\n", argv[0], argv[1]); perror("open"); - exit(1); + fprintf(stderr, "%s: couldn't open file %s\n", argv[0], argv[1]); + return 1; } if (argc == 2) { if (ioctl(fd, TIOCMGDTRWAIT, &dtrwait) < 0) { + res = 1; perror("TIOCMGDTRWAIT"); - exit(1); } - printf("dtrwait %d\n", dtrwait); + if (ioctl(fd, TIOCGDRAINWAIT, &drainwait) < 0) { + res = 1; + perror("TIOCGDRAINWAIT"); + } + printf("dtrwait %d drainwait %d\n", dtrwait, drainwait); } else { char *prg = argv[0]; - res = dtrwait = -1; while (argv[2] != NULL) { if (!strcmp(argv[2],"dtrwait")) { if (dtrwait >= 0) @@ -75,18 +78,30 @@ int main(int argc, char *argv[]) usage(prg); dtrwait = atoi(argv[3]); argv += 2; - } else { + } else if (!strcmp(argv[2],"drainwait")) { + if (drainwait >= 0) + usage(prg); + if (argv[3] == NULL || !isdigit(argv[3][0])) + usage(prg); + drainwait = atoi(argv[3]); + argv += 2; + } else usage(prg); - } } if (dtrwait >= 0) { if (ioctl(fd, TIOCMSDTRWAIT, &dtrwait) < 0) { + res = 1; perror("TIOCMSDTRWAIT"); - exit(1); + } + } + if (drainwait >= 0) { + if (ioctl(fd, TIOCSDRAINWAIT, &drainwait) < 0) { + res = 1; + perror("TIOCSDRAINWAIT"); } } } close(fd); - exit(0); + return res; }