Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
GNOME
vte
Commits
118ad1ca
Commit
118ad1ca
authored
Aug 03, 2019
by
Christian Persch
Browse files
pty: Prefer using TIOCGPTPEER ioctl
parent
6e640d5e
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/pty.cc
View file @
118ad1ca
...
...
@@ -33,6 +33,7 @@
#include
"vtetypes.hh"
#include
"vtespawn.hh"
#include
<assert.h>
#include
<sys/types.h>
#include
<sys/ioctl.h>
#include
<sys/socket.h>
...
...
@@ -159,24 +160,39 @@ vte_pty_child_setup (VtePty *pty)
}
/* Note: *not* O_CLOEXEC! */
auto
const
fd_flags
=
O_RDWR
|
((
priv
->
flags
&
VTE_PTY_NO_CTTY
)
?
O_NOCTTY
:
0
);
auto
const
fd_flags
=
int
{
O_RDWR
|
((
priv
->
flags
&
VTE_PTY_NO_CTTY
)
?
O_NOCTTY
:
0
)};
auto
fd
=
int
{
-
1
};
char
*
name
=
ptsname
(
masterfd
);
if
(
name
==
nullptr
)
{
_vte_debug_print
(
VTE_DEBUG_PTY
,
"%s failed: %m
\n
"
,
"ptsname"
);
#ifdef __linux__
fd
=
ioctl
(
masterfd
,
TIOCGPTPEER
,
fd_flags
);
if
(
fd
==
-
1
&&
errno
!=
EINVAL
)
{
_vte_debug_print
(
VTE_DEBUG_PTY
,
"%s failed: %m
\n
"
,
"ioctl(TIOCGPTPEER)"
);
_exit
(
127
);
}
}
_vte_debug_print
(
VTE_DEBUG_PTY
,
"Setting up child pty: master FD = %d name = %s
\n
"
,
masterfd
,
name
);
/* EINVAL means the kernel doesn't support this ioctl; fall back to ptsname + open */
#endif
int
fd
=
open
(
name
,
fd_flags
);
if
(
fd
==
-
1
)
{
_vte_debug_print
(
VTE_DEBUG_PTY
,
"Failed to open PTY: %m
\n
"
);
_exit
(
127
);
auto
const
name
=
ptsname
(
masterfd
);
if
(
name
==
nullptr
)
{
_vte_debug_print
(
VTE_DEBUG_PTY
,
"%s failed: %m
\n
"
,
"ptsname"
);
_exit
(
127
);
}
_vte_debug_print
(
VTE_DEBUG_PTY
,
"Setting up child pty: master FD = %d name = %s
\n
"
,
masterfd
,
name
);
fd
=
open
(
name
,
fd_flags
);
if
(
fd
==
-
1
)
{
_vte_debug_print
(
VTE_DEBUG_PTY
,
"Failed to open PTY: %m
\n
"
);
_exit
(
127
);
}
}
assert
(
fd
!=
-
1
);
#if defined(HAVE_SETSID) && defined(HAVE_SETPGID)
if
(
!
(
priv
->
flags
&
VTE_PTY_NO_SESSION
))
{
/* Start a new session and become process-group leader. */
...
...
Philip Chimento
🚮
@ptomato
mentioned in issue
#182 (closed)
·
Oct 10, 2019
mentioned in issue
#182 (closed)
mentioned in issue #182
Toggle commit list
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment