diff options
author | Martin Sivak <msivak@redhat.com> | 2007-12-21 12:17:26 +0100 |
---|---|---|
committer | Martin Sivak <msivak@redhat.com> | 2007-12-21 12:17:26 +0100 |
commit | 5b1aab4ce3ceaf7075f620083078eaa32b59d7df (patch) | |
tree | 66380ebf9c576c8a86a49446de2c9fe52447ad06 | |
parent | a9d245e9ddf98c84825ee5accfffa43a23575c16 (diff) | |
download | firstaidkit-5b1aab4ce3ceaf7075f620083078eaa32b59d7df.tar.gz firstaidkit-5b1aab4ce3ceaf7075f620083078eaa32b59d7df.tar.xz firstaidkit-5b1aab4ce3ceaf7075f620083078eaa32b59d7df.zip |
Add spawnvch utility function to run process in chroot environment
-rw-r--r-- | tasker/utils.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tasker/utils.py b/tasker/utils.py new file mode 100644 index 0000000..139bb39 --- /dev/null +++ b/tasker/utils.py @@ -0,0 +1,38 @@ +# First Aid Kit - diagnostic and repair tool for Linux +# Copyright (C) 2007 Martin Sivak <msivak@redhat.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +import os +import sys +import subprocess + +def spawnvch(executable, params, chroot): #returns errorcode + """Simpliest chroot modification of spawn + executable - path to binary to execute (in chroot!) + params - it's parameters + chroot - directory to chroot to + +Returns the error code returned by process""" + + pid = os.fork() + if pid==0: #child + os.chroot(chroot) + os.execv(executable, params) + os.exit(1) + else: + res = os.waitpid(pid, 0) + return os.WEXITSTATUS(res) + |