Skip to content

Commit

Permalink
Merge pull request #18 from openziti/allow.windows
Browse files Browse the repository at this point in the history
allows windows machines to use `agent controller init`
  • Loading branch information
andrewpmartinez authored Oct 18, 2023
2 parents 1bb5be4 + 370c252 commit 7417edc
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 3 deletions.
21 changes: 18 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
Copyright NetFoundry Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package agent

import (
Expand All @@ -14,7 +30,6 @@ import (
"regexp"
"strconv"
"strings"
"syscall"
"time"
)

Expand Down Expand Up @@ -52,7 +67,7 @@ func GetGopsProcesses() ([]*Process, error) {
}
// process is alive and is reachable by us
if process, err := os.FindProcess(pid); err == nil {
if err = process.Signal(syscall.Signal(0)); err == nil {
if isReachable(process) {
proc, err := ps.FindProcess(pid)
if err != nil {
return nil, err
Expand Down Expand Up @@ -84,7 +99,7 @@ func tooManyProcsError(procs []*Process) error {
list = append(list, v.String())
}
builder := &strings.Builder{}
builder.WriteString("too many gops-agent process found, including [")
builder.WriteString("too many gops-agent process found, specify one, found [")
builder.WriteString(strings.Join(list, ", "))
builder.WriteString("]")
return errors.New(builder.String())
Expand Down
30 changes: 30 additions & 0 deletions proc_nowin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//go:build !windows

/*
Copyright NetFoundry Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package agent

import (
"os"
"syscall"
)

func isReachable(proc *os.Process) bool {
err := proc.Signal(syscall.Signal(0))

return err == nil
}
25 changes: 25 additions & 0 deletions proc_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
Copyright NetFoundry Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package agent

import (
"os"
)

func isReachable(proc *os.Process) bool {
return true
}

0 comments on commit 7417edc

Please sign in to comment.