Skip to content

Commit

Permalink
fix: plugin verification panics due to missing SA_ONSTACK signal (pac…
Browse files Browse the repository at this point in the history
  • Loading branch information
YOU54F authored Jul 2, 2024
1 parent 061aaf9 commit c80e188
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 2 deletions.
3 changes: 2 additions & 1 deletion internal/native/message_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@ func (m *MessageServer) UsingPlugin(pluginName string, pluginVersion string) err
defer free(cPluginName)
cPluginVersion := C.CString(pluginVersion)
defer free(cPluginVersion)


InstallSignalHandlers()
r := C.pactffi_using_plugin(m.messagePact.handle, cPluginName, cPluginVersion)

// 1 - A general panic was caught.
Expand Down
1 change: 1 addition & 0 deletions internal/native/mock_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ func (m *MockServer) UsingPlugin(pluginName string, pluginVersion string) error
cPluginVersion := C.CString(pluginVersion)
defer free(cPluginVersion)

InstallSignalHandlers()
r := C.pactffi_using_plugin(m.pact.handle, cPluginName, cPluginVersion)

// 1 - A general panic was caught.
Expand Down
87 changes: 87 additions & 0 deletions internal/native/signal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
//go:build cgo
// +build cgo

package native

/*
#if defined(__APPLE__) || defined(__linux__)
// https://github.com/wailsapp/wails/pull/2152/files#diff-d4a0fa73df7b0ab971e550f95249e358b634836e925ace96f7400480916ac09e
#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
static void fix_signal(int signum)
{
struct sigaction st;
if (sigaction(signum, NULL, &st) < 0) {
goto fix_signal_error;
}
st.sa_flags |= SA_ONSTACK;
if (sigaction(signum, &st, NULL) < 0) {
goto fix_signal_error;
}
return;
fix_signal_error:
fprintf(stderr, "error fixing handler for signal %d, please "
"report this issue to "
"https://github.com/pact-foundation/pact-go: %s\n",
signum, strerror(errno));
}
static void install_signal_handlers()
{
#if defined(SIGCHLD)
fix_signal(SIGCHLD);
#endif
#if defined(SIGHUP)
fix_signal(SIGHUP);
#endif
#if defined(SIGINT)
fix_signal(SIGINT);
#endif
#if defined(SIGQUIT)
fix_signal(SIGQUIT);
#endif
#if defined(SIGABRT)
fix_signal(SIGABRT);
#endif
#if defined(SIGFPE)
fix_signal(SIGFPE);
#endif
#if defined(SIGTERM)
fix_signal(SIGTERM);
#endif
#if defined(SIGBUS)
fix_signal(SIGBUS);
#endif
#if defined(SIGSEGV)
fix_signal(SIGSEGV);
#endif
#if defined(SIGXCPU)
fix_signal(SIGXCPU);
#endif
#if defined(SIGXFSZ)
fix_signal(SIGXFSZ);
#endif
}
#else
static void install_signal_handlers()
{
}
#endif
*/
import "C"
import (
"os"
"runtime"
)

func InstallSignalHandlers() {
if os.Getenv("PACT_GO_INSTALL_SIGNAL_HANDLERS") != "0" {
if runtime.GOOS != "windows" {
C.install_signal_handlers()
}
}
}
2 changes: 1 addition & 1 deletion internal/native/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func (v *Verifier) SetPublishOptions(providerVersion string, buildUrl string, pr

func (v *Verifier) Execute() error {
// TODO: Validate

InstallSignalHandlers()
result := C.pactffi_verifier_execute(v.handle)

/// | Error | Description |
Expand Down

0 comments on commit c80e188

Please sign in to comment.