Skip to content

Commit c065944

Browse files
committed
Fix OpenBSD compatibility for posix_openpt call
Replace O_CLOEXEC flag in posix_openpt with separate fcntl call to support OpenBSD which doesn't support O_CLOEXEC in posix_openpt. Based on fix by rpx99 (https://github.com/rpx99)
1 parent ad9f07c commit c065944

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

src/async-process.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
#include "async-process.h"
22

3+
// OpenBSD-compatible PTY opening function
34
static const char* open_pty(int *out_fd)
45
{
5-
int fd = posix_openpt(O_RDWR | O_CLOEXEC | O_NOCTTY);
6+
int fd = posix_openpt(O_RDWR | O_NOCTTY);
67
if (fd < 0) return NULL;
7-
if (grantpt(fd) == -1 || unlockpt(fd) == -1) return NULL;
8-
fcntl(fd, F_SETFD, FD_CLOEXEC);
8+
if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) {
9+
close(fd);
10+
return NULL;
11+
}
12+
13+
if (grantpt(fd) == -1 || unlockpt(fd) == -1) {
14+
close(fd);
15+
return NULL;
16+
}
917
const char *name = ptsname(fd);
1018
if (name == NULL) {
1119
close(fd);

0 commit comments

Comments
 (0)