-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add killsignal and killtimeout to exec/rtsp
- Loading branch information
Showing
3 changed files
with
69 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package exec | ||
|
||
import ( | ||
"errors" | ||
"net/url" | ||
"os" | ||
"os/exec" | ||
"syscall" | ||
"time" | ||
|
||
"github.com/AlexxIT/go2rtc/pkg/core" | ||
) | ||
|
||
// closer support custom killsignal with custom killtimeout | ||
type closer struct { | ||
cmd *exec.Cmd | ||
query url.Values | ||
} | ||
|
||
func (c *closer) Close() (err error) { | ||
sig := os.Kill | ||
if s := c.query.Get("killsignal"); s != "" { | ||
sig = syscall.Signal(core.Atoi(s)) | ||
} | ||
|
||
log.Trace().Msgf("[exec] kill with signal=%d", sig) | ||
err = c.cmd.Process.Signal(sig) | ||
|
||
if s := c.query.Get("killtimeout"); s != "" { | ||
timeout := time.Duration(core.Atoi(s)) * time.Second | ||
timer := time.AfterFunc(timeout, func() { | ||
log.Trace().Msgf("[exec] kill after timeout=%s", s) | ||
_ = c.cmd.Process.Kill() | ||
}) | ||
defer timer.Stop() // stop timer if Wait ends before timeout | ||
} | ||
|
||
return errors.Join(err, c.cmd.Wait()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.