Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scripts don't work if user doesn't have write permission to CWD #1106

Open
HiassofT opened this issue Jan 9, 2024 · 1 comment
Open

Scripts don't work if user doesn't have write permission to CWD #1106

HiassofT opened this issue Jan 9, 2024 · 1 comment

Comments

@HiassofT
Copy link

HiassofT commented Jan 9, 2024

Operating system: RPiOS Bookwork lite 64bit
Python version: 3.11.2
Pi model: Pi 5
GPIO Zero version: 2.0
Pin factory used: default / lgpio

Trying to run a gpiozero script from a directory where the user doesn't have write permissions fails miserably as lgpio tries to create a named pipe in that directory. eg:

from gpiozero import Button

b5 = Button(5)

Then run this script eg as user pi from the root directory

pi@raspberrypi:~ $ cd /
pi@raspberrypi:/ $ python3 ~/gpiotest.py 
2024-01-09 14:52:43 xCreatePipe: Can't set permissions (436) for //.lgd-nfy0, No such file or directory
/usr/lib/python3/dist-packages/gpiozero/devices.py:295: PinFactoryFallback: Falling back from lgpio: [Errno 2] No such file or directory: '.lgd-nfy-3'
  warnings.warn(
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/gpiozero/pins/pi.py", line 408, in pin
    pin = self.pins[info]
          ~~~~~~~~~^^^^^^
KeyError: PinInfo(number=29, name='GPIO5', names=frozenset({'GPIO5', 5, 'BOARD29', 'WPI21', '5', 'J8:29', 'BCM5'}), pull='', row=15, col=1, interfaces=frozenset({'', 'dpi', 'spi', 'gpio', 'uart', 'i2c'}))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pi/gpiotest.py", line 3, in <module>
    b5 = Button(5)
         ^^^^^^^^^
  File "/usr/lib/python3/dist-packages/gpiozero/devices.py", line 103, in __call__
    self = super().__call__(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/gpiozero/input_devices.py", line 412, in __init__
    super().__init__(
  File "/usr/lib/python3/dist-packages/gpiozero/mixins.py", line 417, in __init__
    super().__init__(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/gpiozero/input_devices.py", line 162, in __init__
    super().__init__(
  File "/usr/lib/python3/dist-packages/gpiozero/mixins.py", line 243, in __init__
    super().__init__(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/gpiozero/input_devices.py", line 79, in __init__
    super().__init__(pin, pin_factory=pin_factory)
  File "/usr/lib/python3/dist-packages/gpiozero/devices.py", line 549, in __init__
    pin = self.pin_factory.pin(pin)
          ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/gpiozero/pins/pi.py", line 410, in pin
    pin = self.pin_class(self, info)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/gpiozero/pins/rpigpio.py", line 101, in __init__
    GPIO.setup(self._number, GPIO.IN, self.GPIO_PULL_UPS[self._pull])
RuntimeError: Cannot determine SOC peripheral base address

Running the script from a directory where the user has write permission works but after exit the current working directory is cluttered with a name pipe:

pi@raspberrypi:/ $ cd ~
pi@raspberrypi:~ $ python3 gpiotest.py 
pi@raspberrypi:~ $ ls -la .lgd*
prw-rw-r-- 1 pi pi 0 Jan  9 15:07 .lgd-nfy0
pi@raspberrypi:~ $ 

lgpio seems to have a lguSetWorkDir function and a LG_WD environment variable to configure the directory where it creates it's pipe(s) and it might be a good idea to set that to something safe like /tmp/gpiozero-PID/ that's guaranteed to be writable and not clash when running multiple scripts using gpiozero/lgpio in parallel - that seems to be the recommended solution until the underlying lgpio issue joan2937/lg#12 is resolved

@m666m
Copy link

m666m commented May 24, 2024

This file .lgd-nfy0 exists in the directorys with running pinout, everytime everywhere...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants