mirror of
				https://gitea.com/Lydanne/buildx.git
				synced 2025-11-01 00:23:56 +08:00 
			
		
		
		
	monitor: Enable to exec into the container
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
This commit is contained in:
		| @@ -159,15 +159,27 @@ func (f *SingleForwarder) doForward() { | ||||
| 	var r io.ReadCloser | ||||
| 	for { | ||||
| 		readerInvalid := false | ||||
| 		var readerInvalidMu sync.Mutex | ||||
| 		copyReaderToWriter := false | ||||
| 		if r != nil { | ||||
| 			copyReaderToWriter = true | ||||
| 		} | ||||
| 		if copyReaderToWriter { | ||||
| 			srcR := r | ||||
| 			go func() { | ||||
| 				buf := make([]byte, 4096) | ||||
| 				readerClosed := false | ||||
| 				for { | ||||
| 					n, readErr := r.Read(buf) | ||||
| 					if readErr != nil && !errors.Is(readErr, io.EOF) && !errors.Is(readErr, io.ErrClosedPipe) { | ||||
| 						logrus.Debugf("single forwarder: reader error: %v", readErr) | ||||
| 						return | ||||
| 					n, readErr := srcR.Read(buf) | ||||
| 					if readErr != nil { | ||||
| 						srcR.Close() | ||||
| 						readerClosed = true | ||||
| 						if !errors.Is(readErr, io.EOF) && !errors.Is(readErr, io.ErrClosedPipe) { | ||||
| 							logrus.Debugf("single forwarder: reader error: %v", readErr) | ||||
| 							return | ||||
| 						} | ||||
| 					} | ||||
|  | ||||
| 					f.curWMu.Lock() | ||||
| 					w := f.curW | ||||
| 					f.curWMu.Unlock() | ||||
| @@ -176,10 +188,14 @@ func (f *SingleForwarder) doForward() { | ||||
| 							logrus.Debugf("single forwarder: writer error: %v", err) | ||||
| 						} | ||||
| 					} | ||||
| 					if readerInvalid { | ||||
| 					readerInvalidMu.Lock() | ||||
| 					ri := readerInvalid | ||||
| 					readerInvalidMu.Unlock() | ||||
| 					if ri || readerClosed { | ||||
| 						return | ||||
| 					} | ||||
| 					if readErr != io.EOF { | ||||
| 						logrus.Debugf("unknown error: %v\n", readErr) | ||||
| 						continue | ||||
| 					} | ||||
|  | ||||
| @@ -202,7 +218,9 @@ func (f *SingleForwarder) doForward() { | ||||
| 			} | ||||
| 			f.curR = newR | ||||
| 			r = newR | ||||
| 			readerInvalidMu.Lock() | ||||
| 			readerInvalid = true | ||||
| 			readerInvalidMu.Unlock() | ||||
| 			f.curRMu.Unlock() | ||||
| 		case <-f.doneCh: | ||||
| 			return | ||||
|   | ||||
| @@ -133,6 +133,27 @@ func (m *MuxIO) Enable(i int) { | ||||
| 	m.enabled[i] = struct{}{} | ||||
| } | ||||
|  | ||||
| func (m *MuxIO) SwitchTo(i int) error { | ||||
| 	m.mu.Lock() | ||||
| 	defer m.mu.Unlock() | ||||
| 	if m.cur == i { | ||||
| 		return nil | ||||
| 	} | ||||
| 	if _, ok := m.enabled[i]; !ok { | ||||
| 		return errors.Errorf("IO index %d isn't active", i) | ||||
| 	} | ||||
| 	if m.outs[m.cur].DisableHook != nil { | ||||
| 		m.outs[m.cur].DisableHook() | ||||
| 	} | ||||
| 	prev := m.cur | ||||
| 	m.cur = i | ||||
| 	if m.outs[m.cur].EnableHook != nil { | ||||
| 		m.outs[m.cur].EnableHook() | ||||
| 	} | ||||
| 	fmt.Fprint(m.in.Stdout, m.toggleMessage(prev, i)) | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func (m *MuxIO) Disable(i int) error { | ||||
| 	m.mu.Lock() | ||||
| 	defer m.mu.Unlock() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Kohei Tokunaga
					Kohei Tokunaga