summaryrefslogtreecommitdiffstats
path: root/meta/recipes-support
diff options
context:
space:
mode:
authorRandy MacLeod <Randy.MacLeod@windriver.com>2019-06-16 11:48:16 -0400
committerRichard Purdie <richard.purdie@linuxfoundation.org>2019-06-30 22:34:23 +0100
commit852f90451d8a963d7c160bfd49e89ada1aa74ffc (patch)
treeaeb18fca40119cb802bf2bb2449baddc92473ef6 /meta/recipes-support
parent3ee2004f36e36a4ec5dc3f9d75f1bd0198a48ff3 (diff)
downloadpoky-852f90451d8a963d7c160bfd49e89ada1aa74ffc.tar.gz
ptest-runner: enable child procs as session leader
When running the run-execscript bash ptest as a user rather than root, a warning: bash: cannot set terminal process group (16036): Inappropriate ioctl for device bash: no job control in this shell contaminates the bash log files causing the test to fail. This happens only when run under ptest-runner and not when interactively testing! The changes made to fix this include: 1. Get the process group id (pgid) before forking, 2. Set the pgid in both the parent and child to avoid a race, 3. Find, open and set permission on the child tty, and 4. Allow the child to attach to controlling tty. (From OE-Core rev: 25121d92f1a4cd70223038e09a719fec94355ee6) Signed-off-by: Randy MacLeod <Randy.MacLeod@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> Signed-off-by: Armin Kuster <akuster808@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/recipes-support')
-rw-r--r--meta/recipes-support/ptest-runner/ptest-runner/0004-utils-ensure-child-can-be-session-leader.patch212
-rw-r--r--meta/recipes-support/ptest-runner/ptest-runner_2.3.1.bb4
2 files changed, 215 insertions, 1 deletions
diff --git a/meta/recipes-support/ptest-runner/ptest-runner/0004-utils-ensure-child-can-be-session-leader.patch b/meta/recipes-support/ptest-runner/ptest-runner/0004-utils-ensure-child-can-be-session-leader.patch
new file mode 100644
index 0000000000..13b4cbc7fb
--- /dev/null
+++ b/meta/recipes-support/ptest-runner/ptest-runner/0004-utils-ensure-child-can-be-session-leader.patch
@@ -0,0 +1,212 @@
1From 79698d3205dedba887e0d2492de945d3079de029 Mon Sep 17 00:00:00 2001
2From: Randy MacLeod <Randy.MacLeod@windriver.com>
3Date: Thu, 6 Jun 2019 17:03:50 -0400
4Subject: [PATCH] utils: ensure child can be session leader
5
6When running the run-execscript bash ptest as a user rather than root, a warning:
7 bash: cannot set terminal process group (16036): Inappropriate ioctl for device
8 bash: no job control in this shell
9contaminates the bash log files causing the test to fail. This happens only
10when run under ptest-runner and not when interactively testing!
11
12The changes made to fix this include:
131. Get the process group id (pgid) before forking,
142. Set the pgid in both the parent and child to avoid a race,
153. Find, open and set permission on the child tty, and
164. Allow the child to attach to controlling tty.
17
18Also add '-lutil' to Makefile. This lib is from libc and provides openpty.
19
20Upstream-Status: Submitted [yocto@yoctoproject.org]
21
22Signed-off-by: Sakib Sajal <sakib.sajal@windriver.com>
23Signed-off-by: Randy MacLeod <Randy.MacLeod@windriver.com>
24---
25 Makefile | 2 +-
26 utils.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++++------
27 2 files changed, 92 insertions(+), 12 deletions(-)
28
29diff --git a/Makefile b/Makefile
30index 1bde7be..439eb79 100644
31--- a/Makefile
32+++ b/Makefile
33@@ -29,7 +29,7 @@ TEST_DATA=$(shell echo `pwd`/tests/data)
34 all: $(SOURCES) $(EXECUTABLE)
35
36 $(EXECUTABLE): $(OBJECTS)
37- $(CC) $(LDFLAGS) $(OBJECTS) -o $@
38+ $(CC) $(LDFLAGS) $(OBJECTS) -lutil -o $@
39
40 tests: $(TEST_SOURCES) $(TEST_EXECUTABLE)
41
42diff --git a/utils.c b/utils.c
43index ad737c2..f11ce39 100644
44--- a/utils.c
45+++ b/utils.c
46@@ -1,5 +1,6 @@
47 /**
48 * Copyright (c) 2016 Intel Corporation
49+ * Copyright (C) 2019 Wind River Systems, Inc.
50 *
51 * This program is free software; you can redistribute it and/or
52 * modify it under the terms of the GNU General Public License
53@@ -22,23 +23,27 @@
54 */
55
56 #define _GNU_SOURCE
57+
58 #include <stdio.h>
59
60+#include <dirent.h>
61+#include <errno.h>
62+#include <fcntl.h>
63+#include <grp.h>
64 #include <libgen.h>
65-#include <signal.h>
66 #include <poll.h>
67-#include <fcntl.h>
68+#include <pty.h>
69+#include <signal.h>
70+#include <stdlib.h>
71+#include <string.h>
72 #include <time.h>
73-#include <dirent.h>
74+#include <unistd.h>
75+
76+#include <sys/ioctl.h>
77 #include <sys/resource.h>
78+#include <sys/stat.h>
79 #include <sys/types.h>
80 #include <sys/wait.h>
81-#include <sys/stat.h>
82-#include <unistd.h>
83-#include <string.h>
84-#include <stdlib.h>
85-
86-#include <errno.h>
87
88 #include "ptest_list.h"
89 #include "utils.h"
90@@ -346,6 +351,53 @@ wait_child(const char *ptest_dir, const char *run_ptest, pid_t pid,
91 return status;
92 }
93
94+/* Returns an integer file descriptor.
95+ * If it returns < 0, an error has occurred.
96+ * Otherwise, it has returned the slave pty file descriptor.
97+ * fp should be writable, likely stdout/err.
98+ */
99+static int
100+setup_slave_pty(FILE *fp) {
101+ int pty_master = -1;
102+ int pty_slave = -1;
103+ char pty_name[256];
104+ struct group *gptr;
105+ gid_t gid;
106+ int slave = -1;
107+
108+ if (openpty(&pty_master, &pty_slave, pty_name, NULL, NULL) < 0) {
109+ fprintf(fp, "ERROR: openpty() failed with: %s.\n", strerror(errno));
110+ return -1;
111+ }
112+
113+ if ((gptr = getgrnam(pty_name)) != 0) {
114+ gid = gptr->gr_gid;
115+ } else {
116+ /* If the tty group does not exist, don't change the
117+ * group on the slave pty, only the owner
118+ */
119+ gid = -1;
120+ }
121+
122+ /* chown/chmod the corresponding pty, if possible.
123+ * This will only work if the process has root permissions.
124+ */
125+ if (chown(pty_name, getuid(), gid) != 0) {
126+ fprintf(fp, "ERROR; chown() failed with: %s.\n", strerror(errno));
127+ }
128+
129+ /* Makes the slave read/writeable for the user. */
130+ if (chmod(pty_name, S_IRUSR|S_IWUSR) != 0) {
131+ fprintf(fp, "ERROR: chmod() failed with: %s.\n", strerror(errno));
132+ }
133+
134+ if ((slave = open(pty_name, O_RDWR)) == -1) {
135+ fprintf(fp, "ERROR: open() failed with: %s.\n", strerror(errno));
136+ }
137+ return (slave);
138+}
139+
140+
141 int
142 run_ptests(struct ptest_list *head, const struct ptest_options opts,
143 const char *progname, FILE *fp, FILE *fp_stderr)
144@@ -362,6 +414,8 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts,
145 int timeouted;
146 time_t sttime, entime;
147 int duration;
148+ int slave;
149+ int pgid = -1;
150
151 if (opts.xml_filename) {
152 xh = xml_create(ptest_list_length(head), opts.xml_filename);
153@@ -379,7 +433,6 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts,
154 close(pipefd_stdout[1]);
155 break;
156 }
157-
158 fprintf(fp, "START: %s\n", progname);
159 PTEST_LIST_ITERATE_START(head, p);
160 char *ptest_dir = strdup(p->run_ptest);
161@@ -388,6 +441,13 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts,
162 break;
163 }
164 dirname(ptest_dir);
165+ if (ioctl(0, TIOCNOTTY) == -1) {
166+ fprintf(fp, "ERROR: Unable to detach from controlling tty, %s\n", strerror(errno));
167+ }
168+
169+ if ((pgid = getpgid(0)) == -1) {
170+ fprintf(fp, "ERROR: getpgid() failed, %s\n", strerror(errno));
171+ }
172
173 child = fork();
174 if (child == -1) {
175@@ -395,13 +455,33 @@ run_ptests(struct ptest_list *head, const struct ptest_options opts,
176 rc = -1;
177 break;
178 } else if (child == 0) {
179- setsid();
180+ close(0);
181+ if ((slave = setup_slave_pty(fp)) < 0) {
182+ fprintf(fp, "ERROR: could not setup pty (%d).", slave);
183+ }
184+ if (setpgid(0,pgid) == -1) {
185+ fprintf(fp, "ERROR: setpgid() failed, %s\n", strerror(errno));
186+ }
187+
188+ if (setsid() == -1) {
189+ fprintf(fp, "ERROR: setsid() failed, %s\n", strerror(errno));
190+ }
191+
192+ if (ioctl(0, TIOCSCTTY, NULL) == -1) {
193+ fprintf(fp, "ERROR: Unable to attach to controlling tty, %s\n", strerror(errno));
194+ }
195+
196 run_child(p->run_ptest, pipefd_stdout[1], pipefd_stderr[1]);
197+
198 } else {
199 int status;
200 int fds[2]; fds[0] = pipefd_stdout[0]; fds[1] = pipefd_stderr[0];
201 FILE *fps[2]; fps[0] = fp; fps[1] = fp_stderr;
202
203+ if (setpgid(child, pgid) == -1) {
204+ fprintf(fp, "ERROR: setpgid() failed, %s\n", strerror(errno));
205+ }
206+
207 sttime = time(NULL);
208 fprintf(fp, "%s\n", get_stime(stime, GET_STIME_BUF_SIZE, sttime));
209 fprintf(fp, "BEGIN: %s\n", ptest_dir);
210--
2112.17.0
212
diff --git a/meta/recipes-support/ptest-runner/ptest-runner_2.3.1.bb b/meta/recipes-support/ptest-runner/ptest-runner_2.3.1.bb
index 0450e18e4e..dec60fcc9b 100644
--- a/meta/recipes-support/ptest-runner/ptest-runner_2.3.1.bb
+++ b/meta/recipes-support/ptest-runner/ptest-runner_2.3.1.bb
@@ -13,7 +13,9 @@ PV = "2.3.1+git${SRCPV}"
13SRC_URI = "git://git.yoctoproject.org/ptest-runner2 \ 13SRC_URI = "git://git.yoctoproject.org/ptest-runner2 \
14 file://0001-utils-Ensure-stdout-stderr-are-flushed.patch \ 14 file://0001-utils-Ensure-stdout-stderr-are-flushed.patch \
15 file://0002-use-process-groups-when-spawning.patch \ 15 file://0002-use-process-groups-when-spawning.patch \
16 file://0003-utils-Ensure-pipes-are-read-after-exit.patch" 16 file://0003-utils-Ensure-pipes-are-read-after-exit.patch \
17 file://0004-utils-ensure-child-can-be-session-leader.patch \
18"
17 19
18S = "${WORKDIR}/git" 20S = "${WORKDIR}/git"
19 21