Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POSIX Spawn 2: Electric Boogaloo #487

Merged
merged 19 commits into from
Dec 10, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 43 additions & 27 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -46,33 +46,49 @@
}
]
}, { # OS!="win"
'targets': [{
'target_name': 'pty',
'include_dirs' : [
'<!(node -e "require(\'nan\')")'
],
'sources': [
'src/unix/pty.cc'
],
'libraries': [
'-lutil'
],
'conditions': [
# http://www.gnu.org/software/gnulib/manual/html_node/forkpty.html
# One some systems (at least including Cygwin, Interix,
# OSF/1 4 and 5, and Mac OS X) linking with -lutil is not required.
['OS=="mac" or OS=="solaris"', {
'libraries!': [
'-lutil'
]
}],
['OS=="mac"', {
"xcode_settings": {
"MACOSX_DEPLOYMENT_TARGET":"10.7"
}
}]
]
}]
'targets': [
{
'target_name': 'spawn-helper',
'type': 'executable',
'cflags': ['-Wall'],
'sources': [
'src/unix/spawn-helper.cc',
'src/unix/comms.cc'
Eugeny marked this conversation as resolved.
Show resolved Hide resolved
],
'libraries': [
'-lpthread'
],
},
{
'target_name': 'pty',
'include_dirs' : [
'<!(node -e "require(\'nan\')")'
],
'sources': [
'src/unix/pty.cc',
'src/unix/comms.cc'
Eugeny marked this conversation as resolved.
Show resolved Hide resolved
],
'libraries': [
'-lutil'
],
'cflags': ['-Wall'],
'conditions': [
# http://www.gnu.org/software/gnulib/manual/html_node/forkpty.html
# One some systems (at least including Cygwin, Interix,
# OSF/1 4 and 5, and Mac OS X) linking with -lutil is not required.
['OS=="mac" or OS=="solaris"', {
'libraries!': [
'-lutil'
]
}],
['OS=="mac"', {
"xcode_settings": {
"MACOSX_DEPLOYMENT_TARGET":"10.7"
}
}]
]
}
]
}]
]
}
1 change: 1 addition & 0 deletions scripts/post-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var BUILD_FILES = [
path.join(RELEASE_DIR, 'conpty_console_list.pdb'),
path.join(RELEASE_DIR, 'pty.node'),
path.join(RELEASE_DIR, 'pty.pdb'),
path.join(RELEASE_DIR, 'spawn-helper'),
path.join(RELEASE_DIR, 'winpty-agent.exe'),
path.join(RELEASE_DIR, 'winpty-agent.pdb'),
path.join(RELEASE_DIR, 'winpty.dll'),
Expand Down
2 changes: 1 addition & 1 deletion src/native.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface IWinptyNative {
}

interface IUnixNative {
fork(file: string, args: string[], parsedEnv: string[], cwd: string, cols: number, rows: number, uid: number, gid: number, useUtf8: boolean, onExitCallback: (code: number, signal: number) => void): IUnixProcess;
fork(file: string, args: string[], parsedEnv: string[], cwd: string, cols: number, rows: number, uid: number, gid: number, useUtf8: boolean, onExitCallback: (code: number, signal: number) => void, helperPath: string): IUnixProcess;
open(cols: number, rows: number): IUnixOpenProcess;
process(fd: number, pty: string): string;
resize(fd: number, cols: number, rows: number): void;
Expand Down
55 changes: 55 additions & 0 deletions src/unix/comms.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include "comms.h"

#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>


void comm_send_int(int fd, int data) {
send(fd, &data, sizeof(data), 0);
}

void comm_send_str(int fd, char *str) {
comm_send_int(fd, strlen(str));
send(fd, str, strlen(str), 0);
}

void comm_send_str_array(int fd, char **arr) {
int len = 0;
auto p = arr;
while (*p) {
len++;
p++;
}

comm_send_int(fd, len);
p = arr;
while (*p) {
comm_send_str(fd, *p);
p++;
}
}

int comm_recv_int(int fd) {
int buf;
recv(fd, &buf, sizeof(buf), 0);
return buf;
}

char* comm_recv_str(int fd) {
int len = comm_recv_int(fd);
auto buf = new char[len + 1];
recv(fd, buf, len, 0);
buf[len] = 0;
return buf;
}

char** comm_recv_str_array(int fd) {
int len = comm_recv_int(fd);
auto buf = new char*[len + 1];
buf[len] = nullptr;
for (int i = 0; i < len; i++) {
buf[i] = comm_recv_str(fd);
}
return buf;
}
19 changes: 19 additions & 0 deletions src/unix/comms.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#define COMM_PTY_FD 0
#define COMM_PIPE_FD 1

#define COMM_MSG_PATH 1
#define COMM_MSG_ARGV 2
#define COMM_MSG_ENV 3
#define COMM_MSG_CWD 4
#define COMM_MSG_UID 5
#define COMM_MSG_GID 6
#define COMM_MSG_GO_FOR_LAUNCH 99

#define COMM_MSG_EXEC_ERROR 100

void comm_send_int(int fd, int data);
void comm_send_str(int fd, char *str);
void comm_send_str_array(int fd, char **arr);
int comm_recv_int(int fd);
char* comm_recv_str(int fd);
char** comm_recv_str_array(int fd);
Loading