This repository was archived by the owner on Feb 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 93
Serial console #140
Merged
Merged
Serial console #140
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ import ( | |
| "os" | ||
| "os/exec" | ||
| "path/filepath" | ||
| "regexp" | ||
| "strings" | ||
| "time" | ||
| ) | ||
|
|
@@ -167,3 +168,72 @@ func CopyFile(src, dst string) (int64, error) { | |
| defer df.Close() | ||
| return io.Copy(df, sf) | ||
| } | ||
|
|
||
| func reader(r io.Reader) { | ||
| buf := make([]byte, 1024) | ||
| for { | ||
| _, err := io.ReadAtLeast(r, buf[:], 20) | ||
| if err != nil { | ||
| return | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // use the serial port socket to ask what the VM's host only IP is | ||
| func RequestIPFromSerialPort(socket string) string { | ||
| c, err := net.Dial("unix", socket) | ||
|
|
||
| if err != nil { | ||
| return "" | ||
| } | ||
| defer c.Close() | ||
| c.SetDeadline(time.Now().Add(time.Second)) | ||
|
|
||
| line := "" | ||
| _, err = c.Write([]byte("\r")) | ||
| _, err = c.Write([]byte("docker\r")) | ||
|
|
||
| IP := "" | ||
| fullLog := "" | ||
|
|
||
| for IP == "" { | ||
| _, err := c.Write([]byte("ip addr show dev eth1\r")) | ||
| if err != nil { | ||
| println(err) | ||
| break | ||
| } | ||
| time.Sleep(1 * time.Second) | ||
| buf := make([]byte, 1024) | ||
| for { | ||
| n, err := c.Read(buf[:]) | ||
| if err != nil { | ||
| return IP | ||
| } | ||
| line = line + string(buf[0:n]) | ||
| fullLog += string(buf[0:n]) | ||
| if strings.Contains(line, "\n") { | ||
| //go looking for the string we want, and chomp line to after the \n | ||
| if i := strings.IndexAny(line, "\n"); i != -1 { | ||
| // inet 10.180.1.3/16 brd 10.180.255.255 scope global wlan0 | ||
| inet := regexp.MustCompile(`^[\t ]*inet ([0-9.]*).*$`) | ||
| if ip := inet.FindStringSubmatch(line[:i]); ip != nil { | ||
| IP = ip[1] | ||
| // clean up | ||
| break | ||
| } else { | ||
| line = line[i+1:] | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } | ||
| go reader(c) | ||
| //give us time reader clean up | ||
| time.Sleep(1) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Relying on Sleep for another goroutine to complete may not be very portable. ch := make(chan bool)
go reader(c, ch)
<- chand the reader will close the channel when it is done. Or you could use a select for a timeout... or you could just leave it as is. :-)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mmm, ok, I need to learn more - I started down this path, and things fell apart fast. - Might look post 0.12.0 release |
||
| if IP == "" && B2D.Verbose { | ||
| logf(fullLog) | ||
| } | ||
|
|
||
| return IP | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like there must be an easier way to soak up and ignore all data in a io.Reader than this... but I don't know off-hand what it is. Maybe someone else does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes please - I'm doing something wrong that kills the socket after a little while.