1 /* $NetBSD: ioctl.c,v 1.2 2001/12/31 20:18:28 thorpej Exp $ */
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
34 __RCSID("$NetBSD: ioctl.c,v 1.2 2001/12/31 20:18:28 thorpej Exp $");
45 #include <sys/types.h>
48 #if defined(__NetBSD__)
50 #elif defined(__bsdi__)
51 int openpty(int *, int *, char *, struct termios
*, struct winsize
*);
52 #elif defined(__FreeBSD__)
68 main(int argc
, char *argv
[])
71 char name
[128], buf
[128];
78 /* get terminal settings for later use */
79 if (tcgetattr(STDIN_FILENO
, &term
) == -1)
83 if (openpty(&m
, &s
, name
, &term
, NULL
) == -1)
91 /* wait for parent to get set up */
93 (void) printf("child1: exiting\n");
97 (void) printf("parent: spawned child1\n");
106 /* wait for parent to get upset */
108 /* drain the tty q */
109 if (read(m
, buf
, sizeof(buf
)) == -1)
111 (void) printf("child2: exiting\n");
115 (void) printf("parent: spawned child2\n");
119 /* set up a restarting signal handler */
120 (void) sigemptyset(&sa
.sa_mask
);
121 sa
.sa_handler
= sigchld
;
122 sa
.sa_flags
= SA_RESTART
;
123 if (sigaction(SIGCHLD
, &sa
, NULL
) == -1)
126 /* put something in the output q */
127 if (write(s
, "Hello world\n", 12) == -1)
130 /* ask for output to drain but don't drain it */
132 if (tcsetattr(s
, TCSADRAIN
, &term
) == -1) {
133 (void) printf("parent: tcsetattr: %s\n", strerror(errno
));
137 /* wait for last child */
138 sa
.sa_handler
= SIG_DFL
;
139 if (sigaction(SIGCHLD
, &sa
, NULL
) == -1)