Merge pull request #642 from scpcom/fix-hid-lock

Fix hid lock
This commit is contained in:
wenjie
2025-11-21 11:36:49 +08:00
committed by GitHub
2 changed files with 17 additions and 0 deletions

View File

@@ -12,6 +12,14 @@ import (
func (s *Service) Reset(c *gin.Context) {
var rsp proto.Response
h := GetHid()
h.Lock()
h.CloseNoLock()
defer func() {
h.OpenNoLock()
h.Unlock()
}()
// reset USB
f, err := os.OpenFile("/sys/kernel/config/usb_gadget/g0/UDC", os.O_WRONLY, 0644)
if err != nil {

View File

@@ -12,6 +12,7 @@ import (
log "github.com/sirupsen/logrus"
"NanoKVM-Server/proto"
"NanoKVM-Server/service/hid"
)
const (
@@ -103,6 +104,14 @@ func (s *Service) MountImage(c *gin.Context) {
return
}
h := hid.GetHid()
h.Lock()
h.CloseNoLock()
defer func() {
h.OpenNoLock()
h.Unlock()
}()
// reset usb
commands := []string{
"echo > /sys/kernel/config/usb_gadget/g0/UDC",