2 * Copyright (c) 1992 Christopher G. Demetriou
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote
14 * products derived from this software without specific written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
40 #include <sys/types.h>
41 #include <sys/ioctl.h>
43 static void usage(void);
49 "usage: comcontrol <filename> [dtrwait <n>] [drainwait <n>]\n");
54 main(int argc, char *argv[])
58 int print_dtrwait = 1, print_drainwait = 1;
59 int dtrwait = -1, drainwait = -1;
64 if (strcmp(argv[1], "-") == 0)
67 fd = open(argv[1], O_RDONLY|O_NONBLOCK, 0);
69 warn("couldn't open file %s", argv[1]);
74 if (ioctl(fd, TIOCMGDTRWAIT, &dtrwait) < 0) {
76 if (errno != ENOTTY) {
78 warn("TIOCMGDTRWAIT");
81 if (ioctl(fd, TIOCGDRAINWAIT, &drainwait) < 0) {
83 if (errno != ENOTTY) {
85 warn("TIOCGDRAINWAIT");
89 printf("dtrwait %d ", dtrwait);
91 printf("drainwait %d ", drainwait);
94 while (argv[2] != NULL) {
95 if (!strcmp(argv[2],"dtrwait")) {
98 if (argv[3] == NULL || !isdigit(argv[3][0]))
100 dtrwait = atoi(argv[3]);
102 } else if (!strcmp(argv[2],"drainwait")) {
105 if (argv[3] == NULL || !isdigit(argv[3][0]))
107 drainwait = atoi(argv[3]);
113 if (ioctl(fd, TIOCMSDTRWAIT, &dtrwait) < 0) {
115 warn("TIOCMSDTRWAIT");
118 if (drainwait >= 0) {
119 if (ioctl(fd, TIOCSDRAINWAIT, &drainwait) < 0) {
121 warn("TIOCSDRAINWAIT");