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

Android fixes #6733

Closed
wants to merge 2 commits into from
Closed

Android fixes #6733

wants to merge 2 commits into from

Conversation

robertchiras
Copy link
Contributor

Checklist
  • tests and code linting passes
  • a test and/or benchmark is included
  • documentation is changed or added
  • the commit message follows commit guidelines
Affected core subsystem(s)

build, child_process

Description of change

Small fixes found when running on Android platform.

In case of x86 arch, the target_arch variables passed through
GYP_DEFINES is also x86. But, this value is not recognized by gyp files,
so we need to pass ia32 instead. For x86 arch, we need to pass the value
of DEST_CPU, which is ia32.

Signed-off-by: Robert Chiras <robert.chiras@intel.com>
In execSync/execFileSync commands, we better verify the stderr buffer
from ret. In case of other exceptions thrown by spawnSync this buffer
might be null. If we don't check it and try to write it to process.stderr
we will end up throwing an irrelevant exception from Socket.write,
masking the initial exception which might show what is actually wrong
with spawnSync. Such an exception was hidden, when running this test on
Android. The exception was about '/bin/sh' not found, since in Android,
sh can be found in '/system/bin/sh'.

Signed-off-by: Robert Chiras <robert.chiras@intel.com>
@nodejs-github-bot nodejs-github-bot added the child_process Issues and PRs related to the child_process subsystem. label May 13, 2016
@bnoordhuis
Copy link
Member

The second commit doesn't look obviously correct to me. If the issue is the location of sh, wouldn't a more appropriate fix look like this?

diff --git a/lib/child_process.js b/lib/child_process.js
index 81fb8c1..4fda6e2 100644
--- a/lib/child_process.js
+++ b/lib/child_process.js
@@ -332,7 +332,12 @@ function normalizeSpawnArguments(file /*, args, options*/) {
       args = ['/s', '/c', '"' + command + '"'];
       options.windowsVerbatimArguments = true;
     } else {
-      file = typeof options.shell === 'string' ? options.shell : '/bin/sh';
+      if (typeof options.shell === 'string')
+        file = options.shell;
+      else if (process.platform === 'android')
+        file = '/system/bin/sh';
+      else
+        file = '/bin/sh';
       args = ['-c', command];
     }
   }

@robertchiras
Copy link
Contributor Author

robertchiras commented May 13, 2016

The second commit is intended to not mask any other exceptions. The exception I met and described is just an example. This is why, I consider it might be a good fix.
Regarding your proposed fix: my way of treading that error, was to correct the test itself, which was calling execSync, by adding shell option.
For example, in test-child-process-emfile:

diff --git a/test/sequential/test-child-process-emfile.js b/test/sequential/test-child-process-emfile.js
index f186db5..961f37c 100644
--- a/test/sequential/test-child-process-emfile.js
+++ b/test/sequential/test-child-process-emfile.js
@@ -9,13 +9,19 @@ if (common.isWindows) {
   return;
 }

-const ulimit = Number(child_process.execSync('ulimit -Hn'));
+var sh = '/bin/sh'
+var opts = {}
+if (process.platform === 'android') {
+  sh = '/system/bin/sh'
+  opts = {shell: sh}
+}
+const ulimit = Number(child_process.execSync('ulimit -Hn', opts));
 if (ulimit > 64 || Number.isNaN(ulimit)) {
   // Sorry about this nonsense. It can be replaced if
   // https://github.com/nodejs/node-v0.x-archive/pull/2143#issuecomment-2847886
   // ever happens.
   const result = child_process.spawnSync(
-    '/bin/sh',
+    sh,
     ['-c', `ulimit -n 64 && '${process.execPath}' '${__filename}'`]
   );
   assert.strictEqual(result.stdout.toString(), '');

But, I think that your proposed fix is better, since we won't have to handle this situation in every test using execSync.

@mscdex mscdex added the arm Issues and PRs related to the ARM platform. label May 13, 2016
@bnoordhuis
Copy link
Member

Okay, I understand now. Can you add a regression test to the second commit that exercises the stderr-is-falsy code path? I filed #6745 for the /bin/sh patch.

bnoordhuis added a commit to bnoordhuis/io.js that referenced this pull request May 14, 2016
`/bin/sh` does not exist on Android but `/system/bin/sh` does.

PR-URL: nodejs#6745
Refs: nodejs#6733
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
evanlucas pushed a commit that referenced this pull request May 17, 2016
`/bin/sh` does not exist on Android but `/system/bin/sh` does.

PR-URL: #6745
Refs: #6733
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
@eljefedelrodeodeljefe
Copy link
Contributor

ping @robertchiras do you find some time to work on this? #6745 landed. Thanks!

@robertchiras
Copy link
Contributor Author

Hi @eljefedelrodeodeljefe
Yes, I did not forgot about this. But, I updated node to latest version and I found out it does not compile anymore for Android. I am preparing a new patch and I will separate the Android build issues from the child_process issue into different pull requests.

@eljefedelrodeodeljefe
Copy link
Contributor

Very grateful @robertchiras. Looking forward to it. I am collecting similar issues across the repo. After we land the stalled stuff I am gonna have a look at building latest too. Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arm Issues and PRs related to the ARM platform. child_process Issues and PRs related to the child_process subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants