Makefile execution: permission denied - go

I've got a quite strange problem with golang and Makefile (on Fedora 33).
My Makefile contains:
run:
go run main.go
which should only print "Hello" to the console. When I run make run I get this error:
go run main.go
make: go: Permission denied
make: *** [Makefile:5: run] Error 127
However, if I change my Makefile to
run:
/usr/bin/go run main.go
it works just fine!
INFO
Outputs of:
$ which go
/usr/bin/go
$ go version
go version go1.15.5 linux/amd64
$ uname -a
Linux localhost.localdomain 5.9.10-200.fc33.x86_64 #1 SMP Mon Nov 23 18:12:50 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Can someone help me with this? If you need more info please tell me!
Thank you!
EDIT
Console
$ echo ${PATH}
/usr/lib64/ccache:/usr/local/bin:/usr/bin:/bin:/home/olena/bin:/usr/local/sbin:/usr/sbin:/var/lib/snapd/snap/bin
Output of make
echo /usr/lib64/ccache:/usr/local/bin:/usr/bin:/bin:/home/olena/bin:/usr/local/sbin:/usr/sbin:/var/lib/snapd/snap/bin
/usr/lib64/ccache:/usr/local/bin:/usr/bin:/bin:/home/olena/bin:/usr/local/sbin:/usr/sbin:/var/lib/snapd/snap/bin
go run main.go
make: go: Permission denied
make: *** [Makefile:6: run] Error 127
In /usr/bin
$ ll | grep go
lrwxrwxrwx. 1 root root 20 Nov 14 09:32 go -> /etc/alternatives/go
In /etc/alternatives
$ ll | grep go
lrwxrwxrwx. 1 root root 22 Nov 29 15:16 go -> /usr/lib/golang/bin/go

I ran to the same issue as yours and finally figured out what was wrong with mine. Maybe this works for you, especially if you use zsh with omz.
In my case, one of the locations defined in $PATH contains a folder named go. That location came before where go binary was in. Once I put that location to be after the binary location, everything just worked.
I believe maybe it has something to do with omz and how its shell functions allow you to go into a folder.

you can add '#' before command to hide output in terminal
run:
#/usr/bin/go run main.go
it outputs only 'Hello'

Related

golang - No such file or directory even when file exists

I have a container running go1.18. But I am not able to execute a go binary file on it.
The error I get is No such file or directory even though the file exists on the system.
root#b5840a7e3deb:/goapp# go get bitbucket.xvz.com/xxx_gosdk/genlog
go: downloading bitbucket.xvz.com/xxx_gosdk/genlog v0.0.0-20180720150703-5438fece8851
go: downloading gopkg.in/yaml.v2 v2.4.0
go: downloading github.com/pkg/errors v0.9.1
root#b5840a7e3deb:/goapp# go generate ./applogs/...
applogs/loggen.go:2: running "genlog": exec: "genlog": executable file not found in $PATH
root#f27b28c39c4b:/goapp# echo $PATH
/go/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/go/bin
root#f27b28c39c4b:/goapp# find . -name genlog
./target/bin/genlog
root#f27b28c39c4b:/goapp# export PATH=/goapp/target/bin:$PATH
root#f27b28c39c4b:/goapp# go generate ./applogs/...
applogs/loggen.go:2: running "genlog": exec: "genlog": executable file not found in $PATH
root#f27b28c39c4b:/goapp# ./target/bin/genlog
bash: ./target/bin/genlog: No such file or directory
root#f27b28c39c4b:/goapp# ls -ltr ./target/bin/genlog
-rwxr-xr-x 1 root root 5785472 Jul 15 11:55 ./target/bin/genlog
root#b5840a7e3deb:/goapp# cd target/bin/
root#b5840a7e3deb:/goapp/target/bin# ./genlog
bash: ./genlog: No such file or directory
root#f27b28c39c4b:/goapp# go version
go version go1.18.3 linux/amd64
Not sure what could be the reason of this?
Both file and linux are 64-bit.
root#b5840a7e3deb:/goapp/target/bin# file genlog
genlog: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-x86_64.so.1, Go BuildID=5_YjQVva2uu05mM9OtMl/4DKTh04b6KayyO-oCXMx/S56k25kGovKc_B70LVqf/UnqDZDQQtMFSIfz-py0j, not stripped
root#b5840a7e3deb:/goapp/target/bin# uname -a
Linux b5840a7e3deb 5.4.17-2136.308.9.el7uek.x86_64 #2 SMP Mon Jun 13 20:40:51 PDT 2022 x86_64 x86_64 x86_64 GNU/Linux
Update: I figured that I was missing a program interpreter which I installed using apt-get. But `ldd` is still complaining that the interpreter is missing.
root#f718aa896bd6:/goapp/target/bin# ldd genlog
linux-vdso.so.1 (0x00007ffedee39000)
libc.musl-x86_64.so.1 => not found
root#f718aa896bd6:/goapp/target/bin# readelf -a genlog | grep interpreter
[Requesting program interpreter: /lib/ld-musl-x86_64.so.1]
root#f718aa896bd6:/goapp# ls /lib/ld-musl-x86_64.so.1
ls: cannot access '/lib/ld-musl-x86_64.so.1': No such file or directory
root#f718aa896bd6:/goapp# apt-get install musl
...
Unpacking musl:amd64 (1.1.24-1) ...
Setting up musl:amd64 (1.1.24-1) ...
root#f718aa896bd6:/goapp# cd target/bin/
root#f718aa896bd6:/goapp/target/bin# ls -ltr /lib/ld-musl-x86_64.so.1
lrwxrwxrwx 1 root root 25 Oct 13 2019 /lib/ld-musl-x86_64.so.1 -> x86_64-linux-musl/libc.so
root#f718aa896bd6:/goapp/target/bin# ./genlog
genlog: error while reading file '': open : no such file or directory
root#f718aa896bd6:/goapp/target/bin# ldd genlog
linux-vdso.so.1 (0x00007ffedee39000)
libc.musl-x86_64.so.1 => not found
root#f718aa896bd6:/goapp/target/bin# readelf -a genlog | grep interpreter
[Requesting program interpreter: /lib/ld-musl-x86_64.so.1]

Use "perl6" command with Git Bash on windows

Using Windows, I installed Rakudo Star and Git and ensured that C:\rakudo\bin and C:\rakudo\share\perl6\site\bin are in my Path environment variable.
Now, typing perl6 inside Git Bash afterwards gives the command not found error, while the command does work inside powershell and cmd. Typing echo $PATH inside Git Bash confirms again that the folders above are in my path variable here as well.
How can I get the perl6 command working inside Git Bash?
Note: Using moar (moar.exe) which resides in the same folder as perl6 works as well in Git Bash. Also hitting Tab show the autocomplete suggestion for moar, it does not do that for perl6.
Bash doesn't run Windows batch files, so you'll have to work around that.
An easy solution might be to add something like this you your .bashrc:
alias perl6='cmd /c perl6.bat'
Alternatively, you can convert perl6.bat to a shell script and put it somewhere in your $PATH.
I use the following:
#!/bin/sh
PATH=/cygdrive/c/rakudo/bin:/cygdrive/c/rakudo/share/perl6/site/bin:$PATH
unset HOME
moar --execname="$0" \
--libpath='C:\rakudo\share\nqp\lib' \
--libpath='C:\rakudo\share\perl6\lib' \
--libpath='C:\rakudo\share\perl6\runtime' \
'C:\rakudo\share\perl6\runtime\perl6.moarvm' \
"$#"
This is using Cygwin; you may need to adapt it a bit for Git bash (I don't know, no experience with it).
Alternatively, if you're using Windows 10, I can recommend installing WSL, and using perl6 in a WSL bash prompt instead. This runs much smoother for me than the Windows version under Cygwin.
I tried to install perl6 from the link you provided and I can confirm the same behavior on Cygwin on Windows 10.
If I type in the Cygwin terminal window:
$ perl6
-bash: perl6: command not found
$ echo $PATH
/usr/local/bin:/usr/bin:/cygdrive/c/WINDOWS/system32:/cygdrive/c/WINDOWS:/cygdrive/c/WINDOWS/System32/Wbem:/cygdrive/c/WINDOWS/System32/WindowsPowerShell/v1.0:/cygdrive/c/WINDOWS/System32/OpenSSH:/cygdrive/c/Users/Bruker/AppData/Local/Microsoft/WindowsApps:/cygdrive/c/rakudo/bin:/cygdrive/c/rakudo/share/perl6/site/bin
$ cd /cygdrive/c/rakudo/bin
$ ls -l
-rwxrwx---+ 1 SYSTEM SYSTEM 930663 May 11 2017 libgcc_s_seh-1.dll
-rwxrwx---+ 1 SYSTEM SYSTEM 136146 Mar 30 20:55 libmoar.dll.a
-rwxrwx---+ 1 SYSTEM SYSTEM 56978 May 11 2017 libwinpthread-1.dll
-rwxrwx---+ 1 SYSTEM SYSTEM 7021172 Mar 30 20:55 moar.dll
-rwxrwx---+ 1 SYSTEM SYSTEM 64066 Mar 30 20:55 moar.exe
-rwxrwx---+ 1 SYSTEM SYSTEM 126 Mar 30 20:56 nqp.bat
-rwxrwx---+ 1 SYSTEM SYSTEM 126 Mar 30 20:56 nqp-m.bat
-rwxrwx---+ 1 SYSTEM SYSTEM 242 Mar 30 20:56 perl6.bat
-rwxrwx---+ 1 SYSTEM SYSTEM 248 Mar 30 20:56 perl6-debug-m.bat
-rwxrwx---+ 1 SYSTEM SYSTEM 242 Mar 30 20:56 perl6-m.bat
$ cat perl6.bat
# "C:\rakudo\bin\moar" --execname="%~dpf0" --libpath="C:\rakudo\share\nqp\lib" --libpath="C:\rakudo\share\nqp\lib" --libpath="C:\rakudo\share/perl6/lib" --libpath="C:\rakudo\share/perl6/runtime" C:\rakudo\share\perl6\runtime\perl6.moarvm %*
Notice that the paths in the bat file are not cygwin paths. So that might explain why it does not work..
For example:
$ "C:\rakudo\bin\moar"
-bash: C:\rakudo\bin\moar: command not found
$ /cygdrive/c/rakudo/bin/moar
ERROR: Missing input file.
USAGE: moar [--crash] [--libpath=...] input.moarvm [program args]
moar --dump input.moarvm
moar --help
[...]
Update:
I also tried install Git Bash, and then from the MINGW64 terminal window:
$ echo $PATH
/c/Users/Bruker/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/mingw64/bin:/usr/bin:/c/Users/Bruker/bin:/c/WINDOWS/system32:/c/WINDOWS:/c/WINDOWS/System32/Wbem:/c/WINDOWS/System32/WindowsPowerShell/v1.0:/c/WINDOWS/System32/OpenSSH:/c/Users/Bruker/AppData/Local/Microsoft/WindowsApps:/usr/bin/vendor_perl:/usr/bin/core_perl
$ PATH=/c/rakudo/bin:$PATH
$ perl6
bash: perl6: command not found
$ moar
ERROR: Missing input file.
USAGE: moar [--crash] [--libpath=...] input.moarvm [program args]
moar --dump input.moarvm
moar --help
[...]
Note that moar is an .exe file while perl6 is a .bat file.
Also it seems perl6 is not "offical" for Cygwin yet according to this issue.

Running make in Cygwin does... nothing?

I'm trying to build gcc-7.1.0 locally on Windows via Cygwin (I already have gcc 5.4.0 installed and functioning). I downloaded the tar, ran the configure program in its own directory as prescribed, which yielded:
~/build-gcc
$ ll
total 609
-rw-r--r-- 1 Barry None 31021 Aug 12 09:08 config.log
-rwxr-xr-x 1 Barry None 33630 Aug 12 09:08 config.status
-rw-r--r-- 1 Barry None 551897 Aug 12 09:08 Makefile
-rw-r--r-- 1 Barry None 13 Aug 12 09:08 serdep.tmp
Great, now:
$ make -j4
$
Nothing.
$ make --version
$
Nothing again.
$ which make
/usr/bin/make
$ cygcheck -c make
Cygwin Package Information
Package Version Status
make 4.2.1-2 OK
So it exists at least. And trying to reinstall make via cygwin suggests that everything is up to date. What's going wrong here?

JSON2CSV install/setup issue (via Go)

I'm attempting to install https://github.com/jehiah/json2csv. The problem is apparently tied to my noob status w.r.t. Bash.
System: Ubuntu 14.04 LTS
Load instruction:
$ go get github.com/jehiah/json2csv
Go is installed:
$ which go ==> /usr/bin/go
~/.bashrc setup:
export GOROOT=/usr/bin/go
export GOPATH=$HOME/projects/go
The package seems to download correctly:
$ cd projects/go
$ tree
$ > bin > json2csv
> src > github.com
...
$ ls bin -l
$ > -rwxrwxr-x 1 <user> <user> 55400 Feb 5 13:57 json2csv
But $json2csv isn't recognized, even from the same directory. I'm sure this is a noob problem, but I haven't cracked it yet. Suggestions?
Add $GOPATH/bin to your PATH variable in your shell,
for bash:
export PATH=$GOPATH/bin:$PATH

Automake/autoconf configuration to install as SUID

Is there a way to configure a binary to be installed as "SUID" using automake/autoconf?
Is there any magick that can lead a make install to set the suid bit of a given binary target?
NOTE:
I am running a "fakerooted" make install inside a script to create a tar file.
I tried:
# Makefile.am
bin_PROGRAMS = my_bin
#...
install-exec-hook:
echo "#### Setting SUID for my_bin. ####"
ls -l $(DESTDIR)$(bindir)/my_bin
chmod 4755 $(DESTDIR)$(bindir)/my_bin
ls -l $(DESTDIR)$(bindir)/my_bin
echo "####-------------------------------####"
But with no success.
During make install I see:
#### Setting SUID for sudo_script. ####
-rwxr-xr-x 1 root root 8704 Mar 28 13:30 /install.pak/usr/bin/my_bin
-rwsr-xr-x 1 root root 8704 Mar 28 13:30 /install.pak/usr/bin/my_bin
####-------------------------------####
So one could think it is a problem with fakeroot, but if I move the chmod out of Makefile.am to my packaging script, it works. This is enough to convince me fakeroot is doing its job.
Thanks.
GAHH!!
Someone unconsciously put in my script, after $FAKEROOT make install:
$FAKEROOT chmod 755 $PAK_DIR/usr/bin/*
replacing all the permissions writen by make install.
Removing this line the install-exec-hook works as expected and the SUID bit is preserved...
(Were did I put my ax?...)

Resources