func receiveTTY(usock *unixsocket.Usock, err error) (*os.File, error) { if err != nil { return nil, err } clientFd, err := usock.ReadFD() if err != nil { return nil, errors.New("Expected FD, none received!") } fileName := strconv.Itoa(rand.Int()) clientFile := unixsocket.FdToFile(clientFd, fileName) return clientFile, nil }
// This should only be called while holding a lock on s.L. // This unfortunately holds the mutex for a little while, and if the // command dies super early, the entire slave pretty well deadlocks. // TODO: review this. func (s *SlaveNode) bootCommand(request *CommandRequest) { identifier := request.Name // TODO: If crashed, do something different... msg := messages.CreateSpawnCommandMessage(identifier) _, err := s.socket.WriteMessage(msg) if err != nil { slog.Error(err) return } commandFD, err := s.socket.ReadFD() if err != nil { fmt.Println(s.socket) slog.Error(err) return } fileName := strconv.Itoa(rand.Int()) commandFile := unixsocket.FdToFile(commandFD, fileName) request.Retchan <- commandFile }
func (mon *SlaveMonitor) slaveDidBeginRegistration(fd int) { // Having just started the process, we expect an IO, which we convert to a UNIX domain socket fileName := strconv.Itoa(rand.Int()) slaveFile := unixsocket.FdToFile(fd, fileName) slaveUsock, err := unixsocket.NewUsockFromFile(slaveFile) if err != nil { slog.Error(err) } if err = slaveUsock.Conn.SetReadBuffer(1024); err != nil { slog.Error(err) } if err = slaveUsock.Conn.SetWriteBuffer(1024); err != nil { slog.Error(err) } // We now expect the slave to use this fd they send us to send a Pid&Identifier Message msg, err := slaveUsock.ReadMessage() if err != nil { slog.Error(err) } pid, identifier, err := messages.ParsePidMessage(msg) // And the last step before executing its action, the slave sends us a pipe it will later use to // send us all the features it's loaded. featurePipeFd, err := slaveUsock.ReadFD() if err != nil { slog.Error(err) } slaveNode := mon.tree.FindSlaveByName(identifier) if slaveNode == nil { Error("slavemonitor.go:slaveDidBeginRegistration:Unknown identifier:" + identifier) } slaveNode.SlaveWasInitialized(pid, slaveUsock, featurePipeFd) }