From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Andrew Morton <akpm@linux-foundation.org>,
Josh Poimboeuf <jpoimboe@redhat.com>
Subject: [for-next][PATCH 5/9] ktest: Give console process a dedicated tty
Date: Wed, 04 Feb 2015 14:50:52 -0500 [thread overview]
Message-ID: <20150204195123.791882832@goodmis.org> (raw)
In-Reply-To: <20150204195047.818126814@goodmis.org>
[-- Attachment #1: 0005-ktest-Give-console-process-a-dedicated-tty.patch --]
[-- Type: text/plain, Size: 2404 bytes --]
From: Josh Poimboeuf <jpoimboe@redhat.com>
Create a pseudoterminal (pty pair) to give the console a dedicated tty
so it doesn't mess with ktest's terminal settings.
Link: http://lkml.kernel.org/r/37b0127f9efad09ff4fc994334db998141e4f6ca.1422473610.git.jpoimboe@redhat.com
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
tools/testing/ktest/ktest.pl | 66 ++++++++++++++++++++++++++++++++++++++------
1 file changed, 57 insertions(+), 9 deletions(-)
diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
index 6ae890a0d486..2d3191693567 100755
--- a/tools/testing/ktest/ktest.pl
+++ b/tools/testing/ktest/ktest.pl
@@ -1410,23 +1410,71 @@ sub dodie {
die @_, "\n";
}
-sub open_console {
- my ($fp) = @_;
+sub create_pty {
+ my ($ptm, $pts) = @_;
+ my $tmp;
+ my $TIOCSPTLCK = 0x40045431;
+ my $TIOCGPTN = 0x80045430;
+
+ sysopen($ptm, "/dev/ptmx", O_RDWR | O_NONBLOCK) or
+ dodie "Cant open /dev/ptmx";
+
+ # unlockpt()
+ $tmp = pack("i", 0);
+ ioctl($ptm, $TIOCSPTLCK, $tmp) or
+ dodie "ioctl TIOCSPTLCK for /dev/ptmx failed";
+
+ # ptsname()
+ ioctl($ptm, $TIOCGPTN, $tmp) or
+ dodie "ioctl TIOCGPTN for /dev/ptmx failed";
+ $tmp = unpack("i", $tmp);
+
+ sysopen($pts, "/dev/pts/$tmp", O_RDWR | O_NONBLOCK) or
+ dodie "Can't open /dev/pts/$tmp";
+}
+
+sub exec_console {
+ my ($ptm, $pts) = @_;
+
+ close($ptm);
+
+ close(\*STDIN);
+ close(\*STDOUT);
+ close(\*STDERR);
- my $flags;
+ open(\*STDIN, '<&', $pts);
+ open(\*STDOUT, '>&', $pts);
+ open(\*STDERR, '>&', $pts);
+
+ close($pts);
+
+ exec $console or
+ dodie "Can't open console $console";
+}
+
+sub open_console {
+ my ($ptm) = @_;
+ my $pts = \*PTSFD;
+ my $pid;
# save terminal settings
$stty = `stty -g`;
- my $pid = open($fp, "$console|") or
- dodie "Can't open console $console";
+ create_pty($ptm, $pts);
- $flags = fcntl($fp, F_GETFL, 0) or
- dodie "Can't get flags for the socket: $!";
- $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or
- dodie "Can't set flags for the socket: $!";
+ $pid = fork;
+
+ if (!$pid) {
+ # child
+ exec_console($ptm, $pts)
+ }
+
+ # parent
+ close($pts);
return $pid;
+
+ open(PTSFD, "Stop perl from warning about single use of PTSFD");
}
sub close_console {
--
2.1.4
next prev parent reply other threads:[~2015-02-04 19:52 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-04 19:50 [for-next][PATCH 0/9] ktest: Updates for 3.20 Steven Rostedt
2015-02-04 19:50 ` [for-next][PATCH 1/9] ktest: Add timings for commands Steven Rostedt
2015-02-04 19:50 ` [for-next][PATCH 2/9] ktest: Restore tty settings after closing console Steven Rostedt
2015-02-04 19:50 ` [for-next][PATCH 3/9] ktest: Show times for build, install, boot and test Steven Rostedt
2015-02-04 19:50 ` [for-next][PATCH 4/9] ktest: Rename start_monitor_and_boot to start_monitor_and_install Steven Rostedt
2015-02-04 19:50 ` Steven Rostedt [this message]
2015-02-04 19:50 ` [for-next][PATCH 6/9] ktest: Enable user input to the console Steven Rostedt
2015-02-04 19:50 ` [for-next][PATCH 7/9] ktest: Print build,install,boot,test times at success and failure Steven Rostedt
2015-02-04 19:50 ` [for-next][PATCH 8/9] ktest: Cleanup terminal on dodie() failure Steven Rostedt
2015-02-04 19:50 ` [for-next][PATCH 9/9] ktest: Place quotes around item variable Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150204195123.791882832@goodmis.org \
--to=rostedt@goodmis.org \
--cc=akpm@linux-foundation.org \
--cc=jpoimboe@redhat.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®