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