diff options
author | Josh Poimboeuf <jpoimboe@redhat.com> | 2015-01-28 14:38:38 -0500 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2015-02-02 10:43:12 -0500 |
commit | 9f2cdcbbb90e70e5e8fe6cd30151b8ac1c8745ac (patch) | |
tree | 6ad6aa629b1b8e2e8742e5e64c843848441fb84d | |
parent | 64d982838e89e0d3981bfe825e0e76b36e106332 (diff) |
ktest: Give console process a dedicated tty
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>
-rwxr-xr-x | tools/testing/ktest/ktest.pl | 66 |
1 files 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 { | |||
1410 | die @_, "\n"; | 1410 | die @_, "\n"; |
1411 | } | 1411 | } |
1412 | 1412 | ||
1413 | sub open_console { | 1413 | sub create_pty { |
1414 | my ($fp) = @_; | 1414 | my ($ptm, $pts) = @_; |
1415 | my $tmp; | ||
1416 | my $TIOCSPTLCK = 0x40045431; | ||
1417 | my $TIOCGPTN = 0x80045430; | ||
1418 | |||
1419 | sysopen($ptm, "/dev/ptmx", O_RDWR | O_NONBLOCK) or | ||
1420 | dodie "Cant open /dev/ptmx"; | ||
1421 | |||
1422 | # unlockpt() | ||
1423 | $tmp = pack("i", 0); | ||
1424 | ioctl($ptm, $TIOCSPTLCK, $tmp) or | ||
1425 | dodie "ioctl TIOCSPTLCK for /dev/ptmx failed"; | ||
1426 | |||
1427 | # ptsname() | ||
1428 | ioctl($ptm, $TIOCGPTN, $tmp) or | ||
1429 | dodie "ioctl TIOCGPTN for /dev/ptmx failed"; | ||
1430 | $tmp = unpack("i", $tmp); | ||
1431 | |||
1432 | sysopen($pts, "/dev/pts/$tmp", O_RDWR | O_NONBLOCK) or | ||
1433 | dodie "Can't open /dev/pts/$tmp"; | ||
1434 | } | ||
1435 | |||
1436 | sub exec_console { | ||
1437 | my ($ptm, $pts) = @_; | ||
1438 | |||
1439 | close($ptm); | ||
1440 | |||
1441 | close(\*STDIN); | ||
1442 | close(\*STDOUT); | ||
1443 | close(\*STDERR); | ||
1415 | 1444 | ||
1416 | my $flags; | 1445 | open(\*STDIN, '<&', $pts); |
1446 | open(\*STDOUT, '>&', $pts); | ||
1447 | open(\*STDERR, '>&', $pts); | ||
1448 | |||
1449 | close($pts); | ||
1450 | |||
1451 | exec $console or | ||
1452 | dodie "Can't open console $console"; | ||
1453 | } | ||
1454 | |||
1455 | sub open_console { | ||
1456 | my ($ptm) = @_; | ||
1457 | my $pts = \*PTSFD; | ||
1458 | my $pid; | ||
1417 | 1459 | ||
1418 | # save terminal settings | 1460 | # save terminal settings |
1419 | $stty = `stty -g`; | 1461 | $stty = `stty -g`; |
1420 | 1462 | ||
1421 | my $pid = open($fp, "$console|") or | 1463 | create_pty($ptm, $pts); |
1422 | dodie "Can't open console $console"; | ||
1423 | 1464 | ||
1424 | $flags = fcntl($fp, F_GETFL, 0) or | 1465 | $pid = fork; |
1425 | dodie "Can't get flags for the socket: $!"; | 1466 | |
1426 | $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or | 1467 | if (!$pid) { |
1427 | dodie "Can't set flags for the socket: $!"; | 1468 | # child |
1469 | exec_console($ptm, $pts) | ||
1470 | } | ||
1471 | |||
1472 | # parent | ||
1473 | close($pts); | ||
1428 | 1474 | ||
1429 | return $pid; | 1475 | return $pid; |
1476 | |||
1477 | open(PTSFD, "Stop perl from warning about single use of PTSFD"); | ||
1430 | } | 1478 | } |
1431 | 1479 | ||
1432 | sub close_console { | 1480 | sub close_console { |