Re: [go-nuts] how cgo handle user define signal ? need go pass the signal handle to c

2022-02-28 Thread Robert Engels
Should be pretty easy to have a Go routine blocked in a C call waiting - then 
have the signal handler add an event to a memory queue and wake the C thread. 
Then dispatch to a Go side handler. 

> On Feb 28, 2022, at 1:49 PM, Ian Lance Taylor  wrote:
> 
> On Mon, Feb 28, 2022 at 5:08 AM LordRusk  wrote:
>> 
>> It seems this does not work. Any code ran from a C signal handler must be
>> async-signal-safe, no go code is async-signal-safe, so it sigfaults when you
>> try this. https://github.com/golang/go/issues/45499
> 
> You can't call Go code directly from the C signal handler, no.  But
> whatever mechanism you use to make C code aware that a signal occurred
> can also be used to make Go code aware that a signal occurred.
> 
>> I really wish there was a way to get around this, there is really no go api
>> for anything to do with signals beyond what can be implemented cross 
>> platform.
>> 
>> for instance, there's been an issue that's almost 8 years old about the 
>> siginfo_t
>> struct being inaccessible from go. https://github.com/golang/go/issues/9764
>> 
>> I don't think anything will come of this soon.
> 
> Go is an open source project.  That issue will be fixed if someone
> develops a workable API.
> 
> Ian
> 
> 
> 
> 
>>> On Friday, August 16, 2019 at 9:46:06 PM UTC-7 Ian Lance Taylor wrote:
>>> 
>>> On Tue, Aug 13, 2019 at 1:03 AM hui zhang  wrote:
 
 in other words
 we need a go runtime signal mask .
 just google, no such api provided by go yet .
 I want know why ?
 any workaround?
>>> 
>>> All the details of signal handling in Go can be seen at
>>> https://golang.org/pkg/os/signal.
>>> 
>>> There is no Go API to set the signal mask because the os/signal
>>> package is intended to handle that for you.
>>> 
>>> It's hard to combine C and Go code in the same program and have them
>>> both do signal handling. If your C program sends itself a signal
>>> periodically, then I recommend that you have your C code call
>>> sigaction to override the Go signal handler. If the Go code needs to
>>> know about the signal, have the C code call a Go function to do so.
>>> 
>>> Ian
>> 
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to golang-nuts+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/c81fa217-210e-4d11-a794-722d5cc64b62n%40googlegroups.com.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/CAOyqgcWEDeVVAmQ2S7NETAddgY3REkX1KJJt5u_OADUKCduTnw%40mail.gmail.com.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/6D6E3477-7B06-46D5-AC3D-18BF6641F0EA%40ix.netcom.com.


Re: [go-nuts] how cgo handle user define signal ? need go pass the signal handle to c

2022-02-28 Thread Ian Lance Taylor
On Mon, Feb 28, 2022 at 5:08 AM LordRusk  wrote:
>
> It seems this does not work. Any code ran from a C signal handler must be
> async-signal-safe, no go code is async-signal-safe, so it sigfaults when you
> try this. https://github.com/golang/go/issues/45499

You can't call Go code directly from the C signal handler, no.  But
whatever mechanism you use to make C code aware that a signal occurred
can also be used to make Go code aware that a signal occurred.

>  I really wish there was a way to get around this, there is really no go api
> for anything to do with signals beyond what can be implemented cross platform.
>
> for instance, there's been an issue that's almost 8 years old about the 
> siginfo_t
> struct being inaccessible from go. https://github.com/golang/go/issues/9764
>
> I don't think anything will come of this soon.

Go is an open source project.  That issue will be fixed if someone
develops a workable API.

Ian




> On Friday, August 16, 2019 at 9:46:06 PM UTC-7 Ian Lance Taylor wrote:
>>
>> On Tue, Aug 13, 2019 at 1:03 AM hui zhang  wrote:
>> >
>> > in other words
>> > we need a go runtime signal mask .
>> > just google, no such api provided by go yet .
>> > I want know why ?
>> > any workaround?
>>
>> All the details of signal handling in Go can be seen at
>> https://golang.org/pkg/os/signal.
>>
>> There is no Go API to set the signal mask because the os/signal
>> package is intended to handle that for you.
>>
>> It's hard to combine C and Go code in the same program and have them
>> both do signal handling. If your C program sends itself a signal
>> periodically, then I recommend that you have your C code call
>> sigaction to override the Go signal handler. If the Go code needs to
>> know about the signal, have the C code call a Go function to do so.
>>
>> Ian
>
> --
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/c81fa217-210e-4d11-a794-722d5cc64b62n%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcWEDeVVAmQ2S7NETAddgY3REkX1KJJt5u_OADUKCduTnw%40mail.gmail.com.


Re: [go-nuts] how cgo handle user define signal ? need go pass the signal handle to c

2022-02-28 Thread LordRusk
It seems this does not work. Any code ran from a C signal handler must be
async-signal-safe, no go code is async-signal-safe, so it sigfaults when you
try this. https://github.com/golang/go/issues/45499

 I really wish there was a way to get around this, there is really no go api
for anything to do with signals beyond what can be implemented cross 
platform.

for instance, there's been an issue that's almost 8 years old about the 
siginfo_t
struct being inaccessible from go. https://github.com/golang/go/issues/9764

I don't think anything will come of this soon.
On Friday, August 16, 2019 at 9:46:06 PM UTC-7 Ian Lance Taylor wrote:

> On Tue, Aug 13, 2019 at 1:03 AM hui zhang  wrote:
> >
> > in other words
> > we need a go runtime signal mask .
> > just google, no such api provided by go yet .
> > I want know why ?
> > any workaround?
>
> All the details of signal handling in Go can be seen at
> https://golang.org/pkg/os/signal.
>
> There is no Go API to set the signal mask because the os/signal
> package is intended to handle that for you.
>
> It's hard to combine C and Go code in the same program and have them
> both do signal handling. If your C program sends itself a signal
> periodically, then I recommend that you have your C code call
> sigaction to override the Go signal handler. If the Go code needs to
> know about the signal, have the C code call a Go function to do so.
>
> Ian
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/c81fa217-210e-4d11-a794-722d5cc64b62n%40googlegroups.com.


Re: [go-nuts] how cgo handle user define signal ? need go pass the signal handle to c

2019-08-16 Thread Ian Lance Taylor
On Tue, Aug 13, 2019 at 1:03 AM hui zhang  wrote:
>
> in other words
> we need a go runtime signal mask .
> just google, no such api provided by go yet .
> I want know why ?
> any workaround?

All the details of signal handling in Go can be seen at
https://golang.org/pkg/os/signal.

There is no Go API to set the signal mask because the os/signal
package is intended to handle that for you.

It's hard to combine C and Go code in the same program and have them
both do signal handling.  If your C program sends itself a signal
periodically, then I recommend that you have your C code call
sigaction to override the Go signal handler.  If the Go code needs to
know about the signal, have the C code call a Go function to do so.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcUYwNLa1NFfenJFOoQbFoX55E8T6GnNwn%2BFg2fn8YWhAA%40mail.gmail.com.


Re: [go-nuts] how cgo handle user define signal ? need go pass the signal handle to c

2019-08-13 Thread hui zhang

in other words
we need a *go runtime signal mask .*
just google, no such api provided by go yet .
I want know why ?
any workaround?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/fcdceef3-6bcc-46cc-bf37-004b379c70bc%40googlegroups.com.


Re: [go-nuts] how cgo handle user define signal ? need go pass the signal handle to c

2019-08-13 Thread hui zhang
I found the case is like this
c code
IgnoreSignal(42);
while(1) {
GoSleep(10);//simulate some call in go runtime , the runtime call stack is
in last mail
int signo = sigwaitinfo(_set, _info); //will use this signo
to do something 
// usleep(1000*1000);
printf("sleep 10s \n");
// raise(42);
}

go code
//export IgnoreSignal
func IgnoreSignal(sig int) {
signal.Ignore(syscall.Signal(sig))
}

//export GoSleep
func GoSleep(x int) {
time.Sleep(time.Duration(x) * time.Second)
}

go build an  so lib ,  c link this so
run app
send signal like below
sigqueue(pid, 42, val);

go will catch that signal ,  and  but ignore it and delete it
what I expect  is passing the signal to  *sigwaitinfo*

hui zhang  于2019年8月13日周二 上午9:58写道:

> I am trying to extend a old c program with go.Add websocket ability to
> this c program.
> first  build  go as a  .so  dynamic lib
> then link the so lib in c program
> I run the cgo ok in an example program.
> But when integrate with old c program,  c program will send a signal 42 to
> itself periodly.
> this cause so lib terminate
>
> rogram received signal SIG42, Real-time event 42.
> [Switching to Thread 0xa53c6b70 (LWP 14957)]
> runtime.futex () at /usr/local/go/src/runtime/sys_linux_386.s:444
> 444 /usr/local/go/src/runtime/sys_linux_386.s: No such file or directory.
> in /usr/local/go/src/runtime/sys_linux_386.s
> Missing separate debuginfos, use: debuginfo-install WBXcms-3.7.0-494.i686
> (gdb) bt
> #0 runtime.futex () at /usr/local/go/src/runtime/sys_linux_386.s:444
> #1 0xb7b04c2a in runtime.futexsleep (addr=0xb7fa47ac, val=0, ns=-1) at
> /usr/local/go/src/runtime/os_linux.go:46
> #2 0xb7ae5437 in runtime.notesleep (n=0xb7fa47ac) at
> /usr/local/go/src/runtime/lock_futex.go:151
> #3 0xb7b0c8f4 in runtime.stopm () at /usr/local/go/src/runtime/proc.go:1936
> #4 0xb7b0d848 in runtime.findrunnable (gp=@0x74421300, inheritTime=@0x0)
> at /usr/local/go/src/runtime/proc.go:2399
> #5 0xb7b0e507 in runtime.schedule () at
> /usr/local/go/src/runtime/proc.go:2525
> #6 0xb7b0edac in runtime.goexit0 (gp=0x744000e0) at
> /usr/local/go/src/runtime/proc.go:2722
> #7 0xb7b2f868 in runtime.mcall () at
> /usr/local/go/src/runtime/asm_386.s:345
> #8 0xb7b2f7c0 in runtime.rt0_go () at
> /usr/local/go/src/runtime/asm_386.s:241
> #9 0xb7b2f7c7 in runtime.rt0_go () at
> /usr/local/go/src/runtime/asm_386.s:246
> #10 0x00
>
> My question is
> *how go so lib ignore this signal 42,  and pass the signal handle to old c
> program.*
>
> Thanks
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/golang-nuts/1YvP-5V6xSI/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/22745e49-1d43-4e3a-9d78-20ff6bb20d4e%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAF7uC_vecUj34DuYteEARMxanWNvGxMT_pWj%3DLjCz7OigFPtvw%40mail.gmail.com.


[go-nuts] how cgo handle user define signal ? need go pass the signal handle to c

2019-08-12 Thread hui zhang
I am trying to extend a old c program with go.Add websocket ability to 
this c program.
first  build  go as a  .so  dynamic lib
then link the so lib in c program
I run the cgo ok in an example program.
But when integrate with old c program,  c program will send a signal 42 to 
itself periodly. 
this cause so lib terminate 

rogram received signal SIG42, Real-time event 42.
[Switching to Thread 0xa53c6b70 (LWP 14957)]
runtime.futex () at /usr/local/go/src/runtime/sys_linux_386.s:444
444 /usr/local/go/src/runtime/sys_linux_386.s: No such file or directory.
in /usr/local/go/src/runtime/sys_linux_386.s
Missing separate debuginfos, use: debuginfo-install WBXcms-3.7.0-494.i686
(gdb) bt
#0 runtime.futex () at /usr/local/go/src/runtime/sys_linux_386.s:444
#1 0xb7b04c2a in runtime.futexsleep (addr=0xb7fa47ac, val=0, ns=-1) at 
/usr/local/go/src/runtime/os_linux.go:46
#2 0xb7ae5437 in runtime.notesleep (n=0xb7fa47ac) at 
/usr/local/go/src/runtime/lock_futex.go:151
#3 0xb7b0c8f4 in runtime.stopm () at /usr/local/go/src/runtime/proc.go:1936
#4 0xb7b0d848 in runtime.findrunnable (gp=@0x74421300, inheritTime=@0x0) at 
/usr/local/go/src/runtime/proc.go:2399
#5 0xb7b0e507 in runtime.schedule () at 
/usr/local/go/src/runtime/proc.go:2525
#6 0xb7b0edac in runtime.goexit0 (gp=0x744000e0) at 
/usr/local/go/src/runtime/proc.go:2722
#7 0xb7b2f868 in runtime.mcall () at /usr/local/go/src/runtime/asm_386.s:345
#8 0xb7b2f7c0 in runtime.rt0_go () at 
/usr/local/go/src/runtime/asm_386.s:241
#9 0xb7b2f7c7 in runtime.rt0_go () at 
/usr/local/go/src/runtime/asm_386.s:246
#10 0x00

My question is 
*how go so lib ignore this signal 42,  and pass the signal handle to old c 
program.*

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/22745e49-1d43-4e3a-9d78-20ff6bb20d4e%40googlegroups.com.