471,350 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

pySerial in a daemon process

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

Aug 26 '07 #1
3 4119
paul wrote:
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'
Did you check the permissions on this file? Often you have to be
member of a "dialout" group or similar to get access.

Regards,
Björn

--
BOFH excuse #172:

pseudo-user on a pseudo-terminal

Aug 26 '07 #2
On Aug 26, 5:20 pm, Bjoern Schliessmann <usenet-
mail-0306.20.chr0n...@spamgourmet.comwrote:
paul wrote:
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'

Did you check the permissions on this file? Often you have to be
member of a "dialout" group or similar to get access.

Regards,

Björn

--
BOFH excuse #172:

pseudo-user on a pseudo-terminal

THANKS! That did it, but perhaps can you explain to me why...

Before I had posted this question first thing I did was to look at /
dev/ttyS0, and indeed the group is dialout (gid=20), so I tried a
couple of things:

1. checked my id to see if I was a member of dialout, and indeed I
am. So, I edited the daemon script to use my id and set the gid to
dialout (ie: os.setegid(20) & os.seteuid(1000)) and it still failed.

2. made the id I really want to use (pydaemon, uid=110) a member of
dialout, and set the daemon script to use those (ie: os.setegid(20) &
os.seteuid(110)) and it still failed...

After reading your comment, I went and did a chgrp to set the various
script file groups to dialout, and indeed it now works. What confuses
me is that if the script needed that group, why doesn't the setegid or
seteuid fail? Why does the script keep running okay until the
connect, and fail then?

Thanks!

Paul

Aug 26 '07 #3
In message <11**********************@w3g2000hsg.googlegroups. com>, paul
wrote:
Before I had posted this question first thing I did was to look at /
dev/ttyS0, and indeed the group is dialout (gid=20)...
What are the full protections on the serial port? That is, can you post the
output of

ls -l /dev/ttyS0

please?

Aug 27 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Joshua Beall | last post: by
3 posts views Thread by Rob Hunter | last post: by
4 posts views Thread by Joe Wong | last post: by
reply views Thread by Joe Wong | last post: by
3 posts views Thread by Thomas Dybdahl Ahle | last post: by
9 posts views Thread by Sakagami Hiroki | last post: by
3 posts views Thread by Ben Finney | last post: by
2 posts views Thread by rahul | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.