Skip to content

Commit

Permalink
options/linux: handle errors in openpty
Browse files Browse the repository at this point in the history
  • Loading branch information
no92 committed Oct 7, 2023
1 parent f5e1b11 commit 571031d
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions options/linux/generic/pty-stubs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,32 @@ int openpty(int *mfd, int *sfd, char *name, const struct termios *ios, const str
mlibc::infoLogger() << "mlibc: openpty ignores win argument" << frg::endlog;
}

// FIXME: Close the master FD if the slave open fails.

int ptmx_fd;
if(int e = mlibc::sys_open("/dev/ptmx", O_RDWR | O_NOCTTY, 0, &ptmx_fd); e) {
errno = e;
return -1;
goto fail;
}

char spath[32];
if(!name)
name = spath;
if(ptsname_r(ptmx_fd, name, 32))
return -1;
goto fail;

int pts_fd;
unlockpt(ptmx_fd);
if(int e = mlibc::sys_open(spath, O_RDWR | O_NOCTTY, 0, &pts_fd); e) {
if(int e = mlibc::sys_open(name, O_RDWR | O_NOCTTY, 0, &pts_fd); e) {
errno = e;
return -1;
goto fail;
}

*mfd = ptmx_fd;
*sfd = pts_fd;
return 0;

fail:
mlibc::sys_close(ptmx_fd);
return -1;
}

int login_tty(int fd) {
Expand Down

0 comments on commit 571031d

Please sign in to comment.