| 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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 log.Fields{ | 155 log.Fields{ |
| 156 "path": cwd, | 156 "path": cwd, |
| 157 }.Errorf(a, "Target `chdir` path is not a directory.") | 157 }.Errorf(a, "Target `chdir` path is not a directory.") |
| 158 return runtimeErrorReturnCode | 158 return runtimeErrorReturnCode |
| 159 } | 159 } |
| 160 } else { | 160 } else { |
| 161 // Just for output. | 161 // Just for output. |
| 162 cwd, _ = os.Getwd() | 162 cwd, _ = os.Getwd() |
| 163 } | 163 } |
| 164 | 164 |
| 165 // Get our output factory. |
| 166 of, err := a.getOutputFactory() |
| 167 if err != nil { |
| 168 log.WithError(err).Errorf(a, "Failed to get output factory insta
nce.") |
| 169 return runtimeErrorReturnCode |
| 170 } |
| 171 |
| 165 // Update our environment for the child process to inherit | 172 // Update our environment for the child process to inherit |
| 166 bsEnv := bootstrap.Environment{ | 173 bsEnv := bootstrap.Environment{ |
| 167 Project: a.project, | 174 Project: a.project, |
| 168 Prefix: a.prefix, | 175 Prefix: a.prefix, |
| 169 } | 176 } |
| 170 | 177 |
| 178 // If our output factory has a Coordinator host, fill that in too. |
| 179 if cho, ok := of.(coordinatorHostOutput); ok { |
| 180 bsEnv.CoordinatorHost = cho.getCoordinatorHost() |
| 181 } |
| 182 |
| 171 // Configure stream server | 183 // Configure stream server |
| 172 streamServer := streamserver.StreamServer(nil) | 184 streamServer := streamserver.StreamServer(nil) |
| 173 streamServerOwned := true | 185 streamServerOwned := true |
| 174 if cmd.streamServerURI != "" { | 186 if cmd.streamServerURI != "" { |
| 175 log.Fields{ | 187 log.Fields{ |
| 176 "url": cmd.streamServerURI, | 188 "url": cmd.streamServerURI, |
| 177 }.Infof(a, "Creating stream server.") | 189 }.Infof(a, "Creating stream server.") |
| 178 streamServer = createStreamServer(a, cmd.streamServerURI) | 190 streamServer = createStreamServer(a, cmd.streamServerURI) |
| 179 | 191 |
| 180 if err := streamServer.Listen(); err != nil { | 192 if err := streamServer.Listen(); err != nil { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 "args": args, | 274 "args": args, |
| 263 }.Debugf(a, "Executing application.") | 275 }.Debugf(a, "Executing application.") |
| 264 for _, entry := range proc.Env { | 276 for _, entry := range proc.Env { |
| 265 log.Debugf(a, "Environment variable: %s", entry) | 277 log.Debugf(a, "Environment variable: %s", entry) |
| 266 } | 278 } |
| 267 } | 279 } |
| 268 | 280 |
| 269 // We're about ready to execute our command. Initialize our Output insta
nce. | 281 // We're about ready to execute our command. Initialize our Output insta
nce. |
| 270 // We want to do this before we execute our subprocess so that if this f
ails, | 282 // We want to do this before we execute our subprocess so that if this f
ails, |
| 271 // we don't have to interrupt an already-running process. | 283 // we don't have to interrupt an already-running process. |
| 272 » output, err := a.configOutput() | 284 » output, err := of.configOutput(a) |
| 273 if err != nil { | 285 if err != nil { |
| 274 log.WithError(err).Errorf(a, "Failed to create output instance."
) | 286 log.WithError(err).Errorf(a, "Failed to create output instance."
) |
| 275 return runtimeErrorReturnCode | 287 return runtimeErrorReturnCode |
| 276 } | 288 } |
| 277 defer output.Close() | 289 defer output.Close() |
| 278 | 290 |
| 279 // Attach and run our Butler instance. | 291 // Attach and run our Butler instance. |
| 280 var ( | 292 var ( |
| 281 executed = false | 293 executed = false |
| 282 returnCode = runtimeErrorReturnCode | 294 returnCode = runtimeErrorReturnCode |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 // callbackReadCloser invokes a callback method when closed. | 404 // callbackReadCloser invokes a callback method when closed. |
| 393 type callbackReadCloser struct { | 405 type callbackReadCloser struct { |
| 394 io.ReadCloser | 406 io.ReadCloser |
| 395 callback func() | 407 callback func() |
| 396 } | 408 } |
| 397 | 409 |
| 398 func (c *callbackReadCloser) Close() error { | 410 func (c *callbackReadCloser) Close() error { |
| 399 defer c.callback() | 411 defer c.callback() |
| 400 return c.ReadCloser.Close() | 412 return c.ReadCloser.Close() |
| 401 } | 413 } |
| OLD | NEW |