@@ -396,7 +396,13 @@ func (vm *Vm) HyperstartExecSync(cmd []string, stdin []byte) (stdout, stderr []b
396396 return nil , nil , err
397397 }
398398
399- err = vm .AddProcess (hyperstartapi .HYPERSTART_EXEC_CONTAINER , execId , false , cmd , []string {}, "/" , tty )
399+ err = vm .AddProcess (& api.Process {
400+ Container : hyperstartapi .HYPERSTART_EXEC_CONTAINER ,
401+ Id : execId ,
402+ Terminal : false ,
403+ Args : cmd ,
404+ Envs : []string {},
405+ Workdir : "/" }, tty )
400406 if err != nil {
401407 return nil , nil , err
402408 }
@@ -435,7 +441,13 @@ func (vm *Vm) HyperstartExec(cmd string, tty *TtyIO) (int, error) {
435441 return - 1 , err
436442 }
437443
438- err := vm .AddProcess (hyperstartapi .HYPERSTART_EXEC_CONTAINER , execID , false , command , []string {}, "/" , tty )
444+ err := vm .AddProcess (& api.Process {
445+ Container : hyperstartapi .HYPERSTART_EXEC_CONTAINER ,
446+ Id : execID ,
447+ Terminal : false ,
448+ Args : command ,
449+ Envs : []string {},
450+ Workdir : "/" }, tty )
439451 if err != nil {
440452 return - 1 , err
441453 }
@@ -461,17 +473,23 @@ func (vm *Vm) Exec(container, execId, cmd string, terminal bool, tty *TtyIO) err
461473 if err := json .Unmarshal ([]byte (cmd ), & command ); err != nil {
462474 return err
463475 }
464- return vm .AddProcess (container , execId , terminal , command , []string {}, "/" , tty )
476+ return vm .AddProcess (& api.Process {
477+ Container : container ,
478+ Id : execId ,
479+ Terminal : terminal ,
480+ Args : command ,
481+ Envs : []string {},
482+ Workdir : "/" }, tty )
465483}
466484
467- func (vm * Vm ) AddProcess (container , execId string , terminal bool , args [] string , env [] string , workdir string , tty * TtyIO ) error {
485+ func (vm * Vm ) AddProcess (process * api. Process , tty * TtyIO ) error {
468486 if ! vm .ctx .IsRunning () {
469487 return NewNotReadyError (vm .Id )
470488 }
471489
472490 envs := []hyperstartapi.EnvironmentVar {}
473491
474- for _ , v := range env {
492+ for _ , v := range process . Envs {
475493 if eqlIndex := strings .Index (v , "=" ); eqlIndex > 0 {
476494 envs = append (envs , hyperstartapi.EnvironmentVar {
477495 Env : v [:eqlIndex ],
@@ -480,24 +498,26 @@ func (vm *Vm) AddProcess(container, execId string, terminal bool, args []string,
480498 }
481499 }
482500
483- stdinPipe , stdoutPipe , stderrPipe , err := vm .ctx .hyperstart .AddProcess (container , & hyperstartapi.Process {
484- Id : execId ,
485- Terminal : terminal ,
486- Args : args ,
501+ stdinPipe , stdoutPipe , stderrPipe , err := vm .ctx .hyperstart .AddProcess (process . Container , & hyperstartapi.Process {
502+ Id : process . Id ,
503+ Terminal : process . Terminal ,
504+ Args : process . Args ,
487505 Envs : envs ,
488- Workdir : workdir ,
506+ Workdir : process .Workdir ,
507+ User : process .User ,
508+ Group : process .Group ,
489509 })
490510
491511 if err != nil {
492- return fmt .Errorf ("exec command %v failed: %v" , args , err )
512+ return fmt .Errorf ("exec command %v failed: %v" , process . Args , err )
493513 }
494514
495515 go streamCopy (tty , stdinPipe , stdoutPipe , stderrPipe )
496516 go func () {
497- status := vm .ctx .hyperstart .WaitProcess (container , execId )
498- vm .ctx .DeleteExec (execId )
517+ status := vm .ctx .hyperstart .WaitProcess (process . Container , process . Id )
518+ vm .ctx .DeleteExec (process . Id )
499519 vm .ctx .reportProcessFinished (types .E_EXEC_FINISHED , & types.ProcessFinished {
500- Id : execId , Code : uint8 (status ), Ack : make (chan bool , 1 ),
520+ Id : process . Id , Code : uint8 (status ), Ack : make (chan bool , 1 ),
501521 })
502522 }()
503523 return nil
0 commit comments