@@ -21,6 +21,7 @@ import (
21
21
"bytes"
22
22
"encoding/json"
23
23
"fmt"
24
+ "io"
24
25
"math/rand"
25
26
"net"
26
27
"os"
@@ -169,21 +170,23 @@ func checkPid(pid int) error {
169
170
}
170
171
171
172
func (d * Driver ) GetState () (state.State , error ) {
172
- if _ , err := os .Stat (d .pidfilePath ()); err != nil {
173
- return state .Stopped , nil
174
- }
175
- p , err := os .ReadFile (d .pidfilePath ())
176
- if err != nil {
177
- return state .Error , err
178
- }
179
- pid , err := strconv .Atoi (strings .TrimSpace (string (p )))
180
- if err != nil {
181
- return state .Error , err
182
- }
183
- if err := checkPid (pid ); err != nil {
184
- // No pid, remove pidfile
185
- os .Remove (d .pidfilePath ())
186
- return state .Stopped , nil
173
+ if runtime .GOOS != "windows" {
174
+ if _ , err := os .Stat (d .pidfilePath ()); err != nil {
175
+ return state .Stopped , nil
176
+ }
177
+ p , err := os .ReadFile (d .pidfilePath ())
178
+ if err != nil {
179
+ return state .Error , err
180
+ }
181
+ pid , err := strconv .Atoi (strings .TrimSpace (string (p )))
182
+ if err != nil {
183
+ return state .Error , err
184
+ }
185
+ if err := checkPid (pid ); err != nil {
186
+ // No pid, remove pidfile
187
+ os .Remove (d .pidfilePath ())
188
+ return state .Stopped , nil
189
+ }
187
190
}
188
191
ret , err := d .RunQMPCommand ("query-status" )
189
192
if err != nil {
@@ -392,6 +395,10 @@ func (d *Driver) Start() error {
392
395
// On Linux, enable the Kernel Virtual Machine accelerator.
393
396
startCmd = append (startCmd ,
394
397
"-accel" , "kvm" )
398
+ //} else if runtime.GOOS == "windows" {
399
+ // // On Windows, enable the WHPX (Hyper-V) accelerator.
400
+ // startCmd = append(startCmd,
401
+ // "-accel", "whpx")
395
402
}
396
403
397
404
startCmd = append (startCmd ,
@@ -424,8 +431,10 @@ func (d *Driver) Start() error {
424
431
return fmt .Errorf ("unknown network: %s" , d .Network )
425
432
}
426
433
427
- startCmd = append (startCmd ,
428
- "-daemonize" )
434
+ if runtime .GOOS != "windows" {
435
+ startCmd = append (startCmd ,
436
+ "-daemonize" )
437
+ }
429
438
430
439
if d .CloudConfigRoot != "" {
431
440
startCmd = append (startCmd ,
@@ -452,7 +461,11 @@ func (d *Driver) Start() error {
452
461
startCmd = append ([]string {d .SocketVMNetPath , d .Program }, startCmd ... )
453
462
}
454
463
455
- if stdout , stderr , err := cmdOutErr (startProgram , startCmd ... ); err != nil {
464
+ startFunc := cmdOutErr
465
+ if runtime .GOOS == "windows" {
466
+ startFunc = cmdStart
467
+ }
468
+ if stdout , stderr , err := startFunc (startProgram , startCmd ... ); err != nil {
456
469
fmt .Printf ("OUTPUT: %s\n " , stdout )
457
470
fmt .Printf ("ERROR: %s\n " , stderr )
458
471
return err
@@ -519,6 +532,12 @@ func cmdOutErr(cmdStr string, args ...string) (string, string, error) {
519
532
return stdoutStr , stderrStr , err
520
533
}
521
534
535
+ func cmdStart (cmdStr string , args ... string ) (string , string , error ) {
536
+ cmd := exec .Command (cmdStr , args ... )
537
+ log .Debugf ("executing: %s %s" , cmdStr , strings .Join (args , " " ))
538
+ return "" , "" , cmd .Start ()
539
+ }
540
+
522
541
func (d * Driver ) Stop () error {
523
542
if _ , err := d .RunQMPCommand ("system_powerdown" ); err != nil {
524
543
return err
@@ -791,7 +810,7 @@ func WaitForTCPWithDelay(addr string, duration time.Duration) error {
791
810
continue
792
811
}
793
812
defer conn .Close ()
794
- if _ , err := conn .Read (make ([]byte , 1 )); err != nil {
813
+ if _ , err := conn .Read (make ([]byte , 1 )); err != nil && err != io . EOF {
795
814
time .Sleep (duration )
796
815
continue
797
816
}
0 commit comments