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

Cannot call Atom Package Manager apm from Bash #2467

Closed
skylize opened this issue Sep 1, 2017 · 6 comments
Closed

Cannot call Atom Package Manager apm from Bash #2467

skylize opened this issue Sep 1, 2017 · 6 comments

Comments

@skylize
Copy link

skylize commented Sep 1, 2017

Windows build number

Microsoft Windows [Version 10.0.16251.1002]

Problem

Fails to run apm (Atom Package Manager) from WSL.


Setup

Install Atom Editor on Windows system verify that user or system PATH includes C:\Users\{username}\AppData\Local\atom\bin .

What's happening?

In WSL Bash Prompt type apm

$ apm
net.js:145
    this._handle.open(options.fd);
                 ^

Error: EINVAL: invalid argument, uv_pipe_open
    at Error (native)
    at new Socket (net.js:145:18)
    at createWritableStdioStream (internal/process/stdio.js:156:16)
    at process.getStdout [as stdout] (internal/process/stdio.js:10:14)
    at module.exports (c:\Users\sky\AppData\Local\atom\app-1.19.5\resources\app\apm\node_modules\npm\node_modules\npmlog\node_modules\set-blocking\index.js:2:11)
    at Object.<anonymous> (c:\Users\sky\AppData\Local\atom\app-1.19.5\resources\app\apm\node_modules\npm\node_modules\npmlog\log.js:11:1)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)

What should be happening instead?

Output in Bash should match this output from calling apm in a cmd terminal

> apm 

apm - Atom Package Manager powered by https://atom.io

Usage: apm <command>

where <command> is one of:
    clean, config, dedupe, deinstall, delete, dev, develop, disable, docs,
    enable, erase, featured, home, i, init, install, link, linked, links, list,
    ln, lns, login, ls, open, outdated, publish, rebuild, rebuild-module-cache,
    remove, rm, search, show, star, starred, stars, test, uninstall, unlink,
    unpublish, unstar, update, upgrade, view.

Run `apm help <command>` to see the more details about a specific command.

Options:
  --color        Enable colored output                                     [boolean] [default: true]
  -v, --version  Print the apm version
  -h, --help     Print this usage message

  Prefix an option with `no-` to set it to false such as --no-color to disable
  colored output.

Layman's interpretation of results

Edit: I was wrong, you really don't need to read this section.

It looks like to me like bash is clobbering Windows environment variables with it's own, causing apm to look in non-existent locations for dependencies.

I think as default behavior WSL should not pass any environment variable to a Windows binary if that variable already exist in the Windows environment.

As implied by the name, the standard purpose of an environment variable is to describe the environment in which the binary will run. Even if invoked from bash, a windows binary will never run inside that bash environment, it will run in the Windows environment. Except in special use cases, the environment variables described in bash will be totally meaningless, while Windows variables will often be vital to even the most basic behavior like starting the application.

Overwriting the existing environment variables in Windows with variables that describe a completely different environment** (without the User specifically requesting it) **is simply not acceptable.

I certainly agree that clobbering as an option would be nice to have. But clobbering by default is prone to cause way more errors than it helps.

strace

strace.1094

execve("/mnt/c/Users/sky/AppData/Local/atom/bin/apm", ["apm"], [/* 19 vars */]) = 0
brk(NULL)                               = 0x7fffef9f6000
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd72e0b0000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=31001, ...}) = 0
mmap(NULL, 31001, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fd72e0a8000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0P\t\2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1868984, ...}) = 0
mmap(NULL, 3971488, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fd72da30000
mprotect(0x7fd72dbf0000, 2097152, PROT_NONE) = 0
mmap(0x7fd72ddf0000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1c0000) = 0x7fd72ddf0000
mmap(0x7fd72ddf6000, 14752, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fd72ddf6000
close(3)                                = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd72e0a0000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd72e090000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd72e080000
arch_prctl(ARCH_SET_FS, 0x7fd72e090700) = 0
mprotect(0x7fd72ddf0000, 16384, PROT_READ) = 0
mprotect(0x7fd72e423000, 8192, PROT_READ) = 0
mprotect(0x7fd72e025000, 4096, PROT_READ) = 0
munmap(0x7fd72e0a8000, 31001)           = 0
getuid()                                = 1000
getgid()                                = 1000
getpid()                                = 1094
rt_sigaction(SIGCHLD, {0x7fd72e217540, ~[RTMIN RT_1], SA_RESTORER, 0x7fd72da654b0}, NULL, 8) = 0
geteuid()                               = 1000
brk(NULL)                               = 0x7fffef9f6000
brk(0x7fffefa17000)                     = 0x7fffefa17000
getppid()                               = 1092
stat("/c/dev/vendor/linter-eslint", {st_mode=S_IFDIR|0777, st_size=4096, ...}) = 0
stat(".", {st_mode=S_IFDIR|0777, st_size=4096, ...}) = 0
open("/mnt/c/Users/sky/AppData/Local/atom/bin/apm", O_RDONLY) = 3
fcntl(3, F_DUPFD, 10)                   = 10
close(3)                                = 0
fcntl(10, F_SETFD, FD_CLOEXEC)          = 0
geteuid()                               = 1000
getegid()                               = 1000
rt_sigaction(SIGINT, NULL, {SIG_DFL, [], SA_RESTORER, 0x7f017e6254b0}, 8) = 0
rt_sigaction(SIGINT, {0x7fd72e217540, ~[RTMIN RT_1], SA_RESTORER, 0x7fd72da654b0}, NULL, 8) = 0
rt_sigaction(SIGQUIT, NULL, {SIG_DFL, [], SA_RESTORER, 0x7f017e6254b0}, 8) = 0
rt_sigaction(SIGQUIT, {SIG_DFL, ~[RTMIN RT_1], SA_RESTORER, 0x7fd72da654b0}, NULL, 8) = 0
rt_sigaction(SIGTERM, NULL, {SIG_DFL, [], SA_RESTORER, 0x7f017e6254b0}, 8) = 0
rt_sigaction(SIGTERM, {SIG_DFL, ~[RTMIN RT_1], SA_RESTORER, 0x7fd72da654b0}, NULL, 8) = 0
read(10, "#!/bin/sh\r\n\"$(dirname \"$0\")/../a"..., 8192) = 68
read(10, "", 8192)                      = 0
pipe([3, 4])                            = 0
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7fd72e0909d0) = 1095
close(4)                                = 0
read(3, "/mnt/c/Users/sky/AppData/Local/a"..., 128) = 40
read(3, "", 128)                        = 0
close(3)                                = 0
wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 1095
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=1095, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
rt_sigreturn({mask=[]})                 = 1095
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7fd72e0909d0) = 1096
wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 1}], 0, NULL) = 1096
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=1096, si_uid=1000, si_status=1, si_utime=0, si_stime=0} ---
rt_sigreturn({mask=[]})                 = 1096
exit_group(1)                           = ?
+++ exited with 1 +++

strace.1095

close(10)                               = 0
close(3)                                = 0
dup2(4, 1)                              = 1
close(4)                                = 0
stat("/home/sky/bin/dirname", 0x7ffff7c1bec0) = -1 ENOENT (No such file or directory)
stat("/home/sky/.local/bin/dirname", 0x7ffff7c1bec0) = -1 ENOENT (No such file or directory)
stat("/home/sky/.nvm/versions/node/v8.4.0/bin/dirname", 0x7ffff7c1bec0) = -1 ENOENT (No such file or directory)
stat("/usr/local/sbin/dirname", 0x7ffff7c1bec0) = -1 ENOENT (No such file or directory)
stat("/usr/local/bin/dirname", 0x7ffff7c1bec0) = -1 ENOENT (No such file or directory)
stat("/usr/sbin/dirname", 0x7ffff7c1bec0) = -1 ENOENT (No such file or directory)
stat("/usr/bin/dirname", {st_mode=S_IFREG|0755, st_size=31408, ...}) = 0
execve("/usr/bin/dirname", ["dirname", "/mnt/c/Users/sky/AppData/Local/a"...], [/* 19 vars */]) = 0
brk(NULL)                               = 0x1f13000
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f319faa0000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=31001, ...}) = 0
mmap(NULL, 31001, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f319faa2000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0P\t\2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1868984, ...}) = 0
mmap(NULL, 3971488, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f319f430000
mprotect(0x7f319f5f0000, 2097152, PROT_NONE) = 0
mmap(0x7f319f7f0000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1c0000) = 0x7f319f7f0000
mmap(0x7f319f7f6000, 14752, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f319f7f6000
close(3)                                = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f319fa90000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f319fa80000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f319fa70000
arch_prctl(ARCH_SET_FS, 0x7f319fa80700) = 0
mprotect(0x7f319f7f0000, 16384, PROT_READ) = 0
mprotect(0x606000, 4096, PROT_READ)     = 0
mprotect(0x7f319fa25000, 4096, PROT_READ) = 0
munmap(0x7f319faa2000, 31001)           = 0
brk(NULL)                               = 0x1f13000
brk(0x1f34000)                          = 0x1f34000
open("/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=1668976, ...}) = 0
mmap(NULL, 1668976, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f319f88d000
close(3)                                = 0
fstat(1, {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0
write(1, "/mnt/c/Users/sky/AppData/Local/a"..., 40) = 40
close(1)                                = 0
close(2)                                = 0
exit_group(0)                           = ?
+++ exited with 0 +++

Other straces

strace -o strace.txt -ff apm created 16 total trace files. Let me know if for some reason you need more of the traces to help. Trace 1095 has already exited with code 0. So I think posting the rest would be frivolous.

See our contributing instructions for assistance.

@therealkenc
Copy link
Collaborator

#2370

@skylize
Copy link
Author

skylize commented Sep 2, 2017

@therealkenc Yes there does appear to be some similarity. Unclear to me if it is the same issue. To me the lightbulb for mine was lines like this in the stack trace:

stat("/usr/local/sbin/dirname", 0x7ffff7c1bec0) = -1 ENOENT (No such file or directory)
stat("/usr/local/bin/dirname", 0x7ffff7c1bec0) = -1 ENOENT (No such file or directory)
stat("/usr/sbin/dirname", 0x7ffff7c1bec0) = -1 ENOENT (No such file or directory)

The stack trace is full of random linux pathnames, but not a windows path to be found anywhere. But then I have no idea what this strace is saying, so I could be completely off base.

All I actually know for sure is that if you try to run apm from bash it crashes every time. Atom itself boots up fine and gets handed the properly filepaths.

@therealkenc
Copy link
Collaborator

therealkenc commented Sep 2, 2017

@skylize - Those ENOENTs are "normal" (for Linux's definition of normal). Notice it got a hit (return value = 0) a few lines down on /usr/bin/dirname. It is just fishing.

There is a "windows path to be found", at the very first line: the execve(). After that, any Windows paths that might come into play happen on the Windows side through the magic of interop. apm, in your scenario, is running on Windows, and WSL has no idea what's going on over there; other than input and output from stdin/stdout (which is faked with pipes) to and from the Windows process.

Win32 Atom boots up fine though interop; but then Atom proper isn't trying to read or write to/from stdin/stdout.

It's beyond my pay-grade to say for certain whether it is the same as #2370 or not. Ben will probably chime in when he's around (it's already the long weekend).

@skylize skylize changed the title WSL Bash clobbers Windows Environment Variables ( cannot run apm from bash) Cannot call Atom Package Manager apm from Bash Sep 2, 2017
@skylize
Copy link
Author

skylize commented Sep 2, 2017

@therealkenc Thanks for the insight. I changed the issue's title so it no longer includes my incorrect assessment of the problem.

@therealkenc
Copy link
Collaborator

Duping this into #2370 because it's been a couple of months now. @skylize - if #2370 changes status and your scenario does not improve, ping this thread and we can revisit.

@skylize
Copy link
Author

skylize commented Dec 7, 2017

@therealkenc Sounds fine. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants