File tree 2 files changed +31
-5
lines changed
2 files changed +31
-5
lines changed Original file line number Diff line number Diff line change 41
41
untarDestDir = flag .String ("untar-dest-dir" , "" , "destination directory to untar --untar-file to" )
42
42
)
43
43
44
- // configureSerialLogOutput is set non-nil on some platforms to configure
45
- // log output to go to the serial console.
46
- var configureSerialLogOutput func ()
44
+ // configureSerialLogOutput and closeSerialLogOutput are set non-nil
45
+ // on some platforms to configure log output to go to the serial
46
+ // console and to close the serial port, respectively.
47
+ var (
48
+ configureSerialLogOutput func ()
49
+ closeSerialLogOutput func ()
50
+ )
47
51
48
52
func main () {
49
53
if configureSerialLogOutput != nil {
@@ -148,7 +152,16 @@ func main() {
148
152
case "solaris/amd64" :
149
153
cmd .Args = append (cmd .Args , legacyReverseBuildletArgs ("solaris-amd64-smartosbuildlet" )... )
150
154
}
155
+ // Release the serial port (if we opened it) so the buildlet
156
+ // process can open & write to it. At least on Windows, only
157
+ // one process can have it open.
158
+ if closeSerialLogOutput != nil {
159
+ closeSerialLogOutput ()
160
+ }
151
161
if err := cmd .Run (); err != nil {
162
+ if configureSerialLogOutput != nil {
163
+ configureSerialLogOutput ()
164
+ }
152
165
sleepFatalf ("Error running buildlet: %v" , err )
153
166
}
154
167
}
Original file line number Diff line number Diff line change @@ -6,17 +6,22 @@ package main
6
6
7
7
import (
8
8
"log"
9
+ "os"
9
10
10
11
"github.com/tarm/serial"
11
12
)
12
13
13
14
func init () {
14
15
configureSerialLogOutput = configureSerialLogOutputWindows
16
+ closeSerialLogOutput = closeSerialLogOutputWindows
15
17
}
16
18
19
+ var com1 * serial.Port
20
+
17
21
func configureSerialLogOutputWindows () {
18
22
c := & serial.Config {Name : "COM1" , Baud : 9600 }
19
- s , err := serial .OpenPort (c )
23
+ var err error
24
+ com1 , err = serial .OpenPort (c )
20
25
if err != nil {
21
26
// Oh well, we tried. This empirically works
22
27
// on Windows on GCE.
@@ -25,5 +30,13 @@ func configureSerialLogOutputWindows() {
25
30
log .Printf ("serial.OpenPort: %v" , err )
26
31
return
27
32
}
28
- log .SetOutput (s )
33
+ log .SetOutput (com1 )
34
+ }
35
+
36
+ func closeSerialLogOutputWindows () {
37
+ if com1 != nil {
38
+ com1 .Close ()
39
+ com1 = nil
40
+ log .SetOutput (os .Stderr )
41
+ }
29
42
}
You can’t perform that action at this time.
0 commit comments