mirror of
https://github.com/bluenviron/mediamtx
synced 2025-02-04 21:53:28 +00:00
fix closing some custom commands on Windows (#3981)
* Bugfix: Rewrote addProcessToGroup. Fixed possible invalid process handle by using windows.OpenProcess instead. Fixes issue: 3980 * run gofumpt --------- Co-authored-by: aler9 <46489434+aler9@users.noreply.github.com>
This commit is contained in:
parent
8f04264fe5
commit
8c1ed7254f
@ -44,13 +44,21 @@ func closeProcessGroup(h windows.Handle) error {
|
||||
}
|
||||
|
||||
func addProcessToGroup(h windows.Handle, p *os.Process) error {
|
||||
type process struct {
|
||||
Pid int
|
||||
Handle uintptr
|
||||
// Combine the required access rights
|
||||
access := uint32(windows.PROCESS_SET_QUOTA | windows.PROCESS_TERMINATE)
|
||||
|
||||
processHandle, err := windows.OpenProcess(access, false, uint32(p.Pid))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open process: %v", err)
|
||||
}
|
||||
defer windows.CloseHandle(processHandle)
|
||||
|
||||
err = windows.AssignProcessToJobObject(h, processHandle)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to assign process to job object: %v", err)
|
||||
}
|
||||
|
||||
return windows.AssignProcessToJobObject(h,
|
||||
windows.Handle((*process)(unsafe.Pointer(p)).Handle))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *Cmd) runOSSpecific(env []string) error {
|
||||
|
Loading…
Reference in New Issue
Block a user