Skip to content

goinstall fails on Windows, sh: ./goinstall: Bad file number #1826

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

Closed
gopherbot opened this issue May 14, 2011 · 29 comments
Closed

goinstall fails on Windows, sh: ./goinstall: Bad file number #1826

gopherbot opened this issue May 14, 2011 · 29 comments

Comments

@gopherbot
Copy link
Contributor

by jcowgar:

What steps will reproduce the problem?

C:\Development\Go> goinstall github.com/dchest/gotweet/src

-- or --

C:\Development\Go> goinstall


What is the expected output?
No output, just the installation of the package

What do you see instead?
sh: ./goinstall: Bad file number

Which compiler are you using (5g, 6g, 8g, gccgo)?
N/A

Which operating system are you using?
Windows 7 Home Premium

Which revision are you using?  (hg identify)
hg not installed, using the May 3rd release of Go, 

gowin32_release.r57.1_installer.exe

Please provide any additional information below.
@gopherbot
Copy link
Contributor Author

Comment 1 by jcowgar:

I built Go from sources to determine if it was an installer issue, a host build issue,
etc... I have the same result when using goinstall that was built on my own box from the
version: 95d2ce135523 (release-branch.r57) release/release.r57.1

@alexbrainman
Copy link
Member

Comment 2:

I can't reproduce your problem. I hit different problem:
C:\>goinstall github.com/dchest/gotweet/src
goinstall: github.com/dchest/gotweet/src: mkdir c:\a\src\pkg\github.com\dchest\: The
system cannot find the path specified.
C:\>
It seems os.Mkdir only handles '/' path delimiters, but not '\'.
Perhaps you have some ideas how to reproduce your problem. Perhaps you can put
fmt.Printf() statements inside goinstall to see where it fails and why. Thank you.
Alex

Status changed to WaitingForReply.

@alexbrainman
Copy link
Member

Comment 3:

Owner changed to @alexbrainman.

@gopherbot
Copy link
Contributor Author

Comment 4 by jcowgar:

I have tried to add printf statements but nothing prints. I continue to get:
sh: ./goinstall.exe: Bad file number
The exit code is 126. This seems like an error with the operating system launching the
program itself. I have tried to take all of the init() functions and var definitions
that may be causing this problem and put them into a test.go program, so far I cannot
make the test.go program fail as goinstall does.
Is it possible to obtain a copy of your goinstall.exe to see if your identical
goinstall.exe fails on my machine? That may lead somewhere.

@alotabits
Copy link

Comment 5:

I am getting the same error and I agree that it appears to be a problem with launching
the executable. The error seems to be coming from sh and not goinstall itself.

@alexbrainman
Copy link
Member

Comment 6:

I'm pretty sure you're right about some executable is not right, but I'm trying to
understand who calls who.
Could you, please, use full path when running goinstall, and also use -v parameter, and
report the result:
C:\Development\Go> C:\Development\Go\src\cmd\goinstall\goinstall -v
github.com/dchest/gotweet/src
Thank you.
Alex

@gopherbot
Copy link
Contributor Author

Comment 7 by jcowgar:

When I run this command from the cmd.exe prompt, I first get a User Access Control
dialog from Windows asking if it is OK for this program to make changes to my computer.
If I choose no, I get an access denied error. If I choose yes, a new command prompt
window appears for a split second and then disappears. Windows then shows a dialog box
stating the program was not installed properly, do I wish to reinstall it.
When running this command from the MSYS shell (sh.exe) I continue to get the original
error except with the full path:
sh: /c/Go/bin/goinstall.exe: Bad file number

@alexbrainman
Copy link
Member

Comment 8:

Please do this:
1) change to goinstall source directory
cd $GOROOT/src/cmd/goinstall
2) delete the file
make clean
3) make sure it is gone
ls -l goinstall.exe
4) build it again
make all
5) make sure it is there (send us the output)
ls -l goinstall.exe
6) run it
./goinstall.exe -v github.com/dchest/gotweet/src
also, please tell us what
8g -V
say. Thank you.
Alex

@gopherbot
Copy link
Contributor Author

Comment 9 by jcowgar:

Seeing this error it just dawned on me what is happening. It's all in the name! User
Access Control (UAC) has something it calls Installer Detection Technology, please see:
http://technet.microsoft.com/en-us/library/dd835540%28WS.10%29.aspx ... Scroll within
the page to the section titled "Installer detection technology"
Basically Windows sees the word "install" in the executable and automatically determines
that the executable requires Admin privileges and thus tries to elevate the executable
permission. I renamed the executable to goinst.exe and I now get the error that you are
getting... 
goinst: github.com/droundy/goopt: mkdir C:\Go\src\pkg\github.com\droundy\: The s
ystem cannot find the path specified.
I'll bet that you have UAC disabled and that is why you are not seeing the initial
problem I and others are reporting, but that's just a guess.
I have not read entirely about the Installation detection technology but I believe it is
possible to embed a resource stating this program does not require elevated privileges.
I will do more research on this and report back. If so, the new patch on the mailing
list dealing with embedding resources via the linker could be used or possibly a
.exe.manifest file could be created or the command name could be renamed (not a good
thing because then there are platform differences in fundamental commands).
I also have an idea about why we are now getting the above error. I will submit a patch
a little later today (wee hours in the morning here, need sleep before work starts :-)

@gopherbot
Copy link
Contributor Author

Comment 10 by jcowgar:

I tried to use the code-login process to submit this patch, but on Windows the install
of Mercurial continues to state:
*** failed to import extension codereview from C:/Development/Projects/go/go/lib
/codereview/codereview.py: No module named HTMLParser
I have no idea why, I do not use Mercurial or Python other than for the go checkout.
Anyway, I have attached a manifest file that causes goinstall.exe to not request
elevated privileges. This manifest file would have to be installed in the same location
as goinstall.exe to function. Also, when testing, you must either recompile
goinstall.exe or update it's create date/time. Windows caches any .manifest file and if
the goinstall.exe timestamp has not changed since your last execution it does not bother
looking for a new .manifest file.
I have also attached a .rc file when used with the resource file patch:
http://golang.org/cl/4516055/ would embed the .manifest into the executable so
only 1 file has to be installed into Go/bin.
This solves the problem with this issue. It does not, however, solve other problems with
Go install that you have run into as well. Should discussion/work on those issues
continue here? BTW... after getting past the directory problem there are other problems
as well.

Attachments:

  1. goinstall.exe.manifest (402 bytes)
  2. goinstall.rc (29 bytes)

@gopherbot
Copy link
Contributor Author

Comment 11 by jcowgar:

I was able to create a code review: http://golang.org/cl/4519062/

@gopherbot
Copy link
Contributor Author

Comment 12 by jcowgar:

As to the other issues, they deal with path separators and it seems that the active code
review: http://golang.org/cl/4252044/ .. should fix this problem.

@alexbrainman
Copy link
Member

Comment 13:

I'm reluctant to make any changes. The fact that naming program goinstall.exe put you on
the "black" list seems wrong to me. Even worse, you could circumvent the system by
attaching bit of xml data to your exe file. I believe goinstall.exe users would have to
be smart enough to be able to switch "UAC Architecture" off, if so desired.
In my mind, maybe some documentation in goinstall documentation should do the trick. But
I live in a "real world" <g>, I'm happy to accept whatever solution there is to
it. 
Russ, what do you say?
Alex

@rsc
Copy link
Contributor

rsc commented May 17, 2011

Comment 14:

We're going to rename goinstall gomake in a few months anyway.
I hope "make" is not on the black list.
Russ

@alexbrainman
Copy link
Member

Comment 15:

Sounds like a plan. Let's leave this opened until then.
Alex

Labels changed: added priority-low, os-windows, security, removed priority-medium.

Status changed to Accepted.

@gopherbot
Copy link
Contributor Author

Comment 16 by jcowgar:

Just so it is understood, It is Windows attempt to do the right thing
under normal situations. Not all programs request elevated rights,
thus Windows sees that it is probably an installer, thus it asks the
user, "Is it OK for this program to change your computer?" and if they
answer yes, then it elevates the rights given to the program to that
of an administrator.
If, however, you tell Windows that this program does not require
elevated rights (what the .manifest file does), then Windows does not
bother asking the user NOR does it give the program elevated rights.
So, nothing is circumvented. You are just helping Windows understand
your programs intentions. Including the .manifest does not give your
application elevated rights w/o asking the user. The names on the
"black" list are install, setup and update.
Now... with that said, I am in agreement that if the name is changing
in a few months then nothing should be done right now. In regards to
documentation, you should not instruct someone to turn off UAC. It has
huge benefits in system safety. If you are going to do anything with
documentation I would state that there is a known problem with the
naming of goinstall on Windows machines where UAC is enabled (the
default, BTW). To get around these problems rename the executable to
goinst.exe or something to that effect.

@alexbrainman
Copy link
Member

Comment 17:

I won't argue with you. Just want to state my personal point of view.
How is goinstall.exe is different (apart from having name that MS don't like) from any
other? It is not "requesting elevated rights" from OS. It does what it is designed to
do. Questions, like "Is it OK for this program to change your computer?" are silly,
because every program changes your computer, some program write to memory, others to
disk and so on.
I don't know much about UAC to make a judgement, but what I've seen so far, tells me to
stay away from it. I think it is attempting to solve hard problems by simple/silly
solutions.
Alex

@gopherbot
Copy link
Contributor Author

Comment 18 by jcowgar:

In a nutshell it's sudo, that's all. Telling someone to disable UAC
could be seen as telling someone to just use root all the time. In
some Linux distributions when you go to install a software package,
for example, it asks for the root password. That's the same thing UAC
does. It can be silly at times, like we discovered in this case but it
was Microsoft's best attempt to make old (non-UAC aware apps) UAC
compliant, that's all. Probably solves the problem most of the time
and then in situations like ours just causes problems... in the end,
naming the executable gomake solves all these problems, so it's a good
solution. No reason to argue, just offering a more detailed
explanation of UAC for everyones understanding.

@alexbrainman
Copy link
Member

Comment 19:

Cool. Thank you for your explanation. I was offering mine too <g>.
Alex

@gopherbot
Copy link
Contributor Author

Comment 20:

Just put the following file into the same directory as the goinstall.exe and you're fine

Attachments:

  1. goinstall.exe.manifest (646 bytes)

@alotabits
Copy link

Comment 21:

The manifest file doesn't work here. The icon for goinstall changes to remove the UAC
shield emblem, but running it still gives me the "Bad file number" error.

@gopherbot
Copy link
Contributor Author

Comment 22 by jcowgar:

You will need to update (change goinstall.exe timestamp) as Windows
caches the last read manifest file based on the executables date. So,
if you ran the executable, Windows loaded any manifest file and stored
its results (or no results if no manifest file). Then running the
executable again Windows will just look at its last read manfiest even
if empty.
Jeremy

@alotabits
Copy link

Comment 23:

I remember reading that now. Thank you for reminding me.

@mark-summerfield
Copy link

Comment 24:

I added goinstall.exe.manifest and updated the timestamps and that got rid of the
annoying dialog. But goinstall really doesn't seem to understand windows paths:
C:\Go\bin>copy /b goinstall.exe.manifest +,,
Access is denied.
        0 file(s) copied.
C:\Go\bin>copy /b goinstall.exe +,,
        1 file(s) copied.
C:\Go\bin>cd c:\goeg\src
c:\goeg\src>set GOPATH=C:\goeg
c:\goeg\src>goinstall *.*
2011/07/01 12:40:59 Invalid GOPATH "C": must be absolute
goinstall: *.*: open C:\Go\src\pkg\*.*: The filename, directory name, or volume label
syntax is inco
rrect.
c:\goeg\src>set GOPATH=\goeg
c:\goeg\src>goinstall *.*
goinstall: *.*: open C:\Go\src\pkg\*.*: The filename, directory name, or volume label
syntax is inco
rrect.
c:\goeg\src>goinstall myapp1
bash: === cd \goeg\src\myapp1; bash gomake -f- install
--- exec: "bash": executable file not found in %PATH%
goinstall: installing: running bash: exec: "bash": executable file not found in %PATH%
c:\goeg\src>

@alexbrainman
Copy link
Member

Comment 25:

1) treating of GOPATH was fixed: http://code.google.com/p/go/source/detail?r=4fae10f46847
2) "goinstall *.*" will not work on windows, "goinstall *" work on unix because unix
shell converts * into the list of files/directories (goinstall does not see *), windows
does not do that. Perhaps "goinstall ."?
3) last problem is goinstall trying to execute gomake bash script, therefore it is
looking for bash in your %PATH% and it finds nothing. That problem will go away once you
will use newer version that can build without make.
Alex

@alexbrainman
Copy link
Member

Comment 26:

Issue #2290 has been merged into this issue.

@ancientlore
Copy link

Comment 27:

I think you won't have this problem if you run your shell as an administrator (using the
right-click menu option, or the runas utility).

@rsc
Copy link
Contributor

rsc commented Dec 9, 2011

Comment 28:

Labels changed: added priority-someday, removed priority-low.

@rsc
Copy link
Contributor

rsc commented Jan 29, 2012

Comment 29:

goinstall has been deleted, replaced by the go tool.
Since the go tool does not include 'install' in the name, I think we're all set.

Status changed to Fixed.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants