pySerial in a daemon process

paul paul.faulstich at gmail.com
Sun Aug 26 16:03:01 EDT 2007


I am writing a daemon process that reads data from the serial port /
dev/ttyS0.  I am using pyserial & the method for setting up a daemon
described in "Chris' Python Page" (http://homepage.hispeed.ch/py430/
python/) on an Ubuntu linux pc.

Everything works great EXCEPT...

in the daemon script, there are two lines to change the uid & gid that
the script runs as:
os.setegid(10)
os.seteuid(1000)

If I comment these out, so that the daemon runs as root, then
everything works fine.  I can also manually run the script that the
daemon process kicks off from my own id just fine.

If I put these back in and try to run the daemon, the script fails
when I try to connect to the serial port, with this error:
serial.serialutil.SerialException: Could not open port: [Errno 13]
Permission denied: '/dev/ttyS0'

In my debugging I have tried setting the uid to my own uid, and the
gid to a variety of different groups that I belong to.  None of them
work.

I could certainly run the daemon as root, but I would rather not.
What really confuses me is that if I manually run the script as myself
(without using the daemon script), it connects fine, but when root
uses os.seteuid() to my uid, it fails.

What do I need to do to get this to work?

Many thanks,

Paul




More information about the Python-list mailing list