66 "golang.org/x/sync/errgroup"
77 "linuxvm/pkg/filesystem"
88 "linuxvm/pkg/network"
9+ "os"
10+ "os/exec"
911)
1012
1113const (
@@ -15,21 +17,41 @@ const (
1517)
1618
1719func main () {
18- g , _ := errgroup .WithContext (context .Background ())
20+ g , ctx := errgroup .WithContext (context .Background ())
1921 g .Go (func () error {
20- err := network .DHClient4 (eth0 , attempts , verbose )
21- if err != nil {
22- logrus .Errorf ("failed to get dhcp config: %v" , err )
23- return err
24- }
25- return nil
22+ return configureNetwork ()
2623 })
2724
2825 g .Go (func () error {
2926 return filesystem .MountTmpfs ()
3027 })
3128
29+ g .Go (func () error {
30+ return doExecCmdLine (ctx , os .Args [1 ], os .Args [2 :])
31+ })
32+
3233 if err := g .Wait (); err != nil {
3334 logrus .Errorf ("failed to run cmd: %v" , err )
3435 }
3536}
37+
38+ func doExecCmdLine (ctx context.Context , targetBin string , targetBinArgs []string ) error {
39+ cmd := exec .CommandContext (ctx , targetBin , targetBinArgs ... )
40+ cmd .Stdout = os .Stdout
41+ cmd .Stderr = os .Stderr
42+ cmd .Stdin = os .Stdin
43+ logrus .Infof ("cmdline: %q" , cmd .Args )
44+ if err := cmd .Run (); err != nil {
45+ logrus .Errorf ("failed to run cmd: %v" , err )
46+ return err
47+ }
48+ return nil
49+ }
50+
51+ func configureNetwork () error {
52+ if err := network .DHClient4 (eth0 , attempts , verbose ); err != nil {
53+ logrus .Errorf ("failed to get dhcp config: %v" , err )
54+ return err
55+ }
56+ return nil
57+ }
0 commit comments