473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 4268
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Joshua Beall | last post by:
Hi All, I am working on a mailing list program for a client, and I am wondering what tbe hest way to deal with script timeouts is. I realize that I could use set_time_limit() to increase the...
3
by: Rob Hunter | last post by:
Hi all. I want to run a Python daemon that manages a "to-do" queue. I want it so that the daemon is always running, where its running consists of looking at the queue to see if it has any jobs,...
4
by: Joe Wong | last post by:
Hi, I am developing two app on Windows, one is a GUI using wxPython and the other is like a daemon process. The GUI app will have a start/stop button to control the excution of the daemon. While I...
0
by: Joe Wong | last post by:
Hi, I am developing two app on Windows, one is a GUI using wxPython and the other is like a daemon process. The GUI app will have a start/stop button to control the excution of the daemon. While I...
3
by: Thomas Dybdahl Ahle | last post by:
Hi, I'm writing a program, using popen4(gnuchess), The problem is, that gnuchess keeps running after program exit. I know about the atexit module, but in java, you could make a process a daemon...
9
by: Sakagami Hiroki | last post by:
Hi, What is the easiest way to create a daemon process in Python? Google says I should call fork() and other system calls manually, but is there no os.daemon() and the like? Regards, --...
3
by: Ben Finney | last post by:
Howdy all, For making a Python program calve off an independent daemon process of itself, I found Carl J. Schroeder's recipe in the ASPN Python Cookbook....
2
by: rahul | last post by:
Hello all I have written a chat server. It is invoked as follows - $ ./server -start It becomes a daemon. I want to implement a stop call- $ ./server -stop The approach I am following is to...
1
by: turtleRider | last post by:
Hi, I am new to Python and non-web programming. I am using pySerial in OSX 10.5.2 (Python 2.5) to access a bluetooth module that is mapped to a device file. I can access the device with screen...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.