Skip to content

Commit

Permalink
check for symlinks masking gpiochip
Browse files Browse the repository at this point in the history
  • Loading branch information
warthog618 committed Jan 25, 2025
1 parent bbe4b67 commit 3f80dbc
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion sim.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package gpiosim
import (
"bufio"
"fmt"
"io/fs"
"os"
"os/exec"
"path"
Expand Down Expand Up @@ -184,7 +185,16 @@ func (b *builder) live() (*Sim, error) {
}
s.Chips[i].devName = devName
s.Chips[i].chipName = chipName
s.Chips[i].devPath = path.Join("/dev", chipName)
devPath := path.Join("/dev", chipName)
stat, err := os.Lstat(devPath)
if err != nil {
return nil, err
}
if stat.Mode()&fs.ModeSymlink != 0 {
err = errors.New("A symlink (" + devPath + ") is masking GPIO device " + chipName)
return nil, err
}
s.Chips[i].devPath = devPath
s.Chips[i].sysfsPath = path.Join("/sys/devices/platform", devName, chipName)
}
return &s, nil
Expand Down

0 comments on commit 3f80dbc

Please sign in to comment.