Skip to content

Commit

Permalink
Allow fallback to /dev/pts
Browse files Browse the repository at this point in the history
  • Loading branch information
vvb2060 committed Sep 25, 2021
1 parent cb4361b commit 45cc956
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions native/jni/su/pts.cpp
Expand Up @@ -108,6 +108,7 @@ int pts_open(char *slave_name, size_t slave_name_size) {
int get_pty_num(int fd) {
int pty_num = -1;
if (ioctl(fd, TIOCGPTN, &pty_num) != 0) {
LOGW("get_pty_num failed with %d: %s\n", errno, std::strerror(errno));
return -1;
}
return pty_num;
Expand Down
15 changes: 12 additions & 3 deletions native/jni/su/su_daemon.cpp
Expand Up @@ -240,10 +240,19 @@ void su_daemon_handler(int client, struct ucred *credential) {
ptmx = magiskpts + "/ptmx";
}
int ptmx_fd = xopen(ptmx.data(), O_RDWR);
int unlock = 0;
ioctl(ptmx_fd, TIOCSPTLCK, &unlock);
send_fd(client, ptmx_fd);
grantpt(ptmx_fd);
unlockpt(ptmx_fd);
int pty_num = get_pty_num(ptmx_fd);
if (pty_num < 0) {
// Kernel issue? Fallback to /dev/pts
close(ptmx_fd);
pts = "/dev/pts";
ptmx_fd = xopen("/dev/ptmx", O_RDWR);
grantpt(ptmx_fd);
unlockpt(ptmx_fd);
pty_num = get_pty_num(ptmx_fd);
}
send_fd(client, ptmx_fd);
close(ptmx_fd);

string pts_slave = pts + "/" + to_string(pty_num);
Expand Down

0 comments on commit 45cc956

Please sign in to comment.