@@ -47,6 +47,7 @@ const (
47
47
// with the boards.
48
48
type PluggableDiscovery struct {
49
49
id string
50
+ processArgs []string
50
51
process * executils.Process
51
52
outgoingCommandsPipe io.Writer
52
53
incomingMessagesChan <- chan * discoveryMessage
@@ -126,28 +127,12 @@ type Event struct {
126
127
127
128
// New create and connect to the given pluggable discovery
128
129
func New (id string , args ... string ) (* PluggableDiscovery , error ) {
129
- proc , err := executils .NewProcess (args ... )
130
- if err != nil {
131
- return nil , err
132
- }
133
- stdout , err := proc .StdoutPipe ()
134
- if err != nil {
135
- return nil , err
136
- }
137
- stdin , err := proc .StdinPipe ()
138
- if err != nil {
139
- return nil , err
140
- }
141
- messageChan := make (chan * discoveryMessage )
142
130
disc := & PluggableDiscovery {
143
- id : id ,
144
- process : proc ,
145
- incomingMessagesChan : messageChan ,
146
- outgoingCommandsPipe : stdin ,
147
- state : Dead ,
148
- cachedPorts : map [string ]* Port {},
131
+ id : id ,
132
+ processArgs : args ,
133
+ state : Dead ,
134
+ cachedPorts : map [string ]* Port {},
149
135
}
150
- go disc .jsonDecodeLoop (stdout , messageChan )
151
136
return disc , nil
152
137
}
153
138
@@ -249,6 +234,25 @@ func (disc *PluggableDiscovery) sendCommand(command string) error {
249
234
250
235
func (disc * PluggableDiscovery ) runProcess () error {
251
236
logrus .Infof ("starting discovery %s process" , disc .id )
237
+ proc , err := executils .NewProcess (disc .processArgs ... )
238
+ if err != nil {
239
+ return err
240
+ }
241
+ stdout , err := proc .StdoutPipe ()
242
+ if err != nil {
243
+ return err
244
+ }
245
+ stdin , err := proc .StdinPipe ()
246
+ if err != nil {
247
+ return err
248
+ }
249
+ disc .outgoingCommandsPipe = stdin
250
+ disc .process = proc
251
+
252
+ messageChan := make (chan * discoveryMessage )
253
+ disc .incomingMessagesChan = messageChan
254
+ go disc .jsonDecodeLoop (stdout , messageChan )
255
+
252
256
if err := disc .process .Start (); err != nil {
253
257
return err
254
258
}
0 commit comments