Re: how to spawn a process under different user

2009-07-03 Thread Nick Craig-Wood
Gabriel Genellina gagsl-...@yahoo.com.ar wrote:
  En Thu, 02 Jul 2009 19:27:05 -0300, Tim Harig user...@ilthio.net
  escribió:
  On 2009-07-02, sanket sanket.s.pa...@gmail.com wrote:
  sanket wrote:
   I am trying to use python's subprocess module to launch a process.
   but in order to do that I have to change the user.
  I am using python 2.4 on centos.
 
  I have never done this in python; but, using the normal system calls in C
  the process is basically:
  
  1. fork() a  new process
  2. the child process changes its user id with setreuid() and
  possibly its group id with setregid()
  3. then the child exec()s new process which replaces itself
 
  All of the necessary functions should be under the os module on POSIX
  operating systems.
 
  How to do that using the subprocess module: write a function for item (2)
  above and pass it as the preexec_fn argument to Popen. preexec_fn is
  executed after fork() and before exec()

If you are forking 100s of processes a second you want to use the
method above, however I think it is easier to use su (assuming you
start off as root),

so instead of passing

  ['mycommand', 'my_arg1', 'my_arg2']

to Popen, pass

  ['su', '-', 'username', '-c', 'mycommand my_arg1 my_arg2']

There is some opportunity for quoting problems there, but it is easy!

-- 
Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


how to spawn a process under different user

2009-07-02 Thread sanket
Hello All,

I am trying to use python's subprocess module to launch a process.
but in order to do that I have to change the user.

I am not getting any clue how to do that?
so can anyone please tell me How can I spawn a process under different
user than currently I am logging in as.

Thank you,
sanket
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to spawn a process under different user

2009-07-02 Thread sanket
On Jul 2, 1:58 pm, Tim Golden m...@timgolden.me.uk wrote:
 sanket wrote:
  Hello All,

  I am trying to use python's subprocess module to launch a process.
  but in order to do that I have to change the user.

  I am not getting any clue how to do that?
  so can anyone please tell me How can I spawn a process under different
  user than currently I am logging in as.

 What platform are you on? If you are on Windows,
 there was a thread on this subject some time in
 the last month. (Short answer: switching user before
 launching subprocess won't work; switching within
 the subprocess will...)

 TJG

Hi TJG,
Thanks for the reply.

I am using python 2.4 on centos.

Thanks,
sanket
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to spawn a process under different user

2009-07-02 Thread Tim Harig
On 2009-07-02, sanket sanket.s.pa...@gmail.com wrote:
 sanket wrote:
  I am trying to use python's subprocess module to launch a process.
  but in order to do that I have to change the user.
 I am using python 2.4 on centos.

I have never done this in python; but, using the normal system calls in C
the process is basically:

1. fork() a  new process
2. the child process changes its user id with setreuid() and
possibly its group id with setregid()
3. then the child exec()s new process which replaces itself

All of the necessary functions should be under the os module on POSIX
operating systems.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to spawn a process under different user

2009-07-02 Thread Gabriel Genellina

En Thu, 02 Jul 2009 19:27:05 -0300, Tim Harig user...@ilthio.net
escribió:

On 2009-07-02, sanket sanket.s.pa...@gmail.com wrote:

sanket wrote:



 I am trying to use python's subprocess module to launch a process.
 but in order to do that I have to change the user.

I am using python 2.4 on centos.


I have never done this in python; but, using the normal system calls in C
the process is basically:

1. fork() a  new process
2. the child process changes its user id with setreuid() and
possibly its group id with setregid()
3. then the child exec()s new process which replaces itself

All of the necessary functions should be under the os module on POSIX
operating systems.


How to do that using the subprocess module: write a function for item (2)
above and pass it as the preexec_fn argument to Popen. preexec_fn is
executed after fork() and before exec()

--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list