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

os/signal: SIGINT cannot be catched with cgo system("ls") call #26245

Open
jeffwubj opened this Issue Jul 6, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@jeffwubj

jeffwubj commented Jul 6, 2018

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.9.3 darwin/amd64

Does this issue reproduce with the latest release?

Yes with
go version go1.10.3 darwin/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/wujeff/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.9.3/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.9.3/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/s8/rvfmqfnd28qb86358xcy1zbr00_t7y/T/go-build817291637=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

package main

import (
"fmt"
"os"
"os/signal"
)

/*
#include <stdlib.h>
static inline void RunCmd() {
system("pwd");
}
*/
import "C"

func main() {
fmt.Println("let's test...")
wait := make(chan bool)
C.RunCmd()
fmt.Println("run command finished")
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func() {
for sig := range c {
fmt.Println(sig.String())
os.Exit(0)
}
}()
select {
case <-wait:
os.Exit(0)
}
}
build the go file then press command+c in Mac to interrupt

What did you expect to see?

process exit successfully

What did you see instead?

lots of error messages:
fatal: morestack on g0
fatal: morestack on g0
fatal: morestack on g0

@ianlancetaylor

This comment has been minimized.

Contributor

ianlancetaylor commented Jul 6, 2018

I can't recreate the morestack on g0 message. I agree that on Darwin calling the C library system function does seem to disable ^C and ^\. If somebody can get an strace of the program, that might show the problem.

The system function is documented to ignore SIGHUP and SIGINT, which is probably somehow causing this. If you can avoid using the system function, you should. Go provides similar functionality in the os/exec package.

@jeffwubj

This comment has been minimized.

jeffwubj commented Jul 31, 2018

Hi Ian,
Thanks for looking at this, I have attached trace file:
sigmiss.txt

Unfortunately, I need to use system as we are loading an existed c lib for some functionalities.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment