-
Notifications
You must be signed in to change notification settings - Fork 211
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
Report status code of child process in term.status
property
#37
base: master
Are you sure you want to change the base?
Conversation
may be race-y due to always storing latest in global. might want to use a map of some sort.
You should probably pass I wrote something similar to this a while back, but I was hesitant as how to this may interfere with libuv's sigchld handler. I eventually dropped the code and started to wade through the libuv code, looking for an easy way to "register" a child pid with the libuv sigchld handler and read it from node. I eventually got distracted from it and forgot about it. Has this been working well enough for you in practice? Say you start a terminal+shell with pty.js and then start a process with node's child_process module... do they interfere with one another once they exit? |
To expand upon my concern. This is the line in question that I believe could cause interference. $ grep waitpid ~/node/ -r
~/node/deps/uv/src/unix/process.c: pid = waitpid(-1, &status, WNOHANG); pid = waitpid(-1, &status, WNOHANG); Passing |
I originally tried it with You make a fair point about libuv itself running |
I suppose it could cause problems right now anyway. Regardless, I still think a better approach might be to use the UV api to somehow make node aware of our processes and then using the same interface node uses (uv's sigchld handler) to grab the exit status.
|
If you access It would be great if we could use libuv for this, libuv doesn't support forkpty though - and other than using |
Well if that were to happen, Furthermore, that handler is only installed as a result of a |
Alright, that's what I hoped. I'll review this and merge soon.
Right, which is why I immediately edited my post and removed that from my list of concerns.
Assuming waitpid would hang on a child pid which existed previously (now that I know it doesn't do this, it's not a problem), uv catching all pids with a waitpid is only a problem if pty.js calls waitpid after, which does not happen currently. |
Awesome, thanks for reviewing, look forward to this being in a release! |
found a silly issue in my original PR. you can only have a single SIGCHLD handler at a time! i somehow missed this. i added a commit to retrieve node/libuv's existing SIGCHLD handler before installing pty.js'. then at the end of pty.js' SIGCHLD handler we call node/libuv's. also - do the |
fixing interoperability with native child_process. also added tests
check the sigchld handler
Just been trying this out, as I trying to resolve this in a slightly different way with waitpid on Friday last week (while this was being worked on by you as well) although I hadn't quite managed to get it working 100% in my attempts. This looks like it's working nicely though, 0 and 1 exit statuses when expected, npm doesn't have the update yet but checked it out from here. Just curious, the status is -302 while the process hasn't exited and confirmed that in pty.cc but wondered why -302? |
@pmgration this method kinda works but as as we've found in Strider-CD/strider#162 we will need to make changes to node/libuv to eliminate all race conditions and have this 100% reliable. |
@niallo thanks for the info.. is there an ETA for the libuv modifications? This will be great to use when confirmed as 100% reliable |
Very helpful, thanks @niallo. |
Any update on this? |
Not sure if there is a better way to handle this but this works. Related PR on pty.js : chjj/pty.js#37
+1 |
1 similar comment
👍 |
Merge pull request chjj#37 from niallo/waitpid Report status code of child process in `term.status` property * niallo/waitpid: missed test file adding travis node 0.10 compatibility set SA_NOCLDSTOP flag for SIGCHLD handler must set exit status correctly fixing interoperability with native child_process. also added tests call node/libuv's SIGCHLD handler. zap status property which krept in. demonstrate fetching exit status use a PID -> exit code map to avoid race conditions. save exit status of child via SIGCHLD handler and waitpid(3) may be race-y due to always storing latest in global. might want to use a map of some sort. Conflicts: lib/pty.js src/unix/pty.cc
+1 |
Will merge either this or #102. Just need to clean it up a bit. |
Use
waitpid(3)
in aSIGCHLD
handler to map the exit status to PID. This is then made available to Node via a getter.For example: