added login and permission fix

This commit is contained in:
2026-02-18 23:59:16 +01:00
parent 6172d9e2aa
commit 3579924883
5 changed files with 60 additions and 35 deletions
+45 -34
View File
@@ -7,6 +7,7 @@ import (
"log"
"os"
"path/filepath"
"strings"
"time"
"golang.org/x/sys/unix"
@@ -35,48 +36,58 @@ func fdToFile(fd int, name string) *os.File {
// 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++ {
// 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 < 15; 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 {
found := false
// Walk the VHCI sysfs tree to find device nodes at any depth.
// Paths look like: vhci_hcd.0/usb3/3-1/3-1:1.0/video4linux/video0
filepath.WalkDir("/sys/devices/platform/vhci_hcd.0", func(path string, d os.DirEntry, err error) error {
if err != nil {
return nil
}
dir := filepath.Dir(path)
parent := filepath.Base(dir)
// video4linux devices → /dev/videoN
if parent == "video4linux" && strings.HasPrefix(d.Name(), "video") {
devPath := "/dev/" + d.Name()
if err := os.Chmod(devPath, 0666); err == nil {
log.Printf("[use] set permissions 0666 on %s", devPath)
found = true
}
}
// sound devices → /dev/snd/*
if parent == "sound" && strings.HasPrefix(d.Name(), "card") {
// For sound cards, chmod all related device nodes
sndDir := filepath.Join(path, "device")
if _, err := os.Stat(sndDir); err == nil {
filepath.WalkDir("/dev/snd", func(sndPath string, sd os.DirEntry, err error) error {
if err == nil && !sd.IsDir() {
os.Chmod(sndPath, 0666)
}
return nil
})
}
}
// input devices → /dev/input/eventN
if strings.HasPrefix(d.Name(), "event") && strings.Contains(path, "/input/input") {
devPath := "/dev/input/" + d.Name()
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)
}
}
}
return nil
})
if attempt == 0 {
continue // first iteration: always wait more
}
// Check if we found any video devices
if len(matches) > 0 {
if attempt >= 2 && found {
return
}
}