@@ -37,7 +37,7 @@ import (
3737
3838func buildCredential (uid , gid * uint32 ) (* syscall.Credential , error ) {
3939 if uid == nil && gid == nil {
40- return nil , nil
40+ return nil , nil //nolint:nilnil
4141 }
4242
4343 cred := & syscall.Credential {}
@@ -95,9 +95,20 @@ func (c *Controller) runCommand(ctx context.Context, request *ExecuteCodeRequest
9595 log .Info ("received command: %v" , request .Code )
9696 cmd := exec .CommandContext (ctx , "bash" , "-c" , request .Code )
9797
98+ // Configure credentials and process group
99+ cred , err := buildCredential (request .Uid , request .Gid )
100+ if err != nil {
101+ return fmt .Errorf ("failed to build credential: %w" , err )
102+ }
103+ cmd .SysProcAttr = & syscall.SysProcAttr {
104+ Setpgid : true ,
105+ Credential : cred ,
106+ }
107+
98108 cmd .Stdout = stdout
99109 cmd .Stderr = stderr
100110 cmd .Env = mergeEnvs (os .Environ (), loadExtraEnvFromFile ())
111+ cmd .Dir = request .Cwd
101112
102113 done := make (chan struct {}, 1 )
103114 var wg sync.WaitGroup
@@ -111,20 +122,7 @@ func (c *Controller) runCommand(ctx context.Context, request *ExecuteCodeRequest
111122 c .tailStdPipe (stderrPath , request .Hooks .OnExecuteStderr , done )
112123 })
113124
114- cmd .Dir = request .Cwd
115-
116- // Configure credentials and process group
117- cred , err := buildCredential (request .Uid , request .Gid )
118- if err != nil {
119- log .Error ("failed to build credentials: %v" , err )
120- }
121- cmd .SysProcAttr = & syscall.SysProcAttr {
122- Setpgid : true ,
123- Credential : cred ,
124- }
125-
126125 err = cmd .Start ()
127-
128126 if err != nil {
129127 request .Hooks .OnExecuteInit (session )
130128 request .Hooks .OnExecuteError (& execute.ErrorOutput {EName : "CommandExecError" , EValue : err .Error ()})
@@ -219,9 +217,7 @@ func (c *Controller) runBackgroundCommand(ctx context.Context, cancel context.Ca
219217 startAt := time .Now ()
220218 log .Info ("received command: %v" , request .Code )
221219 cmd := exec .CommandContext (ctx , "bash" , "-c" , request .Code )
222-
223220 cmd .Dir = request .Cwd
224-
225221 // Configure credentials and process group
226222 cred , err := buildCredential (request .Uid , request .Gid )
227223 if err != nil {
@@ -233,7 +229,6 @@ func (c *Controller) runBackgroundCommand(ctx context.Context, cancel context.Ca
233229 }
234230
235231 cmd .Stdout = pipe
236-
237232 cmd .Stderr = pipe
238233 cmd .Env = mergeEnvs (os .Environ (), loadExtraEnvFromFile ())
239234
0 commit comments