xref: /third_party/ltp/testcases/kernel/pty/pty01.c (revision f08c3bdf)
1f08c3bdfSopenharmony_ci/*
2f08c3bdfSopenharmony_ci *
3f08c3bdfSopenharmony_ci *   Copyright (c) International Business Machines  Corp., 2002
4f08c3bdfSopenharmony_ci *
5f08c3bdfSopenharmony_ci *   This program is free software;  you can redistribute it and/or modify
6f08c3bdfSopenharmony_ci *   it under the terms of the GNU General Public License as published by
7f08c3bdfSopenharmony_ci *   the Free Software Foundation; either version 2 of the License, or
8f08c3bdfSopenharmony_ci *   (at your option) any later version.
9f08c3bdfSopenharmony_ci *
10f08c3bdfSopenharmony_ci *   This program is distributed in the hope that it will be useful,
11f08c3bdfSopenharmony_ci *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
12f08c3bdfSopenharmony_ci *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
13f08c3bdfSopenharmony_ci *   the GNU General Public License for more details.
14f08c3bdfSopenharmony_ci *
15f08c3bdfSopenharmony_ci *   You should have received a copy of the GNU General Public License
16f08c3bdfSopenharmony_ci *   along with this program;  if not, write to the Free Software
17f08c3bdfSopenharmony_ci *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18f08c3bdfSopenharmony_ci */
19f08c3bdfSopenharmony_ci
20f08c3bdfSopenharmony_ci/* 12/23/2002	Port to LTP	robbiew@us.ibm.com */
21f08c3bdfSopenharmony_ci/* 06/30/2001	Port to Linux	nsharoff@us.ibm.com */
22f08c3bdfSopenharmony_ci
23f08c3bdfSopenharmony_ci#define _GNU_SOURCE
24f08c3bdfSopenharmony_ci#include <sys/types.h>
25f08c3bdfSopenharmony_ci#include <sys/stat.h>
26f08c3bdfSopenharmony_ci#include <sys/wait.h>
27f08c3bdfSopenharmony_ci#include <errno.h>
28f08c3bdfSopenharmony_ci#include <fcntl.h>
29f08c3bdfSopenharmony_ci#include <stdio.h>
30f08c3bdfSopenharmony_ci#include <stdlib.h>
31f08c3bdfSopenharmony_ci#include <string.h>
32f08c3bdfSopenharmony_ci#include <termios.h>
33f08c3bdfSopenharmony_ci#include <unistd.h>
34f08c3bdfSopenharmony_ci
35f08c3bdfSopenharmony_ci#include "test.h"
36f08c3bdfSopenharmony_ci#include "safe_macros.h"
37f08c3bdfSopenharmony_ci#include "lapi/ioctl.h"
38f08c3bdfSopenharmony_ci
39f08c3bdfSopenharmony_cichar *TCID = "pty01";		/* Test program identifier.    */
40f08c3bdfSopenharmony_ciint TST_TOTAL = 5;		/* Total number of test cases. */
41f08c3bdfSopenharmony_ci/**************/
42f08c3bdfSopenharmony_ci
43f08c3bdfSopenharmony_ci/*
44f08c3bdfSopenharmony_ci * pty master clone device
45f08c3bdfSopenharmony_ci */
46f08c3bdfSopenharmony_ci#define MASTERCLONE "/dev/ptmx"
47f08c3bdfSopenharmony_ci
48f08c3bdfSopenharmony_ci/*
49f08c3bdfSopenharmony_ci * string for testing read/write on ptys
50f08c3bdfSopenharmony_ci */
51f08c3bdfSopenharmony_ci#define STRING "Linux Test Project\n"
52f08c3bdfSopenharmony_ci
53f08c3bdfSopenharmony_ci/*
54f08c3bdfSopenharmony_ci * test buffer size
55f08c3bdfSopenharmony_ci */
56f08c3bdfSopenharmony_ci#define TESTSIZE 1024
57f08c3bdfSopenharmony_ci
58f08c3bdfSopenharmony_ci/*
59f08c3bdfSopenharmony_ci * mode we expect grantpt() to leave pty as
60f08c3bdfSopenharmony_ci */
61f08c3bdfSopenharmony_ci#define PTY_MODE 020622
62f08c3bdfSopenharmony_ci
63f08c3bdfSopenharmony_ci/*
64f08c3bdfSopenharmony_ci * number of procs for parallel test
65f08c3bdfSopenharmony_ci */
66f08c3bdfSopenharmony_ci#define NUMPROCS 15
67f08c3bdfSopenharmony_ci
68f08c3bdfSopenharmony_ci/*
69f08c3bdfSopenharmony_ci * test slave locking
70f08c3bdfSopenharmony_ci */
71f08c3bdfSopenharmony_cistatic int test1(void)
72f08c3bdfSopenharmony_ci{
73f08c3bdfSopenharmony_ci	int masterfd;		/* master pty fd */
74f08c3bdfSopenharmony_ci	int slavefd;		/* slave pty fd */
75f08c3bdfSopenharmony_ci	char *slavename;
76f08c3bdfSopenharmony_ci	struct stat st;
77f08c3bdfSopenharmony_ci	char buf[TESTSIZE];
78f08c3bdfSopenharmony_ci
79f08c3bdfSopenharmony_ci	masterfd = SAFE_OPEN(NULL, MASTERCLONE, O_RDWR);
80f08c3bdfSopenharmony_ci
81f08c3bdfSopenharmony_ci	slavename = ptsname(masterfd);
82f08c3bdfSopenharmony_ci	if (slavename == NULL) {
83f08c3bdfSopenharmony_ci		tst_brkm(TBROK | TERRNO, NULL, "ptsname() call failed");
84f08c3bdfSopenharmony_ci	}
85f08c3bdfSopenharmony_ci
86f08c3bdfSopenharmony_ci	if (grantpt(masterfd) != 0) {
87f08c3bdfSopenharmony_ci		tst_brkm(TBROK | TERRNO, NULL, "grantpt() call failed");
88f08c3bdfSopenharmony_ci	}
89f08c3bdfSopenharmony_ci
90f08c3bdfSopenharmony_ci	if (stat(slavename, &st) != 0) {
91f08c3bdfSopenharmony_ci		tst_brkm(TBROK | TERRNO, NULL, "stat(%s) failed", slavename);
92f08c3bdfSopenharmony_ci	}
93f08c3bdfSopenharmony_ci	if (st.st_uid != getuid()) {
94f08c3bdfSopenharmony_ci		tst_brkm(TBROK, NULL, "uid mismatch");
95f08c3bdfSopenharmony_ci	}
96f08c3bdfSopenharmony_ci
97f08c3bdfSopenharmony_ci	 /* grantpt() is a no-op in bionic. */
98f08c3bdfSopenharmony_ci#ifndef __BIONIC__
99f08c3bdfSopenharmony_ci	if (st.st_mode != (S_IFCHR | S_IRUSR | S_IWUSR | S_IWGRP)) {
100f08c3bdfSopenharmony_ci		tst_brkm(TBROK, NULL, "mode mismatch (mode=%o)", st.st_mode);
101f08c3bdfSopenharmony_ci	}
102f08c3bdfSopenharmony_ci#endif
103f08c3bdfSopenharmony_ci
104f08c3bdfSopenharmony_ci	slavefd = open(slavename, O_RDWR);
105f08c3bdfSopenharmony_ci	if (slavefd >= 0) {
106f08c3bdfSopenharmony_ci		tst_brkm(TBROK, NULL, "open didn't fail as expected!");
107f08c3bdfSopenharmony_ci	}
108f08c3bdfSopenharmony_ci
109f08c3bdfSopenharmony_ci	if (unlockpt(masterfd) != 0) {
110f08c3bdfSopenharmony_ci		tst_brkm(TBROK | TERRNO, NULL, "unlockpt() failed");
111f08c3bdfSopenharmony_ci	}
112f08c3bdfSopenharmony_ci
113f08c3bdfSopenharmony_ci	slavefd = SAFE_OPEN(NULL, slavename, O_RDWR);
114f08c3bdfSopenharmony_ci
115f08c3bdfSopenharmony_ci	/*
116f08c3bdfSopenharmony_ci	 * test writing to the master / reading from the slave
117f08c3bdfSopenharmony_ci	 */
118f08c3bdfSopenharmony_ci	if (write(masterfd, STRING, strlen(STRING)) != strlen(STRING)) {
119f08c3bdfSopenharmony_ci		/*
120f08c3bdfSopenharmony_ci		 * XXX: the errno printout might be garbage, but better to be
121f08c3bdfSopenharmony_ci		 * safe than sorry..
122f08c3bdfSopenharmony_ci		 */
123f08c3bdfSopenharmony_ci		tst_brkm(TFAIL | TERRNO, NULL, "write to master");
124f08c3bdfSopenharmony_ci	}
125f08c3bdfSopenharmony_ci
126f08c3bdfSopenharmony_ci	if (read(slavefd, buf, strlen(STRING)) != strlen(STRING)) {
127f08c3bdfSopenharmony_ci		/* XXX: Same as write above.. */
128f08c3bdfSopenharmony_ci		tst_brkm(TFAIL | TERRNO, NULL, "read from slave");
129f08c3bdfSopenharmony_ci	}
130f08c3bdfSopenharmony_ci	if (strncmp(STRING, buf, strlen(STRING) - 1) != 0) {
131f08c3bdfSopenharmony_ci		tst_brkm(TFAIL, NULL,
132f08c3bdfSopenharmony_ci			 "strings are different (STRING = '%s' != buf = '%s')",
133f08c3bdfSopenharmony_ci			 STRING, buf);
134f08c3bdfSopenharmony_ci	}
135f08c3bdfSopenharmony_ci
136f08c3bdfSopenharmony_ci	/*
137f08c3bdfSopenharmony_ci	 * test writing to the slave / reading from the master
138f08c3bdfSopenharmony_ci	 */
139f08c3bdfSopenharmony_ci	if (write(slavefd, STRING, strlen(STRING)) != strlen(STRING)) {
140f08c3bdfSopenharmony_ci		/* XXX: Same as write above.. */
141f08c3bdfSopenharmony_ci		tst_brkm(TFAIL | TERRNO, NULL, "write to slave");
142f08c3bdfSopenharmony_ci	}
143f08c3bdfSopenharmony_ci
144f08c3bdfSopenharmony_ci	if (read(masterfd, buf, strlen(STRING)) != strlen(STRING)) {
145f08c3bdfSopenharmony_ci		/* XXX: Same as write above.. */
146f08c3bdfSopenharmony_ci		tst_brkm(TFAIL | TERRNO, NULL, "read from master");
147f08c3bdfSopenharmony_ci	}
148f08c3bdfSopenharmony_ci	if (strncmp(STRING, buf, strlen(STRING) - 1) != 0) {
149f08c3bdfSopenharmony_ci		tst_brkm(TFAIL, NULL,
150f08c3bdfSopenharmony_ci			 "strings are different (STRING = '%s' != buf = '%s').",
151f08c3bdfSopenharmony_ci			 STRING, buf);
152f08c3bdfSopenharmony_ci	}
153f08c3bdfSopenharmony_ci
154f08c3bdfSopenharmony_ci	/*
155f08c3bdfSopenharmony_ci	 * try an invalid ioctl on the slave...
156f08c3bdfSopenharmony_ci	 */
157f08c3bdfSopenharmony_ci	if (ioctl(slavefd, TIOCGWINSZ, NULL) == 0) {
158f08c3bdfSopenharmony_ci		tst_brkm(TFAIL, NULL,
159f08c3bdfSopenharmony_ci			 "invalid slave TIOCGWINSZ ioctl succeeded.. it should "
160f08c3bdfSopenharmony_ci			 "have failed");
161f08c3bdfSopenharmony_ci	}
162f08c3bdfSopenharmony_ci
163f08c3bdfSopenharmony_ci	/*
164f08c3bdfSopenharmony_ci	 * try an invalid ioctl on the master...
165f08c3bdfSopenharmony_ci	 */
166f08c3bdfSopenharmony_ci	if (ioctl(masterfd, TIOCGWINSZ, NULL) == 0) {
167f08c3bdfSopenharmony_ci		tst_brkm(TFAIL, NULL,
168f08c3bdfSopenharmony_ci			 "invalid master TIOCGWINSZ ioctl succeeded.. it should "
169f08c3bdfSopenharmony_ci			 "have failed");
170f08c3bdfSopenharmony_ci	}
171f08c3bdfSopenharmony_ci
172f08c3bdfSopenharmony_ci	/*
173f08c3bdfSopenharmony_ci	 * close pty fds
174f08c3bdfSopenharmony_ci	 */
175f08c3bdfSopenharmony_ci	if (close(slavefd) != 0) {
176f08c3bdfSopenharmony_ci		tst_brkm(TBROK | TERRNO, NULL, "close of slave");
177f08c3bdfSopenharmony_ci	}
178f08c3bdfSopenharmony_ci	if (close(masterfd) != 0) {
179f08c3bdfSopenharmony_ci		tst_brkm(TBROK | TERRNO, NULL, "close of master");
180f08c3bdfSopenharmony_ci	}
181f08c3bdfSopenharmony_ci	tst_resm(TPASS, "test1");
182f08c3bdfSopenharmony_ci	/** NOTREACHED **/
183f08c3bdfSopenharmony_ci	return 0;
184f08c3bdfSopenharmony_ci}
185f08c3bdfSopenharmony_ci
186f08c3bdfSopenharmony_ci/*
187f08c3bdfSopenharmony_ci * test slave operations with closed master
188f08c3bdfSopenharmony_ci */
189f08c3bdfSopenharmony_cistatic void test2(void)
190f08c3bdfSopenharmony_ci{
191f08c3bdfSopenharmony_ci	int masterfd;		/* master pty fd */
192f08c3bdfSopenharmony_ci	int slavefd;		/* slave pty fd */
193f08c3bdfSopenharmony_ci	int i;
194f08c3bdfSopenharmony_ci	char *slavename;
195f08c3bdfSopenharmony_ci	char c;
196f08c3bdfSopenharmony_ci
197f08c3bdfSopenharmony_ci	masterfd = SAFE_OPEN(NULL, MASTERCLONE, O_RDWR);
198f08c3bdfSopenharmony_ci
199f08c3bdfSopenharmony_ci	slavename = ptsname(masterfd);
200f08c3bdfSopenharmony_ci	if (slavename == NULL) {
201f08c3bdfSopenharmony_ci		tst_brkm(TBROK | TERRNO, NULL, "ptsname() call failed");
202f08c3bdfSopenharmony_ci	}
203f08c3bdfSopenharmony_ci
204f08c3bdfSopenharmony_ci	if (grantpt(masterfd) != 0) {
205f08c3bdfSopenharmony_ci		tst_brkm(TBROK | TERRNO, NULL, "grantpt() call failed");
206f08c3bdfSopenharmony_ci	}
207f08c3bdfSopenharmony_ci
208f08c3bdfSopenharmony_ci	if (unlockpt(masterfd) != 0) {
209f08c3bdfSopenharmony_ci		tst_brkm(TBROK | TERRNO, NULL, "unlockpt() call failed");
210f08c3bdfSopenharmony_ci	}
211f08c3bdfSopenharmony_ci
212f08c3bdfSopenharmony_ci	slavefd = SAFE_OPEN(NULL, slavename, O_RDWR);
213f08c3bdfSopenharmony_ci
214f08c3bdfSopenharmony_ci	/*
215f08c3bdfSopenharmony_ci	 * close pty fds.  See what happens when we close the master
216f08c3bdfSopenharmony_ci	 * first.
217f08c3bdfSopenharmony_ci	 */
218f08c3bdfSopenharmony_ci	if (close(masterfd) != 0) {
219f08c3bdfSopenharmony_ci		tst_brkm(TBROK | TERRNO, NULL, "close()");
220f08c3bdfSopenharmony_ci	}
221f08c3bdfSopenharmony_ci
222f08c3bdfSopenharmony_ci	errno = 0;
223f08c3bdfSopenharmony_ci	if ((i = read(slavefd, &c, 1)) == 1) {
224f08c3bdfSopenharmony_ci		tst_brkm(TFAIL, NULL,
225f08c3bdfSopenharmony_ci			 "reading from slave fd should have failed, but didn't"
226f08c3bdfSopenharmony_ci			 "(read '%c')", c);
227f08c3bdfSopenharmony_ci	}
228f08c3bdfSopenharmony_ci
229f08c3bdfSopenharmony_ci	if ((i = write(slavefd, &c, 1)) == 1) {
230f08c3bdfSopenharmony_ci		tst_brkm(TFAIL, NULL,
231f08c3bdfSopenharmony_ci			 "writing to slave fd should have failed, but didn't");
232f08c3bdfSopenharmony_ci	}
233f08c3bdfSopenharmony_ci
234f08c3bdfSopenharmony_ci	if (ioctl(slavefd, TIOCGWINSZ, NULL) == 0) {
235f08c3bdfSopenharmony_ci		tst_brkm(TFAIL, NULL,
236f08c3bdfSopenharmony_ci			 "trying TIOCGWINSZ on slave fd should have failed, "
237f08c3bdfSopenharmony_ci			 "but didn't");
238f08c3bdfSopenharmony_ci	}
239f08c3bdfSopenharmony_ci
240f08c3bdfSopenharmony_ci	if (close(slavefd) != 0) {
241f08c3bdfSopenharmony_ci		tst_brkm(TBROK, NULL, "close");
242f08c3bdfSopenharmony_ci	}
243f08c3bdfSopenharmony_ci	tst_resm(TPASS, "test2");
244f08c3bdfSopenharmony_ci}
245f08c3bdfSopenharmony_ci
246f08c3bdfSopenharmony_ci/*
247f08c3bdfSopenharmony_ci * test operations on master with closed slave
248f08c3bdfSopenharmony_ci */
249f08c3bdfSopenharmony_cistatic void test3(void)
250f08c3bdfSopenharmony_ci{
251f08c3bdfSopenharmony_ci	int masterfd;		/* master pty fd */
252f08c3bdfSopenharmony_ci
253f08c3bdfSopenharmony_ci	masterfd = SAFE_OPEN(NULL, MASTERCLONE, O_RDWR);
254f08c3bdfSopenharmony_ci
255f08c3bdfSopenharmony_ci	if (ioctl(masterfd, TIOCGWINSZ, NULL) == 0) {
256f08c3bdfSopenharmony_ci		tst_brkm(TFAIL | TERRNO, NULL,
257f08c3bdfSopenharmony_ci			 "trying TIOCGWINSZ on master with no open slave "
258f08c3bdfSopenharmony_ci			 "succeeded unexpectedly");
259f08c3bdfSopenharmony_ci	}
260f08c3bdfSopenharmony_ci	tst_resm(TPASS, "test3");
261f08c3bdfSopenharmony_ci}
262f08c3bdfSopenharmony_ci
263f08c3bdfSopenharmony_ci/*
264f08c3bdfSopenharmony_ci * test multiple opens on slave side of pty
265f08c3bdfSopenharmony_ci */
266f08c3bdfSopenharmony_cistatic void test4(void)
267f08c3bdfSopenharmony_ci{
268f08c3bdfSopenharmony_ci	int masterfd;		/* master pty fd */
269f08c3bdfSopenharmony_ci	int slavefd;		/* slave pty fd */
270f08c3bdfSopenharmony_ci	int slavefd2;
271f08c3bdfSopenharmony_ci	int slavefd3;
272f08c3bdfSopenharmony_ci	char *slavename;
273f08c3bdfSopenharmony_ci
274f08c3bdfSopenharmony_ci	masterfd = SAFE_OPEN(NULL, MASTERCLONE, O_RDWR);
275f08c3bdfSopenharmony_ci
276f08c3bdfSopenharmony_ci	slavename = ptsname(masterfd);
277f08c3bdfSopenharmony_ci	if (slavename == NULL) {
278f08c3bdfSopenharmony_ci		tst_brkm(TBROK, NULL, "ptsname() call failed");
279f08c3bdfSopenharmony_ci	}
280f08c3bdfSopenharmony_ci
281f08c3bdfSopenharmony_ci	if (grantpt(masterfd) != 0) {
282f08c3bdfSopenharmony_ci		tst_brkm(TBROK, NULL, "grantpt() call failed");
283f08c3bdfSopenharmony_ci	}
284f08c3bdfSopenharmony_ci
285f08c3bdfSopenharmony_ci	if (unlockpt(masterfd) != 0) {
286f08c3bdfSopenharmony_ci		tst_brkm(TBROK | TERRNO, NULL, "unlockpt() call failed");
287f08c3bdfSopenharmony_ci	}
288f08c3bdfSopenharmony_ci
289f08c3bdfSopenharmony_ci	slavefd = SAFE_OPEN(NULL, slavename, O_RDWR);
290f08c3bdfSopenharmony_ci
291f08c3bdfSopenharmony_ci	slavefd2 = open(slavename, O_RDWR);
292f08c3bdfSopenharmony_ci	if (slavefd < 0) {
293f08c3bdfSopenharmony_ci		tst_brkm(TFAIL | TERRNO, NULL, "Could not open %s (again)",
294f08c3bdfSopenharmony_ci			 slavename);
295f08c3bdfSopenharmony_ci	}
296f08c3bdfSopenharmony_ci
297f08c3bdfSopenharmony_ci	slavefd3 = open(slavename, O_RDWR);
298f08c3bdfSopenharmony_ci	if (slavefd < 0) {
299f08c3bdfSopenharmony_ci		tst_brkm(TFAIL | TERRNO, NULL, "Could not open %s (once more)",
300f08c3bdfSopenharmony_ci			 slavename);
301f08c3bdfSopenharmony_ci	}
302f08c3bdfSopenharmony_ci
303f08c3bdfSopenharmony_ci	/*
304f08c3bdfSopenharmony_ci	 * close pty fds.
305f08c3bdfSopenharmony_ci	 */
306f08c3bdfSopenharmony_ci	if (close(slavefd) != 0) {
307f08c3bdfSopenharmony_ci		tst_brkm(TBROK | TERRNO, NULL, "close slave");
308f08c3bdfSopenharmony_ci	}
309f08c3bdfSopenharmony_ci
310f08c3bdfSopenharmony_ci	if (close(slavefd2) != 0) {
311f08c3bdfSopenharmony_ci		tst_brkm(TBROK, NULL, "close slave again");
312f08c3bdfSopenharmony_ci	}
313f08c3bdfSopenharmony_ci
314f08c3bdfSopenharmony_ci	if (close(slavefd3) != 0) {
315f08c3bdfSopenharmony_ci		tst_brkm(TBROK, NULL, "close slave once more");
316f08c3bdfSopenharmony_ci	}
317f08c3bdfSopenharmony_ci
318f08c3bdfSopenharmony_ci	if (close(masterfd) != 0) {
319f08c3bdfSopenharmony_ci		tst_brkm(TBROK, NULL, "close master");
320f08c3bdfSopenharmony_ci	}
321f08c3bdfSopenharmony_ci	tst_resm(TPASS, "test4");
322f08c3bdfSopenharmony_ci}
323f08c3bdfSopenharmony_ci
324f08c3bdfSopenharmony_ci/*
325f08c3bdfSopenharmony_ci * test opening/closing lots of ptys in parallel.  We may run out
326f08c3bdfSopenharmony_ci * of ptys for this test depending on how the system is configured,
327f08c3bdfSopenharmony_ci * but that's not a fatal error.
328f08c3bdfSopenharmony_ci */
329f08c3bdfSopenharmony_cistatic void test5(void)
330f08c3bdfSopenharmony_ci{
331f08c3bdfSopenharmony_ci	int masterfd;		/* master pty fd */
332f08c3bdfSopenharmony_ci	char *slavename;
333f08c3bdfSopenharmony_ci	int status;
334f08c3bdfSopenharmony_ci	int i;
335f08c3bdfSopenharmony_ci
336f08c3bdfSopenharmony_ci	for (i = 0; i < NUMPROCS; ++i) {
337f08c3bdfSopenharmony_ci		switch (fork()) {
338f08c3bdfSopenharmony_ci		case -1:
339f08c3bdfSopenharmony_ci			tst_brkm(TBROK, NULL, "fork()");
340f08c3bdfSopenharmony_ci			break;
341f08c3bdfSopenharmony_ci		case 0:
342f08c3bdfSopenharmony_ci			masterfd = open(MASTERCLONE, O_RDWR);
343f08c3bdfSopenharmony_ci			if (masterfd < 0) {
344f08c3bdfSopenharmony_ci				printf("proc %d: opening %s failed: %s",
345f08c3bdfSopenharmony_ci				       i, MASTERCLONE, strerror(errno));
346f08c3bdfSopenharmony_ci				exit(1);
347f08c3bdfSopenharmony_ci			}
348f08c3bdfSopenharmony_ci			if (grantpt(masterfd) != 0) {
349f08c3bdfSopenharmony_ci				printf("proc %d: grantpt() call failed: %s",
350f08c3bdfSopenharmony_ci				       i, strerror(errno));
351f08c3bdfSopenharmony_ci				exit(1);
352f08c3bdfSopenharmony_ci			}
353f08c3bdfSopenharmony_ci			slavename = ptsname(masterfd);
354f08c3bdfSopenharmony_ci			if (slavename == NULL) {
355f08c3bdfSopenharmony_ci				printf("proc %d: ptsname() call failed: %s",
356f08c3bdfSopenharmony_ci				       i, strerror(errno));
357f08c3bdfSopenharmony_ci				exit(1);
358f08c3bdfSopenharmony_ci			}
359f08c3bdfSopenharmony_ci			sleep(10);
360f08c3bdfSopenharmony_ci			if (close(masterfd) != 0) {
361f08c3bdfSopenharmony_ci				printf("proc %d: close failed: %s",
362f08c3bdfSopenharmony_ci				       i, strerror(errno));
363f08c3bdfSopenharmony_ci				exit(1);
364f08c3bdfSopenharmony_ci			}
365f08c3bdfSopenharmony_ci			exit(0);
366f08c3bdfSopenharmony_ci		default:
367f08c3bdfSopenharmony_ci			break;
368f08c3bdfSopenharmony_ci		}
369f08c3bdfSopenharmony_ci	}
370f08c3bdfSopenharmony_ci	while (wait(&status) > 0) {
371f08c3bdfSopenharmony_ci		if (status) {
372f08c3bdfSopenharmony_ci			tst_brkm(TFAIL, NULL,
373f08c3bdfSopenharmony_ci				 "child exited with non-zero status %d",
374f08c3bdfSopenharmony_ci				 status);
375f08c3bdfSopenharmony_ci		}
376f08c3bdfSopenharmony_ci	}
377f08c3bdfSopenharmony_ci	tst_resm(TPASS, "test5");
378f08c3bdfSopenharmony_ci}
379f08c3bdfSopenharmony_ci
380f08c3bdfSopenharmony_ci/*
381f08c3bdfSopenharmony_ci * main test driver
382f08c3bdfSopenharmony_ci */
383f08c3bdfSopenharmony_ciint main(void)
384f08c3bdfSopenharmony_ci{
385f08c3bdfSopenharmony_ci	test1();
386f08c3bdfSopenharmony_ci	test2();
387f08c3bdfSopenharmony_ci	test3();
388f08c3bdfSopenharmony_ci	test4();
389f08c3bdfSopenharmony_ci	test5();
390f08c3bdfSopenharmony_ci
391f08c3bdfSopenharmony_ci	/*
392f08c3bdfSopenharmony_ci	 * all done
393f08c3bdfSopenharmony_ci	 */
394f08c3bdfSopenharmony_ci	tst_exit();
395f08c3bdfSopenharmony_ci}
396