sushantnadkar / vcgencmd

Python binding for Raspberry Pi's Video Core General Command Service (vcgencmd)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Doesn't gracefully handle user without permissions

teeks99 opened this issue · comments

For most if not all sub-commands, the vcgencmd tool requires users to have root(-like?) permissions on the system.

For example, standard run:

$ sudo vcgencmd version
Dec 15 2020 18:34:30 
Copyright (c) 2012 Broadcom
version 4b4aff21f72c5b9ba39d83c7b0f8fa910a6ef99b (clean) (release) (start)

Vs. a failed run:

$ vcgencmd version
VCHI initialization failed

Which isn't 100% clear, but at least gives you an idea.

However, when running this python module, the error is completely opaque:

$ python3
Python 3.7.3 (default, Jul 25 2020, 13:03:44) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import vcgencmd
>>> out = vcgencmd.Vcgencmd()
>>> 
>>> out.version()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/myuser/vcgencmd/vcgencmd/vcgencmd.py", line 50, in version
    out = self.__verify_command("version", "", [""])
  File "/home/myuser/vcgencmd/vcgencmd/vcgencmd.py", line 27, in __verify_command
    return self.__run_command(cmd + source)
  File "/home/myuser/vcgencmd/vcgencmd/vcgencmd.py", line 18, in __run_command
    out = subprocess.check_output(args, stderr=subprocess.PIPE).decode("utf-8")
  File "/usr/lib/python3.7/subprocess.py", line 395, in check_output
    **kwargs).stdout
  File "/usr/lib/python3.7/subprocess.py", line 487, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['vcgencmd', 'version']' returned non-zero exit status 255.