Skip to content
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

Closed
jeffwubj opened this issue Jul 6, 2018 · 4 comments
Closed

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

jeffwubj opened this issue Jul 6, 2018 · 4 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Darwin WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@jeffwubj
Copy link

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 ianlancetaylor added OS-Darwin NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jul 6, 2018
@ianlancetaylor ianlancetaylor added this to the Go1.11 milestone Jul 6, 2018
@ianlancetaylor
Copy link
Contributor

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.

@ianlancetaylor ianlancetaylor added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jul 10, 2018
@ianlancetaylor ianlancetaylor modified the milestones: Go1.11, Go1.12 Jul 10, 2018
@jeffwubj
Copy link
Author

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.

@ianlancetaylor ianlancetaylor removed the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Aug 1, 2018
@ianlancetaylor
Copy link
Contributor

I can't recreate this problem on Darwin 10.12 with Go 1.12beta1. The programs works as expected.

What version of Darwin are you using? Can you try Go 1.12 beta1?

@ianlancetaylor ianlancetaylor added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Dec 21, 2018
@gopherbot
Copy link

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@golang golang locked and limited conversation to collaborators Jan 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Darwin WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

3 participants