pySerial in a daemon process

Discussion in 'Python' started by paul, Aug 26, 2007.

  1. paul

    paul Guest

    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
     
    paul, Aug 26, 2007
    #1
    1. Advertising

  2. 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
     
    Bjoern Schliessmann, Aug 26, 2007
    #2
    1. Advertising

  3. paul

    paul Guest

    On Aug 26, 5:20 pm, Bjoern Schliessmann <usenet-
    > wrote:
    > 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
     
    paul, Aug 26, 2007
    #3
  4. In message <>, 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?
     
    Lawrence D'Oliveiro, Aug 27, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Thomas Dybdahl Ahle

    Python daemon process

    Thomas Dybdahl Ahle, Aug 26, 2006, in forum: Python
    Replies:
    3
    Views:
    484
    Thomas Dybdahl Ahle
    Aug 29, 2006
  2. Sakagami Hiroki

    Creating a daemon process in Python

    Sakagami Hiroki, Feb 21, 2007, in forum: Python
    Replies:
    9
    Views:
    938
    Nick Craig-Wood
    Feb 23, 2007
  3. Jean-Paul Calderone
    Replies:
    0
    Views:
    459
    Jean-Paul Calderone
    Mar 20, 2009
  4. Floris Bruynooghe
    Replies:
    1
    Views:
    454
    Floris Bruynooghe
    Mar 24, 2009
  5. Daemon Win32::Daemon;

    , Sep 7, 2006, in forum: Perl Misc
    Replies:
    0
    Views:
    258
Loading...

Share This Page