File tree Expand file tree Collapse file tree 1 file changed +26
-1
lines changed
pkg/custompluginmonitor/plugin Expand file tree Collapse file tree 1 file changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -147,7 +147,12 @@ func (p *Plugin) run(rule cpmtypes.CustomRule) (exitStatus cpmtypes.Status, outp
147
147
}
148
148
defer cancel ()
149
149
150
- cmd := exec .CommandContext (ctx , rule .Path , rule .Args ... )
150
+ // create a process group
151
+ sysProcAttr := & syscall.SysProcAttr {
152
+ Setpgid : true ,
153
+ }
154
+ cmd := exec .Command (rule .Path , rule .Args ... )
155
+ cmd .SysProcAttr = sysProcAttr
151
156
152
157
stdoutPipe , err := cmd .StdoutPipe ()
153
158
if err != nil {
@@ -164,6 +169,26 @@ func (p *Plugin) run(rule cpmtypes.CustomRule) (exitStatus cpmtypes.Status, outp
164
169
return cpmtypes .Unknown , "Error in starting plugin. Please check the error log"
165
170
}
166
171
172
+ waitChan := make (chan struct {})
173
+ defer close (waitChan )
174
+
175
+ go func () {
176
+ select {
177
+ case <- ctx .Done ():
178
+ glog .Errorf ("Error in running plugin timeout %q" , rule .Path )
179
+ if cmd .Process == nil || cmd .Process .Pid == 0 {
180
+ glog .Errorf ("Error in cmd.Process check %q" , rule .Path )
181
+ break
182
+ }
183
+ err := syscall .Kill (- cmd .Process .Pid , syscall .SIGKILL )
184
+ if err != nil {
185
+ glog .Errorf ("Error in kill process %d, %v" , cmd .Process .Pid , err )
186
+ }
187
+ case <- waitChan :
188
+ return
189
+ }
190
+ }()
191
+
167
192
var (
168
193
wg sync.WaitGroup
169
194
stdout []byte
You can’t perform that action at this time.
0 commit comments