WSL: Can't run Zsh

“apt-get install zsh” is ok oh-my-zsh is ok but when run :

compaudit:105: wait failed: invalid argument
compdef:95: wait failed: invalid argument
_update_zsh_update:1: wait failed: invalid argument
/root/.oh-my-zsh/oh-my-zsh.sh:3: wait failed: invalid argument

Sorry my english!

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Reactions: 19
  • Comments: 42 (7 by maintainers)

Most upvoted comments

Ok, I’ve investigated the zsh failures and I’ve found the culprit. It’s a (somewhat) long read, so bucle up.


Part 1: wait3() with getrusage not properly implemented

After installing it with apt install zsh, here’s what running zsh outputs:

root@localhost:~# zsh    <--- bash prompt
compaudit:105: wait failed: invalid argument
compdef:95: wait failed: invalid argument
localhost#     <--- zsh prompt

Those compaudit and compdef errors are thrown because compinit is run in /etc/zsh/zshrc. If I start zsh without loading startup files the errors don’t show up anymore:

root@localhost:~# zsh -f
localhost#

and tracing the execution of those startup files with zsh -x show the errors happen in:

  • compaudit’s getent (line 107):

    +compaudit:103> local GROUP GROUPMEM _i_pw _i_gid
    +compaudit:104> (( UID == EUID  ))
    +compaudit:105> getent group root
    +compaudit:105> IFS=: +compaudit:105> read GROUP _i_pw _i_gid GROUPMEM
    compaudit:105: wait failed: invalid argument
    
  • compdef’s bindkey | read (line 356):

    +compdef:94> [[ -n yes ]]
    +compdef:95> bindkey '\e~'
    +compdef:95> IFS='  ' +compdef:95> read -A opt
    compdef:95: wait failed: invalid argument
    

Those two lines have in common that a fork() has to happen: both external and piped commands are not properly exited (notice the jobs command shows weird results):

localhost# which ls
/bin/ls
localhost# ls
zsh: wait failed: invalid argument
localhost# jobs
zsh: wait failed: invalid argument
[1]    running    ls
[12]    running
[15]    running

Other commands, like zsh builtins (no fork), work correctly:

localhost# which pwd
pwd: shell built-in command
localhost# pwd
/root
localhost#

That said, the culprit seems to be some wait function: looking for the wait failed string in the zsh codebase we easily find it:

signals.c (line 482):

/* check for WAIT error */
if (pid == -1) {
  if (errno != ECHILD)
  zerr("wait failed: %e", errno);
  /* WAIT changed errno, so restore the original */
  errno = old_errno;
  break;
}

If we look up a little bit we find the call that sets the pid variable:

#ifdef HAVE_WAIT3
# ifdef HAVE_GETRUSAGE
  struct rusage ru;
  pid = wait3((void *)&status, WAITFLAGS, &ru);
# else
  pid = wait3((void *)&status, WAITFLAGS, NULL);
# endif
#else
# ifdef HAVE_WAITPID
  pid = waitpid(-1, &status, WAITFLAGS);
# else
  pid = wait(&status);
# endif
#endif

At this point I set up a test bench with those 4 calls to see which one fails and why. You can look up the code at the following gist.

Here are the results:

# make test
./wait3_getrusage
wait failed: Invalid argument
make: [test] Error 22 (ignored)
./wait3
./waitpid
./wait

Furthermore, an strace of each executable shows (only relevant info shown):

# strace ./wait3_getrusage
wait4(-1, 0x7ff5fffef628, WNOHANG|WSTOPPED|WCONTINUED, 0x7ff5fffef630) = -1 EINVAL (Invalid argument)

# strace ./wait3
wait4(-1, 0x7ff5fffef6c8, WNOHANG|WSTOPPED|WCONTINUED, NULL) = -1 ECHILD (No child processes)

# strace ./waitpid
wait4(-1, 0x7ff5fffef6b8, WNOHANG|WSTOPPED|WCONTINUED, NULL) = -1 ECHILD (No child processes)

# strace ./wait
wait4(-1, 0x7ff5fffef6b8, WNOHANG|WSTOPPED|WCONTINUED, NULL) = -1 ECHILD (No child processes)

So it seems all 4 functions end up running the same wait4() syscall, with the exception that the first version passes a struct rusage to it while the rest set the parameter to NULL.

So, to conclude, #BashOnUbuntuOnWindows should properly implement that syscall or ignore the rusage parameter in a safe way.

Meanwhile, we can trick the zsh compilation to use one of the above calls that work correctly. To do so, follow the instructions of this gist.


Note there are several other things that don’t work yet within zsh, like subshells process substitution and named pipes. I’ll document this on a later post. A normal installation of Oh My Zsh seems to work ok though.

First off: @mcornella, excellent write-up. Thanks!

We have this one on our radar and will look into it.

@johnkchiu I got it working by installing newest release of Conemu https://github.com/Maximus5/ConEmu/releases/tag/v16.05.15 and ensuring Powerline was installed.

sudo pip install powerline-status https://powerline.readthedocs.io/en/latest/installation/linux.html#installation-on-linux

conemu

Fixed on internal builds. I am not a zsh person so I have note tested everything, but:

 russ@RUSSALEX-DESK:~$ zsh
 russ@RUSSALEX-DESK ~ % ls -la
 total 84
 drwxr-xr-x 2 russ russ     0 Apr 27 01:00 .
 drwxr-xr-x 2 root root     0 Jan  1  1970 ..
 -rw------- 1 russ russ    24 Apr 26 19:04 .bash_history
 -rw-r--r-- 1 russ russ   220 Apr 26 19:03 .bash_logout
 -rw-r--r-- 1 russ russ  3636 Apr 26 19:04 .bashrc
 drwxrwxrwx 2 russ russ     0 Apr 26 19:22 bin
 -rw-rw-rw- 1 russ russ    48 Apr 26 19:24 .gitconfig
 -rw-rw-rw- 1 russ russ    16 Apr 26 19:11 .node_repl_history
 -rw-r--r-- 1 russ russ   675 Apr 26 19:03 .profile
 drwxrwxrwx 2 russ russ     0 Apr 26 19:07 projects
 drwxrwxrwx 2 russ russ     0 Apr 26 19:20 tmp
 -rw------- 1 russ russ   625 Apr 26 19:04 .viminfo
 -rw-rw-rw- 1 russ russ 35211 Apr 27 00:55 .zcompdump
 -rw------- 1 russ russ    49 Apr 27 01:00 .zsh_history
 -rw-r--r-- 1 russ russ  1295 Apr 27 00:56 .zshrc
 russ@RUSSALEX-DESK ~ %

Hello guys, With the new update of Windows build 14342, zsh working properly. Oh My Zsh also works. It’s awesome.

Closing this issue out since zsh now works. Feel free to continue the discussion here though!

Sorry for the late replies here.

@cH40z-Lord, I wish I could give more information on the schedule. Unfortunately I can not. Best I can say is to stick on the Insider Fast right to get things as quickly as possible.

@AngeloG, Never tried myzsh before so this will not be a fair test. It did install with no errors but I do not believe the prompt displayed correctly: ➜ ~ For fun, I set my theme to random. Some look to work while others fail with errors like:

russ@RUSSALEX-DESK:~$ zsh
[oh-my-zsh] Random theme '/home/russ/.oh-my-zsh/themes/trapd00r.zsh-theme' load
d...
prompt_jnrowe_precmd:3: command not found: zsh_path
russ@RUSSALEX-DESK:-> (0)
>

My suggestion on this one would be to start a new issue here (and possibly on our uservoice page) when the zsh fixes go out.

@kameleon83 mcornella , @benhillis is talking about process substitution on #266 (as @aseering points out). Looks like we still have the same bug under zsh

I figured it out. You have to clone https://github.com/powerline/fonts then manually double click and install one of the Powerline fonts. After configuring ConEmu, then the symbols will display.

powerline_windows_conemu powerline_working

I documented the configuration on my wiki.

@russalex that’s a known issue on ohmyzsh. Some themes require loading plugins, which is not done automatically, so random doesn’t really work reliably.

@AngeloG as far as I’ve tested, most of ohmyzsh should work ok, except where process substitution is used. Some plugins may not work as well, but that’s a bigger testing effort that I can’t do right know. If in the future something doesn’t work you can always open an issue on the official repo and I’ll do my best to help.

For what it’s worth, process substitution under bash is being investigated with issue #266 . I don’t know how zsh does process substitution but would assume that they’re related.

It is still in beta. We must send the bug to insider hub. I did not do it. After I use archlinux and not Ubuntu usually so uncertain behavior of it

P.S.: Sorry for my english. I’m french and I translate by google

@lama0900 Hello just write in “.bashrc” exec zsh

so and how to run this by default? chsh doesn’t do anything. always have to run zsh as user. strange thing, as root it get’s executed by default