| OLD | NEW |
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package main | 5 package main |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "encoding/json" | 8 "encoding/json" |
| 9 "io" | 9 "io" |
| 10 "os" | 10 "os" |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 } | 171 } |
| 172 | 172 |
| 173 // Update our environment for the child process to inherit | 173 // Update our environment for the child process to inherit |
| 174 bsEnv := bootstrap.Environment{ | 174 bsEnv := bootstrap.Environment{ |
| 175 Project: a.project, | 175 Project: a.project, |
| 176 Prefix: a.prefix, | 176 Prefix: a.prefix, |
| 177 CoordinatorHost: a.coordinatorHost, | 177 CoordinatorHost: a.coordinatorHost, |
| 178 } | 178 } |
| 179 | 179 |
| 180 // Configure stream server | 180 // Configure stream server |
| 181 » streamServer := streamserver.StreamServer(nil) | 181 » var streamServer streamserver.StreamServer |
| 182 streamServerOwned := true | 182 streamServerOwned := true |
| 183 if cmd.streamServerURI != "" { | 183 if cmd.streamServerURI != "" { |
| 184 log.Fields{ | 184 log.Fields{ |
| 185 "url": cmd.streamServerURI, | 185 "url": cmd.streamServerURI, |
| 186 }.Infof(a, "Creating stream server.") | 186 }.Infof(a, "Creating stream server.") |
| 187 » » streamServer = createStreamServer(a, cmd.streamServerURI) | 187 » » var err error |
| 188 » » if streamServer, err = createStreamServer(a, cmd.streamServerURI
); err != nil { |
| 189 » » » log.WithError(err).Errorf(a, "Failed to create stream se
rver.") |
| 190 » » » return runtimeErrorReturnCode |
| 191 » » } |
| 188 | 192 |
| 189 if err := streamServer.Listen(); err != nil { | 193 if err := streamServer.Listen(); err != nil { |
| 190 » » » log.Errorf(log.SetError(a, err), "Failed to connect to s
tream server.") | 194 » » » log.WithError(err).Errorf(a, "Failed to connect to strea
m server.") |
| 191 return runtimeErrorReturnCode | 195 return runtimeErrorReturnCode |
| 192 } | 196 } |
| 193 defer func() { | 197 defer func() { |
| 194 if streamServerOwned { | 198 if streamServerOwned { |
| 195 streamServer.Close() | 199 streamServer.Close() |
| 196 } | 200 } |
| 197 }() | 201 }() |
| 198 | 202 |
| 199 » » bsEnv.StreamServerURI = string(cmd.streamServerURI) | 203 » » bsEnv.StreamServerURI = streamServer.Address() |
| 200 } | 204 } |
| 201 | 205 |
| 202 // Build our command enviornment. | 206 // Build our command enviornment. |
| 203 env := environ.System() | 207 env := environ.System() |
| 204 bsEnv.Augment(env) | 208 bsEnv.Augment(env) |
| 205 | 209 |
| 206 // Construct and execute the command. | 210 // Construct and execute the command. |
| 207 procCtx, procCancelFunc := context.WithCancel(a) | 211 procCtx, procCancelFunc := context.WithCancel(a) |
| 208 defer procCancelFunc() | 212 defer procCancelFunc() |
| 209 | 213 |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 // callbackReadCloser invokes a callback method when closed. | 407 // callbackReadCloser invokes a callback method when closed. |
| 404 type callbackReadCloser struct { | 408 type callbackReadCloser struct { |
| 405 io.ReadCloser | 409 io.ReadCloser |
| 406 callback func() | 410 callback func() |
| 407 } | 411 } |
| 408 | 412 |
| 409 func (c *callbackReadCloser) Close() error { | 413 func (c *callbackReadCloser) Close() error { |
| 410 defer c.callback() | 414 defer c.callback() |
| 411 return c.ReadCloser.Close() | 415 return c.ReadCloser.Close() |
| 412 } | 416 } |
| OLD | NEW |