@@ -413,7 +413,7 @@ func runContainerDockerRun(container *docker.Container, d *stiDocker, image stri
413
413
}
414
414
415
415
// this funtion simply abstracts out the first phase of attaching to the container that was originally in line with the RunContainer() method
416
- func runContainerAttachOne (attached chan struct {}, container * docker.Container , opts RunContainerOptions , d * stiDocker ) sync.WaitGroup {
416
+ func runContainerAttach (attached chan struct {}, container * docker.Container , opts RunContainerOptions , d * stiDocker ) * sync.WaitGroup {
417
417
attachOpts := docker.AttachToContainerOptions {
418
418
Container : container .ID ,
419
419
Success : attached ,
@@ -422,11 +422,11 @@ func runContainerAttachOne(attached chan struct{}, container *docker.Container,
422
422
if opts .Stdin != nil {
423
423
attachOpts .InputStream = opts .Stdin
424
424
attachOpts .Stdin = true
425
- } else if opts .Stdout != nil {
425
+ }
426
+ if opts .Stdout != nil {
426
427
attachOpts .OutputStream = opts .Stdout
427
428
attachOpts .Stdout = true
428
429
}
429
-
430
430
if opts .Stderr != nil {
431
431
attachOpts .ErrorStream = opts .Stderr
432
432
attachOpts .Stderr = true
@@ -440,33 +440,11 @@ func runContainerAttachOne(attached chan struct{}, container *docker.Container,
440
440
glog .Errorf ("Unable to attach container with %v" , attachOpts )
441
441
}
442
442
}()
443
- return wg
444
- }
445
-
446
- // this funtion simply abstracts out the second phase of attaching to the container that was originally in line with the RunContainer() method
447
- func runContainerAttachTwo (attached2 chan struct {}, container * docker.Container , opts RunContainerOptions , d * stiDocker , wg sync.WaitGroup ) {
448
- attachOpts2 := docker.AttachToContainerOptions {
449
- Container : container .ID ,
450
- Success : attached2 ,
451
- Stream : true ,
452
- OutputStream : opts .Stdout ,
453
- Stdout : true ,
454
- }
455
- if opts .Stderr != nil {
456
- attachOpts2 .Stderr = true
457
- attachOpts2 .ErrorStream = opts .Stderr
458
- }
459
- go func () {
460
- wg .Add (1 )
461
- defer wg .Done ()
462
- if err := d .client .AttachToContainer (attachOpts2 ); err != nil {
463
- glog .Errorf ("Unable to attach container with %v" , attachOpts2 )
464
- }
465
- }()
443
+ return & wg
466
444
}
467
445
468
446
// this funtion simply abstracts out the waiting on the container hosting the builder function that was originally in line with the RunContainer() method
469
- func runContainerWait (wg sync.WaitGroup , d * stiDocker , container * docker.Container ) error {
447
+ func runContainerWait (wg * sync.WaitGroup , d * stiDocker , container * docker.Container ) error {
470
448
glog .V (2 ).Infof ("Waiting for container" )
471
449
exitCode , err := d .client .WaitContainer (container .ID )
472
450
glog .V (2 ).Infof ("Container wait returns with %d and %v\n " , exitCode , err )
@@ -528,22 +506,11 @@ func (d *stiDocker) RunContainer(opts RunContainerOptions) (err error) {
528
506
defer d .RemoveContainer (container .ID )
529
507
530
508
glog .V (2 ).Infof ("Attaching to container" )
531
- // creating / piping the channels in runContainerAttachOne lead to unintended hangs
509
+ // creating / piping the channels in runContainerAttach lead to unintended hangs
532
510
attached := make (chan struct {})
533
- wg := runContainerAttachOne (attached , container , opts , d )
511
+ wg := runContainerAttach (attached , container , opts , d )
534
512
attached <- <- attached
535
513
536
- // If attaching both stdin and stdout or stderr, attach stdout and stderr in
537
- // a second goroutine
538
- // TODO remove this goroutine when docker 1.4 will be in broad usage,
539
- // see: https://github.com/docker/docker/commit/f936a10d8048f471d115978472006e1b58a7c67d
540
- if opts .Stdin != nil && opts .Stdout != nil {
541
- // creating / piping the channels in runContainerAttachTwo lead to unintended hangs
542
- attached2 := make (chan struct {})
543
- runContainerAttachTwo (attached2 , container , opts , d , wg )
544
- attached2 <- <- attached2
545
- }
546
-
547
514
glog .V (2 ).Infof ("Starting container" )
548
515
if err = d .client .StartContainer (container .ID , nil ); err != nil {
549
516
return err
0 commit comments