Redirection to file doesn't work when snap program invokes another snap program via shell
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
snapd |
New
|
Undecided
|
Unassigned |
Bug Description
Hi!
I'm using snap 2.49.1 on Debian 10. The issue is also reproducing on snap 2.49.1 on Ubuntu 20.04 in VirtualBox.
I'm experiencing a very strange bug with, apparently, all programs installed via snap --classic.
If I run program FOO, installed from snapcraft, and it runs a shell, which in turn runs program BAR, also installed from snapcraft, and BAR's output is redirected to a file, I always get zero exit code, but an EMPTY FILE.
If, instead of BAR, FOO runs some non-snap program, it works as expected. If FOO redirects BAR's output to cat's stdin, and redirects cat's stdout to a file, it also works as expected.
Here are some examples with "ruby" from snap:
$ sudo snap install ruby --classic
...
$ cat hello.rb
puts "hello from ruby"
GOOD:
$ /snap/bin/ruby hello.rb > out
$ cat out
hello from ruby
GOOD:
$ /snap/bin/ruby -e 'system(
$ cat out
hello from ruby
GOOD:
$ /snap/bin/ruby -e 'system("echo hello from shell > out")'
$ cat out
hello from shell
>>>>>>>> BAD <<<<<<<<
$ /snap/bin/ruby -e 'system(
$ cat out
<nothing>
Here are similar examples with "go: from snap:
$ sudo snap install go --classic
...
$ cat hello.go
package main
import "fmt"
func main() {
fmt.
}
$ cat exec.go
package main
import "syscall"
import "os"
func main() {
syscall.
}
GOOD:
$ /snap/bin/go run hello.go > out
$ cat out
hello from go
GOOD:
$ /snap/bin/go run exec.go "/snap/bin/go run hello.go | cat > out"
$ cat out
hello from go
GOOD:
$ /snap/bin/go run exec.go "echo hello from shell > out"
$ cat out
hello from shell
GOOD (non-snap go):
$ /usr/bin/go run exec.go "/usr/bin/go run hello.go > out"
$ cat out
hello from shell
>>>>>>>> BAD <<<<<<<<
$ /snap/bin/go run exec.go "/snap/bin/go run hello.go > out"
$ cat out
<nothing>
Please let me know if I can provide any further information!
affects: | snapcraft → snapd |
Fun fact: originally I faced this issue when compiling BoringSSL. I had both CMake and Go installed from snap. BoringSSL can't be built with this setup, since CMake invokes "go run file.go > file.c" for code generation during build, and it produces an empty file instead of the desired code.
For people coming from Google: if you're using snap and get strange linker errors when building BoringSSL, you're probably facing the same issue:
/usr/bin/ld: libcrypto. a(err.c. o): in function `ERR_reason_ error_string' : crypto/ err/err. c:579: undefined reference to `kOpenSSLReason ValuesLen' crypto/ err/err. c:578: undefined reference to `kOpenSSLReason Values' crypto/ err/err. c:578: undefined reference to `kOpenSSLReason StringData'
boringssl/
/usr/bin/ld: boringssl/
/usr/bin/ld: boringssl/