blob: c5648234bd37eeb8e3d0d399d4212d18f253a1e7 [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
2 *
3 * Copyright (c) International Business Machines Corp., 2001
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
Wanlong Gao4548c6c2012-10-19 18:03:36 +080017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
plars865695b2001-08-27 22:15:12 +000018 */
19
20/*
21 * NAME
22 * ioctl02.c
23 *
24 * DESCRIPTION
25 * Testcase to test the TCGETA, and TCSETA ioctl implementations for
26 * the tty driver
27 *
28 * ALGORITHM
29 * In this test, the parent and child open the parentty and the childtty
30 * respectively. After opening the childtty the child flushes the stream
31 * and sends a SIGUSR1 to the parent (thereby asking it to continue its
32 * testing). The parent, which was waiting for this signal to arrive, now
33 * starts the testing. It issues a TCGETA ioctl to get all the tty
34 * parameters. It then changes them to known values by issuing a TCSETA
35 * ioctl. Then the parent issues a TCGETA ioctl again and compares the
36 * received values with what it had set earlier. The test fails if TCGETA
37 * or TCSETA fails, or if the received values don't match those that were
38 * set. The parent does all the testing, the requirement of the child
39 * process is to moniter the testing done by the parent, and hence the
40 * child just waits for the parent.
41 *
42 * USAGE: <for command-line>
43 * ioctl02 -D /dev/tty[0-9] [-c n] [-f] [-i n] [-I x] [-P x] [-t]
44 * where, -c n : Run n copies concurrently.
45 * -f : Turn off functionality Testing.
46 * -i n : Execute test n times.
47 * -I x : Execute test for x seconds.
48 * -P x : Pause for x seconds between iterations.
49 * -t : Turn on syscall timing.
50 *
51 * HISTORY
52 * 07/2001 Ported by Wayne Boyer
53 *
54 * RESTRICTIONS
55 * test must be run with the -D option
56 * test may have to be run as root depending on the tty permissions
57 */
58
59#include <stdio.h>
plars865695b2001-08-27 22:15:12 +000060#include <termio.h>
61#include <fcntl.h>
62#include <signal.h>
63#include <errno.h>
Steven Jackson249f4052016-12-13 16:16:00 +000064#include <sys/wait.h>
robbiew0f24d852003-03-26 21:07:16 +000065#include <sys/types.h>
66#include <sys/stat.h>
67#include <sys/ioctl.h>
68#include <sys/termios.h>
plars865695b2001-08-27 22:15:12 +000069#include "test.h"
plars865695b2001-08-27 22:15:12 +000070
71#define CNUL 0
72
73char *TCID = "ioctl02";
74int TST_TOTAL = 1;
plars865695b2001-08-27 22:15:12 +000075
Wanlong Gao6633ce92012-11-05 11:19:57 +080076static struct termio termio, save_io;
plars865695b2001-08-27 22:15:12 +000077
Wanlong Gao6633ce92012-11-05 11:19:57 +080078static char *parenttty, *childtty;
79static int parentfd, childfd;
80static int parentpid, childpid;
81static volatile int sigterm, sigusr1, sigusr2;
82static int closed = 1;
plars865695b2001-08-27 22:15:12 +000083
Wanlong Gao6633ce92012-11-05 11:19:57 +080084static int do_child_setup(void);
85static int do_parent_setup(void);
86static int run_ptest(void);
87static int run_ctest(void);
88static int chk_tty_parms();
89static void setup(void);
90static void cleanup(void);
91static void help(void);
92static void do_child(void);
robbiewd34d5812005-07-11 22:28:09 +000093void do_child_uclinux(void);
Wanlong Gao6633ce92012-11-05 11:19:57 +080094static void sigterm_handler(void);
plars865695b2001-08-27 22:15:12 +000095
Wanlong Gao6633ce92012-11-05 11:19:57 +080096static int Devflag;
97static char *devname;
plars865695b2001-08-27 22:15:12 +000098
Wanlong Gao6633ce92012-11-05 11:19:57 +080099static option_t options[] = {
plars865695b2001-08-27 22:15:12 +0000100 {"D:", &Devflag, &devname},
101 {NULL, NULL, NULL}
102};
103
robbiew0f24d852003-03-26 21:07:16 +0000104int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +0000105{
Cyril Hrubis89af32a2012-10-24 16:39:11 +0200106 int lc;
plars865695b2001-08-27 22:15:12 +0000107 int rval;
plars865695b2001-08-27 22:15:12 +0000108
Cyril Hrubisd6d11d02015-03-09 17:35:43 +0100109 tst_parse_opts(ac, av, options, &help);
110
robbiewd34d5812005-07-11 22:28:09 +0000111#ifdef UCLINUX
112 maybe_run_child(&do_child_uclinux, "dS", &parentpid, &childtty);
113#endif
114
Garrett Cooper2b6b1ee2010-12-19 05:07:50 -0800115 if (!Devflag)
116 tst_brkm(TBROK, NULL, "You must specify a tty device with "
plars865695b2001-08-27 22:15:12 +0000117 "the -D option.");
plars865695b2001-08-27 22:15:12 +0000118
Cyril Hrubisd1e794d2015-07-30 23:52:51 +0200119 tst_require_root();
subrata_modaked216842008-09-24 15:58:12 +0000120
plars865695b2001-08-27 22:15:12 +0000121 setup();
122
plars865695b2001-08-27 22:15:12 +0000123 for (lc = 0; TEST_LOOPING(lc); lc++) {
124
Caspar Zhangd59a6592013-03-07 14:59:12 +0800125 tst_count = 0;
plars865695b2001-08-27 22:15:12 +0000126
127 parenttty = devname;
128 childtty = devname;
129
130 parentpid = getpid();
131
Wanlong Gao6633ce92012-11-05 11:19:57 +0800132 childpid = FORK_OR_VFORK();
133 if (childpid < 0)
Garrett Cooperff29dd12010-12-19 05:05:40 -0800134 tst_brkm(TBROK, cleanup, "fork failed");
plars865695b2001-08-27 22:15:12 +0000135
subrata_modak56207ce2009-03-23 13:35:39 +0000136 if (childpid == 0) { /* child */
robbiewd34d5812005-07-11 22:28:09 +0000137#ifdef UCLINUX
Garrett Cooperff29dd12010-12-19 05:05:40 -0800138 if (self_exec(av[0], "dS", parentpid, childtty) < 0)
robbiewd34d5812005-07-11 22:28:09 +0000139 tst_brkm(TBROK, cleanup, "self_exec failed");
robbiewd34d5812005-07-11 22:28:09 +0000140#else
141 do_child();
142#endif
plars865695b2001-08-27 22:15:12 +0000143 }
144
Garrett Cooperff29dd12010-12-19 05:05:40 -0800145 while (!sigusr1)
plars865695b2001-08-27 22:15:12 +0000146 sleep(1);
plars865695b2001-08-27 22:15:12 +0000147
148 sigusr1 = 0;
149
Wanlong Gao6633ce92012-11-05 11:19:57 +0800150 parentfd = do_parent_setup();
151 if (parentfd < 0) {
plars865695b2001-08-27 22:15:12 +0000152 kill(childpid, SIGTERM);
153 waitpid(childpid, NULL, 0);
154 cleanup();
Garrett Cooperff29dd12010-12-19 05:05:40 -0800155 }
plars865695b2001-08-27 22:15:12 +0000156
157 /* run the parent test */
Wanlong Gao6633ce92012-11-05 11:19:57 +0800158 rval = run_ptest();
159 if (rval == -1) {
subrata_modak4bb656a2009-02-26 12:02:09 +0000160 /*
plars865695b2001-08-27 22:15:12 +0000161 * Parent cannot set/get ioctl parameters.
162 * SIGTERM the child and cleanup.
163 */
164 kill(childpid, SIGTERM);
165 waitpid(childpid, NULL, 0);
166 cleanup();
167 }
168
Garrett Cooperff29dd12010-12-19 05:05:40 -0800169 if (rval != 0)
plars865695b2001-08-27 22:15:12 +0000170 tst_resm(TFAIL, "TCGETA/TCSETA tests FAILED with "
171 "%d %s", rval, rval > 1 ? "errors" : "error");
Garrett Cooperff29dd12010-12-19 05:05:40 -0800172 else
plars865695b2001-08-27 22:15:12 +0000173 tst_resm(TPASS, "TCGETA/TCSETA tests SUCCEEDED");
plars865695b2001-08-27 22:15:12 +0000174
Garrett Cooperff29dd12010-12-19 05:05:40 -0800175 /* FIXME: check return codes. */
plars865695b2001-08-27 22:15:12 +0000176 (void)kill(childpid, SIGTERM);
177 (void)waitpid(childpid, NULL, 0);
178
179 /*
180 * Clean up things from the parent by restoring the
181 * tty device information that was saved in setup()
182 * and closing the tty file descriptor.
183 */
Garrett Cooperff29dd12010-12-19 05:05:40 -0800184 if (ioctl(parentfd, TCSETA, &save_io) == -1)
plars865695b2001-08-27 22:15:12 +0000185 tst_resm(TINFO, "ioctl restore failed in main");
Garrett Cooperff29dd12010-12-19 05:05:40 -0800186 if (close(parentfd) == -1)
plars865695b2001-08-27 22:15:12 +0000187 tst_brkm(TBROK, cleanup, "close() failed in main");
plars865695b2001-08-27 22:15:12 +0000188
plars865695b2001-08-27 22:15:12 +0000189 closed = 1;
190 }
191 cleanup();
192
Garrett Cooper53740502010-12-16 00:04:01 -0800193 tst_exit();
plars865695b2001-08-27 22:15:12 +0000194}
195
Wanlong Gao6633ce92012-11-05 11:19:57 +0800196static void do_child(void)
subrata_modak56207ce2009-03-23 13:35:39 +0000197{
Wanlong Gao6633ce92012-11-05 11:19:57 +0800198 childfd = do_child_setup();
199 if (childfd < 0)
robbiewd34d5812005-07-11 22:28:09 +0000200 _exit(1);
robbiewd34d5812005-07-11 22:28:09 +0000201 run_ctest();
202 _exit(0);
203}
204
Wanlong Gao6633ce92012-11-05 11:19:57 +0800205void do_child_uclinux(void)
robbiewd34d5812005-07-11 22:28:09 +0000206{
207 struct sigaction act;
208
209 /* Set up the signal handlers again */
210 act.sa_handler = (void *)sigterm_handler;
211 act.sa_flags = 0;
Jan Stancekc5532e42013-05-14 11:59:33 +0200212 sigemptyset(&act.sa_mask);
robbiewd34d5812005-07-11 22:28:09 +0000213 (void)sigaction(SIGTERM, &act, 0);
subrata_modakbdbaec52009-02-26 12:14:51 +0000214
robbiewd34d5812005-07-11 22:28:09 +0000215 /* Run the normal child */
216 do_child();
217}
218
plars865695b2001-08-27 22:15:12 +0000219/*
220 * run_ptest() - setup the various termio structure values and issue
221 * the TCSETA ioctl call with the TEST macro.
222 */
Wanlong Gao6633ce92012-11-05 11:19:57 +0800223static int run_ptest(void)
plars865695b2001-08-27 22:15:12 +0000224{
225 int i, rval;
226
227 /* Use "old" line discipline */
228 termio.c_line = 0;
229
230 /* Set control modes */
subrata_modak56207ce2009-03-23 13:35:39 +0000231 termio.c_cflag = B50 | CS7 | CREAD | PARENB | PARODD | CLOCAL;
plars865695b2001-08-27 22:15:12 +0000232
233 /* Set control chars. */
subrata_modak56207ce2009-03-23 13:35:39 +0000234 for (i = 0; i < NCC; i++) {
Wanlong Gao6633ce92012-11-05 11:19:57 +0800235 if (i == VEOL2)
plars865695b2001-08-27 22:15:12 +0000236 continue;
plars865695b2001-08-27 22:15:12 +0000237 termio.c_cc[i] = CSTART;
238 }
239
240 /* Set local modes. */
subrata_modak56207ce2009-03-23 13:35:39 +0000241 termio.c_lflag =
242 ((unsigned short)(ISIG | ICANON | XCASE | ECHO | ECHOE | NOFLSH));
plars865695b2001-08-27 22:15:12 +0000243
244 /* Set input modes. */
subrata_modak56207ce2009-03-23 13:35:39 +0000245 termio.c_iflag =
246 BRKINT | IGNPAR | INPCK | ISTRIP | ICRNL | IUCLC | IXON | IXANY |
247 IXOFF;
plars865695b2001-08-27 22:15:12 +0000248
249 /* Set output modes. */
subrata_modak56207ce2009-03-23 13:35:39 +0000250 termio.c_oflag = OPOST | OLCUC | ONLCR | ONOCR;
plars865695b2001-08-27 22:15:12 +0000251
252 TEST(ioctl(parentfd, TCSETA, &termio));
253
254 if (TEST_RETURN < 0) {
255 tst_resm(TFAIL, "ioctl TCSETA failed : "
256 "errno = %d", TEST_ERRNO);
Wanlong Gao6633ce92012-11-05 11:19:57 +0800257 return -1;
plars865695b2001-08-27 22:15:12 +0000258 }
259
Cyril Hrubise38b9612014-06-02 17:20:57 +0200260 /* Get termio and see if all parameters actually got set */
261 rval = ioctl(parentfd, TCGETA, &termio);
262 if (rval < 0) {
263 tst_resm(TFAIL, "ioctl TCGETA failed. Ending test.");
264 return -1;
plars865695b2001-08-27 22:15:12 +0000265 }
Cyril Hrubise38b9612014-06-02 17:20:57 +0200266
267 return chk_tty_parms();
plars865695b2001-08-27 22:15:12 +0000268}
269
Wanlong Gao6633ce92012-11-05 11:19:57 +0800270static int run_ctest(void)
plars865695b2001-08-27 22:15:12 +0000271{
plars865695b2001-08-27 22:15:12 +0000272 /*
273 * Wait till the parent has finished testing.
274 */
Wanlong Gao6633ce92012-11-05 11:19:57 +0800275 while (!sigterm)
plars865695b2001-08-27 22:15:12 +0000276 sleep(1);
Wanlong Gao6633ce92012-11-05 11:19:57 +0800277
plars865695b2001-08-27 22:15:12 +0000278 sigterm = 0;
279
280 tst_resm(TINFO, "child: Got SIGTERM from parent.");
281
Wanlong Gao6633ce92012-11-05 11:19:57 +0800282 if (close(childfd) == -1)
plars865695b2001-08-27 22:15:12 +0000283 tst_resm(TINFO, "close() in run_ctest() failed");
subrata_modak43337a32009-02-26 11:43:51 +0000284 return 0;
plars865695b2001-08-27 22:15:12 +0000285}
286
Wanlong Gao6633ce92012-11-05 11:19:57 +0800287static int chk_tty_parms(void)
plars865695b2001-08-27 22:15:12 +0000288{
289 int i, flag = 0;
290
291 if (termio.c_line != 0) {
292 tst_resm(TINFO, "line discipline has incorrect value %o",
293 termio.c_line);
294 flag++;
295 }
Wanlong Gao6633ce92012-11-05 11:19:57 +0800296 /*
297 * The following Code Sniffet is disabled to check the value of c_cflag
298 * as it seems that due to some changes from 2.6.24 onwards, this
299 * setting is not done properly for either of (B50|CS7|CREAD|PARENB|
300 * PARODD|CLOCAL|(CREAD|HUPCL|CLOCAL).
301 * However, it has been observed that other flags are properly set.
302 */
303#if 0
Wanlong Gao354ebb42012-12-07 10:10:04 +0800304 if (termio.c_cflag != (B50 | CS7 | CREAD | PARENB | PARODD | CLOCAL)) {
Wanlong Gao6633ce92012-11-05 11:19:57 +0800305 tst_resm(TINFO, "cflag has incorrect value. %o",
306 termio.c_cflag);
307 flag++;
308 }
309#endif
plars865695b2001-08-27 22:15:12 +0000310
subrata_modak56207ce2009-03-23 13:35:39 +0000311 for (i = 0; i < NCC; i++) {
plars865695b2001-08-27 22:15:12 +0000312 if (i == VEOL2) {
313 if (termio.c_cc[VEOL2] == CNUL) {
314 continue;
315 } else {
316 tst_resm(TINFO, "control char %d has "
317 "incorrect value %d %d", i,
subrata_modak4bb656a2009-02-26 12:02:09 +0000318 termio.c_cc[i], CNUL);
plars865695b2001-08-27 22:15:12 +0000319 flag++;
320 continue;
321 }
322 }
323
324 if (termio.c_cc[i] != CSTART) {
325 tst_resm(TINFO, "control char %d has incorrect "
326 "value %d.", i, termio.c_cc[i]);
327 flag++;
328 }
329 }
330
subrata_modak56207ce2009-03-23 13:35:39 +0000331 if (!
332 (termio.c_lflag
333 && (ISIG | ICANON | XCASE | ECHO | ECHOE | NOFLSH))) {
plars865695b2001-08-27 22:15:12 +0000334 tst_resm(TINFO, "lflag has incorrect value. %o",
335 termio.c_lflag);
336 flag++;
337 }
338
subrata_modak56207ce2009-03-23 13:35:39 +0000339 if (!
340 (termio.c_iflag
341 && (BRKINT | IGNPAR | INPCK | ISTRIP | ICRNL | IUCLC | IXON | IXANY
342 | IXOFF))) {
plars865695b2001-08-27 22:15:12 +0000343 tst_resm(TINFO, "iflag has incorrect value. %o",
344 termio.c_iflag);
345 flag++;
346 }
347
subrata_modak56207ce2009-03-23 13:35:39 +0000348 if (!(termio.c_oflag && (OPOST | OLCUC | ONLCR | ONOCR))) {
plars865695b2001-08-27 22:15:12 +0000349 tst_resm(TINFO, "oflag has incorrect value. %o",
350 termio.c_oflag);
351 flag++;
352 }
353
Wanlong Gao6633ce92012-11-05 11:19:57 +0800354 if (!flag)
plars865695b2001-08-27 22:15:12 +0000355 tst_resm(TINFO, "termio values are set as expected");
plars865695b2001-08-27 22:15:12 +0000356
Wanlong Gao6633ce92012-11-05 11:19:57 +0800357 return flag;
plars865695b2001-08-27 22:15:12 +0000358}
359
Wanlong Gao6633ce92012-11-05 11:19:57 +0800360static int do_parent_setup(void)
plars865695b2001-08-27 22:15:12 +0000361{
362 int pfd;
363
Wanlong Gao6633ce92012-11-05 11:19:57 +0800364 pfd = open(parenttty, O_RDWR, 0777);
365 if (pfd < 0)
plars865695b2001-08-27 22:15:12 +0000366 tst_brkm(TBROK, cleanup, "Could not open %s in "
367 "do_parent_setup(), errno = %d", parenttty, errno);
plars865695b2001-08-27 22:15:12 +0000368
369 /* unset the closed flag */
370 closed = 0;
subrata_modakbdbaec52009-02-26 12:14:51 +0000371
plars865695b2001-08-27 22:15:12 +0000372 /* flush tty queues to remove old output */
Garrett Cooperff29dd12010-12-19 05:05:40 -0800373 if (ioctl(pfd, TCFLSH, 2) < 0)
plars865695b2001-08-27 22:15:12 +0000374 tst_brkm(TBROK, cleanup, "ioctl TCFLSH failed : "
375 "errno = %d", errno);
Wanlong Gao6633ce92012-11-05 11:19:57 +0800376 return pfd;
plars865695b2001-08-27 22:15:12 +0000377}
378
Wanlong Gao6633ce92012-11-05 11:19:57 +0800379static int do_child_setup(void)
plars865695b2001-08-27 22:15:12 +0000380{
381 int cfd;
382
Wanlong Gao6633ce92012-11-05 11:19:57 +0800383 cfd = open(childtty, O_RDWR, 0777);
384 if (cfd < 0) {
plars865695b2001-08-27 22:15:12 +0000385 tst_resm(TINFO, "Could not open %s in do_child_setup(), errno "
386 "= %d", childtty, errno);
387 /* signal the parent so we don't hang the test */
388 kill(parentpid, SIGUSR1);
Wanlong Gao6633ce92012-11-05 11:19:57 +0800389 return -1;
plars865695b2001-08-27 22:15:12 +0000390 }
391
392 /* flush tty queues to remove old output */
393 if (ioctl(cfd, TCFLSH, 2) < 0) {
394 tst_resm(TINFO, "ioctl TCFLSH failed. : errno = %d", errno);
395 /* signal the parent so we don't hang the test */
396 kill(parentpid, SIGUSR1);
Wanlong Gao6633ce92012-11-05 11:19:57 +0800397 return -1;
plars865695b2001-08-27 22:15:12 +0000398 }
399
400 /* tell the parent that we're done */
401 kill(parentpid, SIGUSR1);
402
Wanlong Gao6633ce92012-11-05 11:19:57 +0800403 return cfd;
plars865695b2001-08-27 22:15:12 +0000404}
405
406/*
407 * Define the signals handlers here.
408 */
Wanlong Gao6633ce92012-11-05 11:19:57 +0800409static void sigterm_handler(void)
plars865695b2001-08-27 22:15:12 +0000410{
411 sigterm = 1;
412}
413
Wanlong Gao6633ce92012-11-05 11:19:57 +0800414static void sigusr1_handler(void)
plars865695b2001-08-27 22:15:12 +0000415{
416 sigusr1 = 1;
417}
418
Wanlong Gao6633ce92012-11-05 11:19:57 +0800419static void sigusr2_handler(void)
plars865695b2001-08-27 22:15:12 +0000420{
421 sigusr2 = 1;
422}
423
Wanlong Gao6633ce92012-11-05 11:19:57 +0800424static void help(void)
plars865695b2001-08-27 22:15:12 +0000425{
426 printf(" -D <tty device> : for example, /dev/tty[0-9]\n");
427}
428
Wanlong Gao6633ce92012-11-05 11:19:57 +0800429static void setup(void)
plars865695b2001-08-27 22:15:12 +0000430{
431 int fd;
432 struct sigaction act;
433
Garrett Cooperff29dd12010-12-19 05:05:40 -0800434 /* XXX: TERRNO required all over the place */
Wanlong Gao6633ce92012-11-05 11:19:57 +0800435 fd = open(devname, O_RDWR, 0777);
436 if (fd < 0)
Garrett Cooperff29dd12010-12-19 05:05:40 -0800437 tst_brkm(TBROK, NULL, "Could not open %s in "
plars865695b2001-08-27 22:15:12 +0000438 "setup(), errno = %d", devname, errno);
subrata_modakbdbaec52009-02-26 12:14:51 +0000439
plars865695b2001-08-27 22:15:12 +0000440 /* Save the current device information - to be restored in cleanup() */
Garrett Cooperff29dd12010-12-19 05:05:40 -0800441 if (ioctl(fd, TCGETA, &save_io) < 0)
plars865695b2001-08-27 22:15:12 +0000442 tst_brkm(TBROK, cleanup, "TCGETA ioctl failed in "
Garrett Cooperff29dd12010-12-19 05:05:40 -0800443 "do_parent_setup");
plars865695b2001-08-27 22:15:12 +0000444
445 /* Close the device */
Garrett Cooperff29dd12010-12-19 05:05:40 -0800446 if (close(fd) == -1)
447 tst_brkm(TBROK, cleanup, "close failed in setup");
plars865695b2001-08-27 22:15:12 +0000448
449 /* Set up the signal handlers */
450 act.sa_handler = (void *)sigterm_handler;
451 act.sa_flags = 0;
Jan Stancekc5532e42013-05-14 11:59:33 +0200452 sigemptyset(&act.sa_mask);
plars865695b2001-08-27 22:15:12 +0000453 (void)sigaction(SIGTERM, &act, 0);
454
455 act.sa_handler = (void *)sigusr1_handler;
456 act.sa_flags = 0;
457 (void)sigaction(SIGUSR1, &act, 0);
458
459 act.sa_handler = (void *)sigusr2_handler;
460 act.sa_flags = 0;
461 (void)sigaction(SIGUSR2, &act, 0);
462
plarsd93a8e72001-11-30 20:38:48 +0000463 act.sa_handler = SIG_IGN;
464 act.sa_flags = 0;
465 (void)sigaction(SIGTTOU, &act, 0);
466
plars865695b2001-08-27 22:15:12 +0000467 sigterm = sigusr1 = sigusr2 = 0;
468
plars865695b2001-08-27 22:15:12 +0000469 TEST_PAUSE;
470}
471
Wanlong Gao6633ce92012-11-05 11:19:57 +0800472static void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000473{
plars865695b2001-08-27 22:15:12 +0000474 if (!closed) {
Garrett Cooperff29dd12010-12-19 05:05:40 -0800475 if (ioctl(parentfd, TCSETA, &save_io) == -1)
plars865695b2001-08-27 22:15:12 +0000476 tst_resm(TINFO, "ioctl restore failed in cleanup()");
Garrett Cooperff29dd12010-12-19 05:05:40 -0800477 if (close(parentfd) == -1)
plars865695b2001-08-27 22:15:12 +0000478 tst_resm(TINFO, "close() failed in cleanup()");
plars865695b2001-08-27 22:15:12 +0000479 }
Chris Dearmanec6edca2012-10-17 19:54:01 -0700480}