Join GitHub today
Multiple bash/ping processes on Windows 7 with Cygwin installed #216
I discovered an ever-growing list of bash.exe/ping.exe processes on my Windows 7 64bit system caused by the Prey "pull" script. The script naively assumes only two possible ping commands, based on OS, then sets command line arguments. Neither of the options work with the Cygwin ping program which is what was available in the path. Even worse, the options cause the Cygwin ping program not to return (clearly a Cygwin problem since "-c" and "-n" aren't valid options) which is why bash/ping processes were accumulating.
Any of these would be workable solutions:
I found one discussion forum thread on the subject:
And one recent issue that might be related:
Is 'which ping' any use? Does that return cygwin's ping?
What does 'echo $PATH' look like for you & for the user that Prey runs under (sorry I don't know Windows too well).
I'm wondering if there is a reliable dynamic way to get pings path and avoid code forking for Windows. I suspect adding a ping.exe binary in the platform/windows/bin is the easiest solution? Is there a suitable one that uses the same args.
core/setup adds that folder to the $PATH so it should be found first & it won't affect Linux/ Mac.
"which ping" returns the cygwin ping but I expect that since I manually added the cygwin bin dir to my path. But it's not first and it doesn't look like the Prey setup added the Prey path to the Windows path. If it had added the MingW utils to my path I probably would have noticed other odd behavior in my local terminal sessions since it would have tried to run the MingW bash.exe rather than the Cygwin version.
Anyway, to accommodate a pre-existing *NIX environment on a Windows workstation, I might try assuming the location of ping.exe on Windows ($WINDIR/system32 or $SYSTEMROOT/system32 should work). Here's some untested code to give you an idea of what I'm describing:
local net_check_target="www.google.com" if [ "$os" == "windows" ]; then local ping_cmd="$SYSTEMROOT/system32/ping -n" else local ping_cmd='ping -q -c' fi connected=`$ping_cmd 1 $net_check_target &> /dev/null && echo 1 || echo 0`
The other alternative is to include a ping.exe in the Prey environment however I did a quick look-around and I didn't find existing work building ping.exe with MingW so my assumption is that it might require a port to that environment.
Really happy you could spot this one out. I guess I never assumed that Cygwin would overlap Windows' execution paths.
I guess there's no problem of bundling a win32 native ping.exe binary in Prey (searching Google for "gnuwin32 ping" yields a bunch of results), but I guess you're solution is a cleaner one. Did you get to test it?