-
Notifications
You must be signed in to change notification settings - Fork 903
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds support for enabling and listening to signals on Linux and MacOS. TODO: also support disabling signals.
- Loading branch information
Showing
10 changed files
with
108 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule macos-minimal-sdk
updated
from ebb736 to 5a77db
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//go:build none | ||
|
||
// Ignore the //go:build above. This file is manually included on Linux and | ||
// MacOS to provide os/signal support. | ||
|
||
#include <stdint.h> | ||
#include <signal.h> | ||
#include <unistd.h> | ||
|
||
// Signal handler in the runtime. | ||
void tinygo_signal_handler(int sig); | ||
|
||
// Enable a signal from the runtime. | ||
void tinygo_signal_enable(uint32_t sig) { | ||
struct sigaction act = { 0 }; | ||
act.sa_flags = SA_SIGINFO; | ||
act.sa_handler = &tinygo_signal_handler; | ||
sigaction(sig, &act, NULL); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
got expected signal | ||
exiting signal program |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package main | ||
|
||
// Test POSIX signals. | ||
// TODO: run `tinygo test os/signal` instead, once CGo errno return values are | ||
// supported. | ||
|
||
import ( | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
"time" | ||
) | ||
|
||
func main() { | ||
c := make(chan os.Signal, 1) | ||
signal.Notify(c, syscall.SIGUSR1) | ||
|
||
// Wait for signals to arrive. | ||
go func() { | ||
for sig := range c { | ||
if sig == syscall.SIGUSR1 { | ||
println("got expected signal") | ||
} else { | ||
println("got signal:", sig.String()) | ||
} | ||
} | ||
}() | ||
|
||
// Send the signal. | ||
syscall.Kill(syscall.Getpid(), syscall.SIGUSR1) | ||
|
||
time.Sleep(time.Millisecond * 100) | ||
println("exiting signal program") | ||
} |