Commit 3599384b authored by vvb2060's avatar vvb2060 Committed by John Wu

Allow fallback to /dev/pts

parent 4b307cad
...@@ -108,6 +108,7 @@ error: ...@@ -108,6 +108,7 @@ error:
int get_pty_num(int fd) { int get_pty_num(int fd) {
int pty_num = -1; int pty_num = -1;
if (ioctl(fd, TIOCGPTN, &pty_num) != 0) { if (ioctl(fd, TIOCGPTN, &pty_num) != 0) {
LOGW("get_pty_num failed with %d: %s\n", errno, std::strerror(errno));
return -1; return -1;
} }
return pty_num; return pty_num;
......
...@@ -240,10 +240,19 @@ void su_daemon_handler(int client, const sock_cred *cred) { ...@@ -240,10 +240,19 @@ void su_daemon_handler(int client, const sock_cred *cred) {
ptmx = magiskpts + "/ptmx"; ptmx = magiskpts + "/ptmx";
} }
int ptmx_fd = xopen(ptmx.data(), O_RDWR); int ptmx_fd = xopen(ptmx.data(), O_RDWR);
int unlock = 0; grantpt(ptmx_fd);
ioctl(ptmx_fd, TIOCSPTLCK, &unlock); unlockpt(ptmx_fd);
send_fd(client, ptmx_fd);
int pty_num = get_pty_num(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); close(ptmx_fd);
string pts_slave = pts + "/" + to_string(pty_num); string pts_slave = pts + "/" + to_string(pty_num);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment