 43fb19e01c
			
		
	
	43fb19e01c
	
	
	
		
			
			This adds both container and task loading of running tasks as well as reattaching to the IO of the task after load. Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
		
			
				
	
	
		
			72 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			72 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| // +build !windows
 | |
| 
 | |
| package containerd
 | |
| 
 | |
| import (
 | |
| 	"context"
 | |
| 	"io"
 | |
| 	"sync"
 | |
| 	"syscall"
 | |
| 
 | |
| 	"github.com/containerd/fifo"
 | |
| )
 | |
| 
 | |
| func copyIO(fifos *FifoSet, ioset *ioSet, tty bool) (closer io.Closer, err error) {
 | |
| 	var (
 | |
| 		f   io.ReadWriteCloser
 | |
| 		ctx = context.Background()
 | |
| 		wg  = &sync.WaitGroup{}
 | |
| 	)
 | |
| 
 | |
| 	if f, err = fifo.OpenFifo(ctx, fifos.In, syscall.O_WRONLY|syscall.O_CREAT|syscall.O_NONBLOCK, 0700); err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 	defer func(c io.Closer) {
 | |
| 		if err != nil {
 | |
| 			c.Close()
 | |
| 		}
 | |
| 	}(f)
 | |
| 	go func(w io.WriteCloser) {
 | |
| 		io.Copy(w, ioset.in)
 | |
| 		w.Close()
 | |
| 	}(f)
 | |
| 
 | |
| 	if f, err = fifo.OpenFifo(ctx, fifos.Out, syscall.O_RDONLY|syscall.O_CREAT|syscall.O_NONBLOCK, 0700); err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 	defer func(c io.Closer) {
 | |
| 		if err != nil {
 | |
| 			c.Close()
 | |
| 		}
 | |
| 	}(f)
 | |
| 	wg.Add(1)
 | |
| 	go func(r io.ReadCloser) {
 | |
| 		io.Copy(ioset.out, r)
 | |
| 		r.Close()
 | |
| 		wg.Done()
 | |
| 	}(f)
 | |
| 
 | |
| 	if f, err = fifo.OpenFifo(ctx, fifos.Err, syscall.O_RDONLY|syscall.O_CREAT|syscall.O_NONBLOCK, 0700); err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 	defer func(c io.Closer) {
 | |
| 		if err != nil {
 | |
| 			c.Close()
 | |
| 		}
 | |
| 	}(f)
 | |
| 
 | |
| 	if !tty {
 | |
| 		wg.Add(1)
 | |
| 		go func(r io.ReadCloser) {
 | |
| 			io.Copy(ioset.err, r)
 | |
| 			r.Close()
 | |
| 			wg.Done()
 | |
| 		}(f)
 | |
| 	}
 | |
| 
 | |
| 	return &wgCloser{
 | |
| 		wg:  wg,
 | |
| 		dir: fifos.Dir,
 | |
| 	}, nil
 | |
| }
 |