Cygwin Terminal shell stopped working properly - cygwin

cygwin64 had been running great on my Windows 7 system for several months. After rebooting this morning, it appeared to be inexplicably broken. When I started a new mintty session, rather than presenting a window with my familiar bash prompt, I got a blank window entitled -sh.exe. Sure enough, despite the lack of any sort of prompt, it was a shell window. ls, pwd, cd, and other commands worked, but my environment was a mess. Aside from the lack of a prompt, my home directory, path, and other things were messed up.
I tried the normal things. I reran cygwin setup to no avail. I completely uninstalled and reinstalled cygwin, again with no discernible effect. I rebooted a number of times during all these tries. What could cause cygwin to suddenly begin behaving so badly?

I had similar issues after installing IBM InfoSphere DataStage, which causes Cygwin to misbehave because it is setting several Windows environment that are inherited by Cygwin, and are crucial to Mintty and the shell. These variables are: SHELL, TERM, TERMCAP, and TERMINFO.
I modified my Mintty shortcut to contain the following target, and this fixed the issues:
C:\cygwin\bin\mintty.exe /bin/env -u SHELL -u TERMCAP -u TERMINFO - TERM=xterm-256color HOME=/home/username /bin/bash -i -l
The -u options are unsetting those variables, and then I'm explicitly setting TERM and HOME (make sure to use your home directory instead of /home/username).
I also had to copy my ~/.minttyrc file to /etc/minttyrc so that mintty would see it.

After digging around, I noticed that the sh.exe that was running was not in /cygwin64/bin, but was instead in \Program Files (x86)\MKS Toolkit. I did not recall installing MKS, but the date on this directory was from the previous day. The only thing I'd recently installed was the IBM InfoSphere DataStage client. It turns out, InfoSphere not only installs the MKS Toolkit, it prepends it to a number of environment variables, totally hosing cygwin.

Related

Command not found in WSL2 even though it's on the path

I'm having an issue with WSL2:
$ where b4a
/usr/local/bin/b4a
$ b4a new
/usr/local/bin/b4a: 1: Not: not found
Even though where finds commands, I can't run them. And it's not a PATH issue either:
echo $PATH
/usr/local/sbin:/usr/local/bin:[...]
And b4a isn't the only command with this problem. What could be the cause? My distribution is Debian 10 and host is Windows 10.
Not necessarily a full answer, but hopefully the troubleshooting methods you need to arrive at a solution ...
Note that it doesn't say that the command itself isn't found. For instance, if you run:
# lllllllllll
lllllllllll: command not found
That's truly a command not found. This is different. While I don't (yet) know the exact cause, this seems closer to the issues we might see with improperly quoted paths with spaces in a shell script.
You mention that other commands have this problem -- Is there something in common with the commands that don't work properly? Is it possible that they are all shell scripts?
Try several things to debug:
Start WSL without your startup profile. It's very likely that something (or you) added a line that is causing problems. From PowerShell or CMD:
wsl ~ -e bash --noprofile --norc
b4a
If that works, then there's a problem in one of your startup files that you'll need to debug. Look for anything modifying environment variables without proper quoting, especially the PATH. WSL automatically appends the Windows path to your Linux path to make it easy to run Windows commands, but the fact that almost every Windows path has spaces in it can cause problems for unsuspecting scripters that don't take this corner case into account.
Having a space in a path is fully allowed in Linux, but some scripts just don't handle it properly.
If the command that is failing is a shell script, trying starting it with:
bash -x /usr/local/bin/b4a
Or even start WSL with wsl ~ -e bash -x to see all trace output from the shell.
In this case, you'll be looking for some problem in the script right around where it actually fails.
If all else fails, you can disable WSL's PATH modification via its config file:
sudo -e /etc/wsl.conf
Add the following:
[interop]
appendWindowsPath = false
Then exit Debian, run wsl --shutdown and restart Debian. Try the b4a command again.
If this works, then the problem is almost certainly due to some problem in the PATH quoting in these commands. I don't recommend it as a permanent solution since you will have to type out the full path of Windows applications each time you want to run them.

cygwin/X version 1.17 xinit version 1.3.* breaks run.exe

i have been using cygwin/X for many years and have not had any major problems, until the upgrade of xinit to version 1.3.x, it breaks everything without any warning at all. people wonder why open source gets such a bad reputation, it's this kind of blindsiding that does it...
anyway, prior to xinit 1.3.x i started Xwin via the Xwin icon. i could then start xterm (or emacs or any X application) using run.exe which i would pin to the taskbar. my command line is as such:
D:\cygwin\bin\run.exe -p /bin bash ~/scripts/xterm.sh
my xterm.sh is as follows:
export DISPLAY=127.0.0.1:0.0
xterm &
exit
this has worked like a charm for YEARS, now it doesn't do anything.
even doing this in a windows cmd:
set DISPLAY=127.0.0.1:0.0
d:\cygwin\bin\run.exe -p /usr/X11R6/bin xterm
doesn't work anymore...
does anyone know how to start an Xwin application (xterm, emacs ...) via the dos command line ...
Try to set DISPLAY to :0.0 (not 127.0.0.1:0.0). Source.

virtual terminals in ubuntu server do not recognize newly installed nvm

Ubuntu server (as all linuxes) has the ability to multitask using ctrl-F1 up to ctrl-F7. Each of these key combos puts you in another terminal. While in the main terminal (ctrl-F1) I installed nvm (node version manager) and also node.js. These work fine in the ctrl-F1 terminal. But when I go to another terminal, ubuntu thinks they are not installed. ECHO $PATH gives the same result in all virtual terminals. Default programs like nano, vim, etc can be started in all the different terminals. How can I 'fix' this issue so that I can run learnyounode in one terminal, nano in another terminal, and node in another terminal?
If you have shells running on those terminals which were initiated before you ran the installer, they will not have received the updated configuration. Log out and then back in, or figure out which configuration file(s) to source anew. Probably
. ~/.bashrc
but there could be pertinent changes in .bash_profile and/or .profile as well (and system config files, if you did a system-wide install).

Cygwin error: "-bash: fork: retry: Resource temporarily unavailable"

I recently reinstalled Cygwin on my computer in order to get access to several command line elements that I was missing. I have never had previous difficulty with Cygwin, but after this reinstallation, an error message continues to appear after (almost) each command entered. For instance:
-bash-4.1$ wc m1.txt
3 [main] bash 2216 child_info_fork::abort: data segment start: parent(0x26D000) != child(0x38D000)
-bash: fork: retry: Resource temporarily unavailable
2013930 4027950 74968256 m1.txt
Generally, the command still runs (as seen above), but not always. Occasionally, the 'error' message occurs several times in a row (the initial number "3" will then change to a "4" or "2", notably if I start a second Cygwin window.
Also, as soon as I start up Cygwin, I get the following message before the prompt:
3 [main] bash 6140 child_info_fork::abort: data segment start: parent(0x26D000) != child(0x36D000)
-bash: fork: retry: Resource temporarily unavailable
-bash: fork: Resource temporarily unavailable
-bash-4.1$
At the moment, I am debating whether to uninstall/reinstall Cygwin again or just live with the error messages, but I was curious if there might be an issue that I am unaware of.
(assuming Cygwin is installed at C:\Cygwin):
Open Task Manager and close any processes that look to be Cygwin related.
Open C:\Cygwin\bin in Windows Explorer
Verify that dash.exe, ash.exe, rebase.exe, and rebaseall exist in this folder
If any of them are missing, re-run Cygwin setup and select the dash, ash, and rebase packages
right-click your C:\Cygwin folder, uncheck Read-only (if its checked), and press OK.
When an error about not being able to switch some files comes up, select "Ignore All". Wait for this process to complete.
Browse to C:\Cygwin\bin in Windows Explorer
Right click dash.exe and click "Run as Administrator". A command Prompt should appear with nothing but a $
Type /usr/bin/rebaseall -v, hit enter, and wait for the process to complete.
If you get errors about Cygwin processes running, try Step 1 again. If that still doesn't work, Restart your computer into safe mode and try these steps again.
A commenter noted that, depending on your settings, you may have to type cd /usr/bin && ./rebaseall -v instead.
Try opening Cygwin again.
This process worked for me. I hope it works for you guys too.
Source: http://cygwin.wikia.com/wiki/Rebaseall
I would like to add the following to the above answers, as it is what I had to do after reinstalling Cygwin:
Navigate to the "/usr/bin" directory (usually, C:\cygwin\bin) and right click, Run as Administrator the file: dash.exe
Then, at the $ prompt type the following, hitting enter after each line:
cd /usr/bin/
/usr/bin/peflags * -d 1
/usr/bin/rebaseall -v
What it does is, it marks the dll's as "rebase-able," and then rebases them. You have to have peflags.exe in addition to the above files (in previous answers). You may have to restart windows after doing this and you will definitely need to make sure that there are no processes nor services belonging to cygwin running. (Use task manager, kill any related processes, and then under the services tab look for any service starting with CYG and stop it.)
After doing this, I was able to get cygwin to run without any errors about dll's being loaded to the wrong addresses aka fork errors, etc.
I hope that this helps others, as it was a pain to find.
SOURCE: http://www.cygwin.com/faq.html#faq.using.fixing-fork-failures
and the rebase README file.
To add on to other answers here, we ran into the same issue but could not run the rebase command from the ash or dash shell. However, when launching the command from the Windows cmd shell, the following worked.
cmd /c "C:\cygwin64\bin\ash.exe /usr/rebaseall -v"
-v is to get verbose output
I found another information here :
http://cygwin.com/ml/cygwin/2014-02/msg00531.html
You have to delete the database at
/etc/rebase.db* and do in a "ash" windows :
peflags * -d 1
rebaseall
It works for me on 2 servers.
I solved this problem by restarting my computer. Probably installed a driver update and kept using sleep instead of shutting down.
Experienced the same issue when loading Cygwin with cygiconv-2.dll forking and not loading successfully in the Cygwin terminal, but after turning off my AntiVirus (it was specifically Ad-aware), the issue resolved, and Cygwin worked properly.
In case you are using babun's Cygwin, after rebaseall, try launching Cygwin by executing .babun\cygwin\cygwin.bat in a Windows command prompt or Windows explorer.
This works for me (while launching babun's default console - mintty results in fork error).
I had the error on win10 and i was trying to rebase to c: before install.
then i saw that the installer was installing it instead to c:/Users/myuser
so i was coping all files from c:/Users/myuser to c:.badun
and then restart plus open badun.bat
not shure if this was wise its now duplicated XD... but then it worked again.
Rebaseing didn't help in my case. In addition to what other people suggested, I noticed that reducing the length of PATH environment variable fixed the issue for me (and for other people as well as can be seen from this answer).
This issue is intermittent in nature & I found this issue when there is network is too slow to connect to remote machine on AWS.... I have Shell script that runs through Gitbash shell & it connects to AWS EC2 instance with ssh..... Most of the time, it ran correctly but 2 out 100 times it get into this issue bash: fork: retry: Resource temporarily unavailable .... Killing the MSYS2 terminal from task manager helps to overcome with this issue....
Negative side is you need to run the scripts from the beginning...
I had the same issue on Windows 10 and the mobaxterm app (which uses cygwin) and I tried all of answers listed here however for me, the solution was to simply delete the "CryptoPro CSP" application.
I started facing this problem after upgrading to windows 10. As of now I do not see that any of the above method working.
What I am noticing is that if you start cygwin with admin right (right click and say "run as admin") then it works fine.
Or you open cmd as administrator and then launch cygwin from there, then also it runs fine.
Just reinstall cygwin and select TCL and activate EXPECT

What has happened to startx on Cygwin?

I just had my desktop computer replaced. Both my previous computer and this one have Windows XP. In order to work with the many Linux servers we have, I installed Cygwin along with its xterm package. However, I cannot run startx to start the X-window server as I did with my previous computer. I've been looking online to see why startx is missing from my install, but I haven't found anything yet. Any help would be greatly appreciated.
[Does more research] Well, I just installed the xinit package, which I do not recall having to do before. (It may have been a requirement for the xterm package the last time I installed Cygwin.) startx now exists, but I wouldn't say it works. The X-window server it starts creates a window that covers my entire monitor with three terminals within it, unlike the old 25 line x 80 column single terminal window I'm used to. Worse, I can't just spawn child windows like I used to, which was the real power of using Cygwin with X-windows.
OK, after doing more research and getting help from one of my coworkers, I have found a solution to my problem.
What has happened is that, although startx exists, it now starts the X server in fullscreen mode by default instead of multiwindow mode. Looking back, I probably could have copied /etc/X11/xinit/xinitrc to ~/.xinitrc and customized it. However, it turns out that there are other startup scripts for the X server which are easier to modify. (See http://x.cygwin.com/docs/ug/using.html.)
In this case, I took the script startxwin.bat. I then made a couple of changes to startxwin.bat:
I added a drive letter to the CYGWIN_ROOT because my work environment has my home directory outside of the C drive.
I added a "+tb" option to the xterm call to suppress the menubar at the top of the X-window.
The nifty thing is that by going to Start → Programs → Cygwin-X → Xwin Server, I can open a GUI Cygwin X-window without ever opening the standard Cygwin command line. This was decidedly not the case with my previous installation.
I should add that I made these changes after expanding my selection of packages. Instead of just installing X11 → xterm, I followed the recommendations in step 15 of http://x.cygwin.com/docs/ug/setup-cygwin-x-installing.html and installed:
X11 → X-start-menu-icons
X11 → xinit
X11 → xorg-docs
X11 → xorg-server
(This selection picked up X11 → xterm as a required package.) While I see no obvious reason why the directions above wouldn't have worked with just X11 → xterm and X11 → xinit installed, I haven't put that theory to the test, and I have little desire to blow away my current installation and rebuild it to prove my theory.
I hope this helps other people avoid some pain.
Disclaimer: I know this answer does not answer your question directly, but it offers a good alternative.
I use Cygwin + XMing to run remote X applications:
Launch XMing
Start my favorite Cygwin shell (zsh)
export DISPLAY=localhost:0
ssh -X myserver.domain
Run X programs
Works like a charm. The best part is that XMing can neatly integrate X windows into the Windows GUI, i.e. each X app has its own full-right window.
Thanks, this helped me a bit (finding out about installing xinit). That new startx window was really crappy, a friend helped me solve it in another way: by starting with: startxwin.sh instead of startx. Then it looked like the "old" one, and worked much better.
When you installed Cygwin, did you install the full package set? The default is to only install a baseline of packages which may not include X.
Run setup.exe again and ensure the X11 packages are installed. I just click on the little double arrows next to "All" until it says "Install". It may be you chose "Default" instead.
It's better to have a full install since I remember having problems with Cygwin dependencies in the past and now, when I run 'Start', 'All Programs', 'CygWin-X', 'XWin Server', it runs fine, opening up one shell, then 'xterm &' opens another shell.
So I really think you need to install the lot. You could try, at a bare minimum, the whole X11 group (not just xinit) but you may as well do the lot, especially given the powerful commands you get.
I always run Cygwin install twice ... the first time, I just install default packages, and the second time, I install EVERYTHING. The download takes forever, but in this way I always have almost everything I could possibly want. (I like how on Cygwin I can install everything and there are no conflicts, unlike some Linux distributions where there are packages that do the same thing in different ways which can't be installed at the same time. But of course Cygwin has an easier job of this than a full OS ... there's no Cygwin sendmail, for example.)
I have to install Cygwin on a new machine tomorrow, so this question freaks me out. I'm going to die if startx isn't working. I hope it turns out that you're just missing a package. I highly recommend installing everything.

Resources