[readline] remove use of openpty

pull/1205/head
Tim Stack 8 months ago
parent 8a5616c010
commit e5bcf85712

@ -67,6 +67,18 @@ auto_fd::dup_of(int fd)
return auto_fd(new_fd);
}
Result<auto_fd, std::string>
auto_fd::openpt(int flags)
{
auto rc = posix_openpt(flags);
if (rc == -1) {
return Err(fmt::format(FMT_STRING("posix_openpt() failed: {}"),
strerror(errno)));
}
return Ok(auto_fd{rc});
}
auto_fd::auto_fd(int fd) : af_fd(fd)
{
require(fd >= -1);

@ -64,6 +64,8 @@ public:
*/
static auto_fd dup_of(int fd);
static Result<auto_fd, std::string> openpt(int flags);
/**
* Construct an auto_fd to manage the given file descriptor.
*

@ -56,6 +56,7 @@
#include "base/ansi_scrubber.hh"
#include "base/auto_mem.hh"
#include "base/fs_util.hh"
#include "base/itertools.hh"
#include "base/lnav_log.hh"
#include "base/paths.hh"
@ -744,16 +745,32 @@ readline_curses::start()
ws.ws_col -= this->vc_left;
ws.ws_col += this->vc_width;
}
if (openpty(this->rc_pty[RCF_MASTER].out(),
this->rc_pty[RCF_SLAVE].out(),
nullptr,
nullptr,
&ws)
< 0)
auto openpt_res = auto_fd::openpt(O_NOCTTY | O_RDWR);
if (openpt_res.isErr()) {
log_error("readline_curses: cannot open pty -- %s",
openpt_res.unwrapErr().c_str());
throw error(errno);
}
this->rc_pty[RCF_MASTER] = openpt_res.unwrap();
log_perror(grantpt(this->rc_pty[RCF_MASTER]));
log_perror(unlockpt(this->rc_pty[RCF_MASTER]));
char slave_path[PATH_MAX];
if (ptsname_r(this->rc_pty[RCF_MASTER], slave_path, sizeof(slave_path))
== -1)
{
perror("error: failed to open terminal(openpty)");
perror("ptsname_r");
throw error(errno);
}
auto slave_open_res
= lnav::filesystem::open_file(slave_path, O_RDWR | O_CLOEXEC);
if (slave_open_res.isErr()) {
log_error("open pseudo failed -- %s",
slave_open_res.unwrapErr().c_str());
throw error(errno);
}
this->rc_pty[RCF_SLAVE] = slave_open_res.unwrap();
this->rc_pty[RCF_MASTER].close_on_exec();
this->rc_pty[RCF_SLAVE].close_on_exec();

Loading…
Cancel
Save