fixed permission on created devices

This commit is contained in:
2026-02-18 23:50:40 +01:00
parent 0202cb4a7f
commit 6172d9e2aa
5 changed files with 68 additions and 1 deletions
+55
View File
@@ -4,7 +4,10 @@ package client
import (
"fmt"
"log"
"os"
"path/filepath"
"time"
"golang.org/x/sys/unix"
)
@@ -26,3 +29,55 @@ func closeFDs(fds [2]int) {
func fdToFile(fd int, name string) *os.File {
return os.NewFile(uintptr(fd), name)
}
// fixVHCIDevicePermissions waits for the VHCI-attached device to create
// device nodes (e.g. /dev/video*) and sets them to world-accessible.
// VHCI-created devices don't get normal udev rules applied, so they
// default to root-only access.
func fixVHCIDevicePermissions(port int) {
// Wait for the device to finish enumerating and create device nodes
// The kernel needs time to enumerate descriptors and bind drivers
for attempt := 0; attempt < 10; attempt++ {
time.Sleep(500 * time.Millisecond)
// Find device nodes created by this VHCI port
// VHCI creates devices under /sys/devices/platform/vhci_hcd.0/usbN/
// We look for video4linux devices
matches, _ := filepath.Glob("/sys/devices/platform/vhci_hcd.0/usb*/*/video4linux/video*")
for _, m := range matches {
devName := filepath.Base(m)
devPath := "/dev/" + devName
if _, err := os.Stat(devPath); err == nil {
if err := os.Chmod(devPath, 0666); err == nil {
log.Printf("[use] set permissions 0666 on %s", devPath)
}
}
}
// Also check for other common device types (input, sound, etc.)
for _, subsys := range []string{"sound/card*", "input/input*/event*"} {
sysMatches, _ := filepath.Glob("/sys/devices/platform/vhci_hcd.0/usb*/*/" + subsys)
for _, m := range sysMatches {
devName := filepath.Base(m)
devPath := "/dev/" + devName
// For sound devices, also check /dev/snd/
if _, err := os.Stat(devPath); err == nil {
os.Chmod(devPath, 0666)
}
devPath = "/dev/snd/" + devName
if _, err := os.Stat(devPath); err == nil {
os.Chmod(devPath, 0666)
}
}
}
if attempt == 0 {
continue // first iteration: always wait more
}
// Check if we found any video devices
if len(matches) > 0 {
return
}
}
}