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

provide a way to control argv[0] of the spawned process #472

Open
mirabilos opened this issue May 7, 2021 · 6 comments · May be fixed by #627
Open

provide a way to control argv[0] of the spawned process #472

mirabilos opened this issue May 7, 2021 · 6 comments · May be fixed by #627
Labels
enhancement help wanted Issues identified as good community contribution opportunities

Comments

@mirabilos
Copy link

To properly fix microsoft/vscode#123332 node-pty must provide a way to control argv[0] of the spawned process, that is, instead of…

const ptyProcess = (await import('node-pty')).spawn("/bin/sh", ["--login"], options);

… which internally does an…

execv("/bin/sh", "/bin/sh", "--login", NULL);

… vscode must do something like…

const ptyProcess = (await import('node-pty')).spawna("/bin/sh", "-sh", [], options);
// or
const ptyProcess = (await import('node-pty')).spawna("/bin/sh", ["-sh"], options);

… which internally does an…

execv("/bin/sh", "-sh", NULL);

… so a new API will be needed, unless this can be put into options somehow, perhaps…

const ptyProcess = (await import('node-pty')).spawna("/bin/sh", [], {"argv0": "-sh"});
@jerch
Copy link
Collaborator

jerch commented May 8, 2021

@mirabilos Why would it be needed to treat this separately, why not just use existing API:

pty.spawn('/bin/sh', ['-sh', ...], ...)

@mirabilos
Copy link
Author

mirabilos commented May 8, 2021 via email

@jerch
Copy link
Collaborator

jerch commented May 9, 2021

@mirabilos Thx, found the piece of code, where it gets copied over as argv[0]. Is that '-' convention of login specced somewhere (maybe in POSIX?) or at least known to work in all major POSIX systems with all shells? Do you have some more insights here, e.g. how does a non shell executable deal with the '-'? How does it get "translated" for the new executable, will it just see the '-' as first char in argv and do additional things on its own (soft convention)? Or are there more changes done from kernel side to the process spawning like implicit **environ changes or switched uid/gid rules or pid/pgid things (hard convention with behavioral changes in outer interfaces)?

API-wise I see 2 possible ways to support it:

  • a boolean flag markAsLoginShell in options, which adds the '-' to argv[0], if it is meant as login shell (smooth upgrade path, but less powerful and semantically slightly wrong if we dont have a shell at all)
  • extend argv to always contain argv[0] explicitly (API breakage, thus works only as major change, more powerful in the long run as it feeds things directly to execvp also allowing for weird interpreter/script execution setups)

@mirabilos
Copy link
Author

mirabilos commented May 9, 2021 via email

@jerch
Copy link
Collaborator

jerch commented May 10, 2021

Looking at child_process its API supports an optional argv0 setting in options, which defaults to the given command if not set. So yeah this might be the best way to deal with it:

interface IPtyForkOptions {
  ...
  argv0: undefined | string;
}

@mirabilos
Copy link
Author

mirabilos commented May 10, 2021 via email

@Tyriar Tyriar added the help wanted Issues identified as good community contribution opportunities label Oct 21, 2021
mattieb added a commit to mattieb/node-pty that referenced this issue Aug 31, 2023
@mattieb mattieb linked a pull request Sep 1, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement help wanted Issues identified as good community contribution opportunities
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants