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.3 2005/03/20 14:07:43 liamfoy Exp $
32 #include <sys/types.h>
33 #include <sys/ioctl.h>
48 "usage: comcontrol <filename> [dtrwait <n>] [drainwait <n>]\n");
53 main(int argc
, char *argv
[])
57 int print_dtrwait
= 1, print_drainwait
= 1;
58 int dtrwait
= -1, drainwait
= -1;
63 if (strcmp(argv
[1], "-") == 0) {
66 fd
= open(argv
[1], O_RDONLY
| O_NONBLOCK
, 0);
68 warn("couldn't open file %s", argv
[1]);
73 if (ioctl(fd
, TIOCMGDTRWAIT
, &dtrwait
) < 0) {
75 if (errno
!= ENOTTY
) {
77 warn("TIOCMGDTRWAIT");
80 if (ioctl(fd
, TIOCGDRAINWAIT
, &drainwait
) < 0) {
82 if (errno
!= ENOTTY
) {
84 warn("TIOCGDRAINWAIT");
88 printf("dtrwait %d ", dtrwait
);
90 printf("drainwait %d ", drainwait
);
93 while (argv
[2] != NULL
) {
94 if (strcmp(argv
[2],"dtrwait") == 0) {
97 if (argv
[3] == NULL
|| !isdigit(argv
[3][0]))
99 dtrwait
= atoi(argv
[3]);
101 } else if (strcmp(argv
[2],"drainwait") == 0) {
104 if (argv
[3] == NULL
|| !isdigit(argv
[3][0]))
106 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");