@@ -396,7 +396,13 @@ func (vm *Vm) HyperstartExecSync(cmd []string, stdin []byte) (stdout, stderr []b
396
396
return nil , nil , err
397
397
}
398
398
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 )
400
406
if err != nil {
401
407
return nil , nil , err
402
408
}
@@ -435,7 +441,13 @@ func (vm *Vm) HyperstartExec(cmd string, tty *TtyIO) (int, error) {
435
441
return - 1 , err
436
442
}
437
443
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 )
439
451
if err != nil {
440
452
return - 1 , err
441
453
}
@@ -461,17 +473,23 @@ func (vm *Vm) Exec(container, execId, cmd string, terminal bool, tty *TtyIO) err
461
473
if err := json .Unmarshal ([]byte (cmd ), & command ); err != nil {
462
474
return err
463
475
}
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 )
465
483
}
466
484
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 {
468
486
if ! vm .ctx .IsRunning () {
469
487
return NewNotReadyError (vm .Id )
470
488
}
471
489
472
490
envs := []hyperstartapi.EnvironmentVar {}
473
491
474
- for _ , v := range env {
492
+ for _ , v := range process . Envs {
475
493
if eqlIndex := strings .Index (v , "=" ); eqlIndex > 0 {
476
494
envs = append (envs , hyperstartapi.EnvironmentVar {
477
495
Env : v [:eqlIndex ],
@@ -480,24 +498,26 @@ func (vm *Vm) AddProcess(container, execId string, terminal bool, args []string,
480
498
}
481
499
}
482
500
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 ,
487
505
Envs : envs ,
488
- Workdir : workdir ,
506
+ Workdir : process .Workdir ,
507
+ User : process .User ,
508
+ Group : process .Group ,
489
509
})
490
510
491
511
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 )
493
513
}
494
514
495
515
go streamCopy (tty , stdinPipe , stdoutPipe , stderrPipe )
496
516
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 )
499
519
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 ),
501
521
})
502
522
}()
503
523
return nil
0 commit comments