Re: spawnle & umask

Discussion in 'Python' started by Yves Glodt, Dec 8, 2005.

  1. Yves Glodt

    Yves Glodt Guest

    Fredrik Lundh wrote:
    > Yves Glodt wrote:
    >
    >> I tried something like this but the umask part does not work clearly...:
    >>
    >> newpid =
    >> os.spawnle(os.P_NOWAIT,'/usr/bin/touch','/usr/bin/touch','xyz','umask 0113')
    >>
    >> What would be the correct syntax for setting the umask for the created
    >> process...?

    >
    > not sure, but something like
    >
    > try:
    > old_mask = os.umask(0113)
    > newpid = os.spawnle(...)
    > finally:
    > os.umask(old_mask) # restore
    >
    > might work.


    It does, I did like this:

    os.umask(0113)
    newpid =
    os.spawnl(os.P_NOWAIT,'/usr/local/bin/wine','/usr/local/bin/wine',executable)

    But I wanted to use spawnle and it's env argument, to avoid setting
    umask manually...

    regards,
    Yves


    > </F>
    >
    >
    >
    Yves Glodt, Dec 8, 2005
    #1
    1. Advertising

  2. Yves Glodt

    David Wahler Guest

    Yves Glodt wrote:
    > It does, I did like this:
    >
    > os.umask(0113)
    > newpid =
    > os.spawnl(os.P_NOWAIT,'/usr/local/bin/wine','/usr/local/bin/wine',executable)
    >
    > But I wanted to use spawnle and it's env argument, to avoid setting
    > umask manually...


    The umask is not part of the environment, so there's no way to set it
    directly through spawnle. Why don't you want to use os.umask?

    -- David
    David Wahler, Dec 8, 2005
    #2
    1. Advertising

  3. Yves Glodt

    Yves Glodt Guest

    David Wahler wrote:
    > Yves Glodt wrote:
    >> It does, I did like this:
    >>
    >> os.umask(0113)
    >> newpid =
    >> os.spawnl(os.P_NOWAIT,'/usr/local/bin/wine','/usr/local/bin/wine',executable)
    >>
    >> But I wanted to use spawnle and it's env argument, to avoid setting
    >> umask manually...

    >
    > The umask is not part of the environment, so there's no way to set it
    > directly through spawnle.


    ok

    > Why don't you want to use os.umask?


    Only because I thought spawnle could set it through env...
    But as it can't I will now go with os.umask.

    thanks,
    Yves

    > -- David
    >
    Yves Glodt, Dec 8, 2005
    #3
  4. Yves Glodt

    Donn Cave Guest

    In article <>,
    Yves Glodt <> wrote:

    > David Wahler wrote:
    > > Yves Glodt wrote:
    > >> It does, I did like this:
    > >>
    > >> os.umask(0113)
    > >> newpid =
    > >> os.spawnl(os.P_NOWAIT,'/usr/local/bin/wine','/usr/local/bin/wine',executabl
    > >> e)
    > >>
    > >> But I wanted to use spawnle and it's env argument, to avoid setting
    > >> umask manually...

    > >
    > > The umask is not part of the environment, so there's no way to set it
    > > directly through spawnle.

    >
    > ok
    >
    > > Why don't you want to use os.umask?

    >
    > Only because I thought spawnle could set it through env...
    > But as it can't I will now go with os.umask.


    On UNIX, the "spawn" functions are just Python code that wraps up
    the low level fork and execve system calls. There's no reason you
    can't write your own version if you like, that does what you need.

    It does make sense to want to modify umask and who knows what other
    inheritable context in the fork, so you might be thinking of an
    API with a function that's called at that time, like

    spawnve(wait, file, args, env, func)

    The funny thing is, that's such a good idea that the implementation
    already has a function with that signature. The only difference is
    that func() also must call the appropriate execve function. So for
    example,

    def execumask113(file, args, env):
    os.umask(0113)
    return os.execve(file, args, env)

    ...
    os._spawnvef(os.P_NOWAIT, '/usr/local/bin/wine',
    ['wine', exe], os.environ, execumask113)

    Now the problem is that this function is evidently not part of the
    published API for os.py, so it would be unseemly to complain if it
    were to change in later versions. So I guess the right thing to do
    is write your own spawn function from the ground up. But at least
    you have some ideas there about how it might work.

    Donn Cave,
    Donn Cave, Dec 8, 2005
    #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. Yves Glodt

    spawnle & umask

    Yves Glodt, Dec 8, 2005, in forum: Python
    Replies:
    0
    Views:
    297
    Yves Glodt
    Dec 8, 2005
  2. Replies:
    2
    Views:
    414
  3. Faik Uygur

    umask option for tarfile extract

    Faik Uygur, Jun 15, 2006, in forum: Python
    Replies:
    0
    Views:
    379
    Faik Uygur
    Jun 15, 2006
  4. Faik Uygur

    getting umask without changing it

    Faik Uygur, Jun 16, 2006, in forum: Python
    Replies:
    0
    Views:
    231
    Faik Uygur
    Jun 16, 2006
  5. Daniel Berger

    umask vs umask

    Daniel Berger, Apr 13, 2008, in forum: Ruby
    Replies:
    8
    Views:
    127
    Heesob Park
    Apr 16, 2008
Loading...

Share This Page