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

Use environment variable to detect whether to run as node. #84

Merged
merged 4 commits into from
Sep 5, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions app/atom_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <stdlib.h>
#include <string.h>

#include "content/public/app/content_main.h"
Expand All @@ -22,7 +23,8 @@ int Start(int argc, char *argv[]);
int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
int argc = 0;
wchar_t** wargv = ::CommandLineToArgvW(::GetCommandLineW(), &argc);
if (argc > 1 && wcscmp(wargv[1], L"--atom-child_process-fork") == 0) {
char* node_indicator = getenv("ATOM_SHELL_INTERNAL_RUN_AS_NODE");
if (node_indicator != NULL && strcmp(node_indicator, "1") == 0)
// Convert argv to to UTF8
char** argv = new char*[argc];
for (int i = 0; i < argc; i++) {
Expand Down Expand Up @@ -57,8 +59,7 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
}
}
// Now that conversion is done, we can finally start.
argv[1] = argv[0];
return node::Start(argc - 1, argv + 1);
return node::Start(argc, argv);
}

sandbox::SandboxInterfaceInfo sandbox_info = {0};
Expand All @@ -72,10 +73,9 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
#include "app/atom_library_main.h"

int main(int argc, const char* argv[]) {
if (argc > 1 && strcmp(argv[1], "--atom-child_process-fork") == 0) {
argv[1] = argv[0];
return node::Start(argc - 1, const_cast<char**>(argv + 1));
}
char* node_indicator = getenv("ATOM_SHELL_INTERNAL_RUN_AS_NODE");
if (node_indicator != NULL && strcmp(node_indicator, "1") == 0)
return node::Start(argc, const_cast<char**>(argv));

return AtomMain(argc, argv);
}
Expand Down
11 changes: 11 additions & 0 deletions spec/fixtures/module/fork_ping.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
process.on('uncaughtException', function(error) {
process.send(error.stack);
});

var child = require('child_process').fork(__dirname + '/ping.js');
process.on('message', function(msg) {
child.send(msg);
});
child.on('message', function (msg) {
process.send(msg);
});
16 changes: 16 additions & 0 deletions spec/node/child_process.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,19 @@ describe 'child_process', ->
assert.equal msg, 'message'
done()
child.send 'message'

it 'should work in forked process', (done) ->
child = child_process.fork path.join(fixtures, 'module', 'fork_ping.js')
child.on 'message', (msg) ->
assert.equal msg, 'message'
done()
child.send 'message'

it 'should work in forked process when options.env is specifed', (done) ->
child = child_process.fork path.join(fixtures, 'module', 'fork_ping.js'),
[],
env: {test: 'somevar'}
child.on 'message', (msg) ->
assert.equal msg, 'message'
done()
child.send 'message'
2 changes: 1 addition & 1 deletion vendor/node
Submodule node updated from de1afc to c2ecf6