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
28 * $FreeBSD: src/sbin/comcontrol/comcontrol.c,v 1.8.2.2 2001/08/01 06:01:51 obrien Exp $
29 * $DragonFly: src/sbin/comcontrol/comcontrol.c,v 1.2 2003/06/17 04:27:32 dillon Exp $
40 #include <sys/types.h>
41 #include <sys/ioctl.h>
47 "usage: comcontrol <filename> [dtrwait <n>] [drainwait <n>]\n");
52 main(int argc, char *argv[])
56 int print_dtrwait = 1, print_drainwait = 1;
57 int dtrwait = -1, drainwait = -1;
62 if (strcmp(argv[1], "-") == 0)
65 fd = open(argv[1], O_RDONLY|O_NONBLOCK, 0);
67 warn("couldn't open file %s", argv[1]);
72 if (ioctl(fd, TIOCMGDTRWAIT, &dtrwait) < 0) {
74 if (errno != ENOTTY) {
76 warn("TIOCMGDTRWAIT");
79 if (ioctl(fd, TIOCGDRAINWAIT, &drainwait) < 0) {
81 if (errno != ENOTTY) {
83 warn("TIOCGDRAINWAIT");
87 printf("dtrwait %d ", dtrwait);
89 printf("drainwait %d ", drainwait);
92 while (argv[2] != NULL) {
93 if (!strcmp(argv[2],"dtrwait")) {
96 if (argv[3] == NULL || !isdigit(argv[3][0]))
98 dtrwait = atoi(argv[3]);
100 } else if (!strcmp(argv[2],"drainwait")) {
103 if (argv[3] == NULL || !isdigit(argv[3][0]))
105 drainwait = atoi(argv[3]);
111 if (ioctl(fd, TIOCMSDTRWAIT, &dtrwait) < 0) {
113 warn("TIOCMSDTRWAIT");
116 if (drainwait >= 0) {
117 if (ioctl(fd, TIOCSDRAINWAIT, &drainwait) < 0) {
119 warn("TIOCSDRAINWAIT");