From 2c57ac46ede15fddecd9f8085c87da617b568fb5 Mon Sep 17 00:00:00 2001 From: Anthony Green Date: Tue, 2 Jan 2024 19:24:55 -0500 Subject: [PATCH] Fix windows builds by separating out OS signal handling code per platform --- green-orb.go | 9 ++------- signals_unix.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ signals_windows.go | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 7 deletions(-) create mode 100644 signals_unix.go create mode 100644 signals_windows.go diff --git a/green-orb.go b/green-orb.go index d5c5d55..d17fd78 100644 --- a/green-orb.go +++ b/green-orb.go @@ -1,6 +1,6 @@ // green-orb.go - an Observe and Report Buddy // -// Copyright (C) 2023 Anthony Green - green@moxielogic.com +// Copyright (C) 2023, 2024 Anthony Green - green@moxielogic.com // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation @@ -315,12 +315,7 @@ func main() { // Goroutine for passing signals go func() { for sig := range sigChan { - if sig == syscall.SIGCHLD { - continue - } - if err := observed_cmd.Process.Signal(sig); err != nil { - log.Println("green-orb error: Failed to send signal to subprocess:", err) - } + process_signal(observed_cmd, sig) } }() diff --git a/signals_unix.go b/signals_unix.go new file mode 100644 index 0000000..304f8ac --- /dev/null +++ b/signals_unix.go @@ -0,0 +1,45 @@ +// +build linux darwin + +// signals_unix.go - pass signals through to observed command +// +// Copyright (C) 2023, 2024 Anthony Green - green@moxielogic.com +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the “Software”), to deal in the Software without +// restriction, including without limitation the rights to use, copy, +// modify, merge, publish, distribute, sublicense, and/or sell copies +// of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +// BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +package main + +import ( + "log" + "os" + "os/exec" + "syscall" +) + +func process_signal(observed_cmd *exec.Cmd, sig os.Signal) error { + if sig == syscall.SIGCHLD { + return nil + } + if err := observed_cmd.Process.Signal(sig); err != nil { + log.Println("green-orb error: Failed to send signal to subprocess:", err) + } + + return nil +} diff --git a/signals_windows.go b/signals_windows.go new file mode 100644 index 0000000..559a971 --- /dev/null +++ b/signals_windows.go @@ -0,0 +1,36 @@ +// +build windows + +// signals_windows.go - dummy placeholder +// +// Copyright (C) 2023, 2024 Anthony Green - green@moxielogic.com +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the “Software”), to deal in the Software without +// restriction, including without limitation the rights to use, copy, +// modify, merge, publish, distribute, sublicense, and/or sell copies +// of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +// BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +package main + +import ( + "os" + "os/exec" +) + +func process_signal(observed_cmd *exec.Cmd, sig os.Signal) error { + return nil +}