summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael E Brown <mebrown@michaels-house.net>2007-12-11 21:19:05 -0600
committerMichael E Brown <mebrown@michaels-house.net>2007-12-11 21:19:05 -0600
commit61e0834a05ffdc25e8143866f26774503d96599f (patch)
tree6377434fcf1f19f8fe55e3815830343a98a61801
parenta4e74ee60455c0c631a7fe068e6587ab285100c4 (diff)
parent208e9b146a9b0189dd13bc5accd73ffc5efd4b9d (diff)
downloadmock-61e0834a05ffdc25e8143866f26774503d96599f.tar.gz
mock-61e0834a05ffdc25e8143866f26774503d96599f.tar.xz
mock-61e0834a05ffdc25e8143866f26774503d96599f.zip
Merge branch 'mock-0.8' of ssh://mebrown@git.fedoraproject.org/git/hosted/mock into mock-0.8
* 'mock-0.8' of ssh://mebrown@git.fedoraproject.org/git/hosted/mock: add warning for when personality has no constant mapping. - make "mock --chroot" non-interactive - set the exit code of "mock --chroot" to the exit code of the process run in the chroot - log the output of the process to root.log add i586/i686 setarch defs. add info message when setarch is ran. add sparcv9 for setarch. add setarch defs for sparc 32/64 personality() returns -1 on error. add docs for --orphanskill mode. add failsafe for daemontest.c such that it exits after 5 mins rather than hanging around forever. add return code propagation test for --chroot cmd. let yum resolvedep run w/privs because it has to download additional metadata sometimes.
-rw-r--r--docs/daemontest.c4
-rw-r--r--docs/mock.19
-rwxr-xr-xdocs/releasetests.sh13
-rwxr-xr-xpy/mock.py13
-rw-r--r--py/mock/exception.py5
-rw-r--r--py/mock/util.py29
6 files changed, 58 insertions, 15 deletions
diff --git a/docs/daemontest.c b/docs/daemontest.c
index f0e7393..5f63e7a 100644
--- a/docs/daemontest.c
+++ b/docs/daemontest.c
@@ -95,7 +95,9 @@ char str[10];
int main()
{
daemonize();
- while(1) sleep(1); /* run */
+ // run for roughly 5 mins then exit. No need to stick around if unit test fails.
+ int i=0;
+ for( i=0; i<300; i++ ) sleep(1);
}
/* EOF */
diff --git a/docs/mock.1 b/docs/mock.1
index cc29ee4..624c026 100644
--- a/docs/mock.1
+++ b/docs/mock.1
@@ -13,6 +13,8 @@ mock [options] {\fB\-\-init\fR|\fBclean\fR|\fBshell\fR}
mock [options] \fB\-\-installdeps\fR {SRPM|RPM}
.LP
mock [options] \fB\-\-install\fR PACKAGE
+.LP
+mock [options] \fB\-\-orphanskill\fR
.SH "DESCRIPTION"
.LP
@@ -99,11 +101,16 @@ Show version number and exit.
.TP
\fB\-\-rebuild\fR \- If no command is specified, rebuild is assumed. Rebuilds the specified SRPM(s). The buildroot is cleaned first, unless --no-clean is specified.
.TP
-\fB\-\-chroot\fR|\fB\-\-shell\fR \- run the specified command within the chroot (which must already be initialized -- no 'clean' is performed). If no command specified, /bin/sh is run.
+\fB\-\-shell\fR \- run the specified command interactively within the chroot (which must already be initialized -- no 'clean' is performed). If no command specified, /bin/sh is run.
+.TP
+\fB\-\-chroot\fR \- run the specified command non-interactively within the chroot (which must already be initialized -- no 'clean' is performed). Command output will be sent to the log files.
.TP
\fB\-\-installdeps\fR \- find out deps for SRPM or RPM, and do a yum install to put them in the buildroot. Buildroot must already be initialized -- no 'clean' is performed
.TP
\fB\-\-install\fR \- Do a yum install PACKAGE inside the buildroot. Buildroot must already be initialized -- no 'clean' is performed
+.TP
+\fB\-\-orphanskill\fP
+Noop mode that simply checks that no stray processes are running in the chroot. Kills any processes that it finds using specified root.
.SH "FILES"
.LP
\fI/etc/mock/\fP \- default configuration directory
diff --git a/docs/releasetests.sh b/docs/releasetests.sh
index 0d2caa5..2a98e1d 100755
--- a/docs/releasetests.sh
+++ b/docs/releasetests.sh
@@ -53,6 +53,19 @@ if [ ! -e $CHROOT/usr/include/python* ]; then
fi
#
+# Test that chroot return code is properly passed up
+#
+set +e
+time $MOCKCMD --offline --chroot -- bash -c "exit 5"
+if [ $? -ne 5 ]; then
+ echo "'mock --chroot' return code not properly passed back."
+ exit 1
+fi
+set -e
+
+
+
+#
# Test offline build
#
time $MOCKCMD --offline --rebuild mock-*.src.rpm
diff --git a/py/mock.py b/py/mock.py
index 012bb29..7b6acef 100755
--- a/py/mock.py
+++ b/py/mock.py
@@ -459,7 +459,7 @@ def main(ret):
elif options.mode == 'clean':
chroot.clean()
- elif options.mode in ('chroot', 'shell'):
+ elif options.mode == 'shell':
chroot.tryLockBuildRoot()
try:
chroot._mountall()
@@ -472,6 +472,17 @@ def main(ret):
finally:
chroot._umountall()
+ elif options.mode == 'chroot':
+ if len(args) == 0:
+ log.critical("You must specify a command to run")
+ sys.exit(50)
+ else:
+ log.info("Running in chroot: %s" % args)
+
+ chroot.tryLockBuildRoot()
+ chroot._resetLogging()
+ chroot.doChroot(args)
+
elif options.mode == 'installdeps':
if len(args) == 0:
log.critical("You must specify an SRPM file.")
diff --git a/py/mock/exception.py b/py/mock/exception.py
index d93fcf3..b6d6282 100644
--- a/py/mock/exception.py
+++ b/py/mock/exception.py
@@ -8,16 +8,19 @@
# python library imports
#from exceptions import Exception
+import os
# our imports
# classes
class Error(Exception):
"base class for our errors."
- def __init__(self, msg):
+ def __init__(self, msg, status=None):
Exception.__init__(self)
self.msg = msg
self.resultcode = 1
+ if status is not None and os.WIFEXITED(status):
+ self.resultcode = os.WEXITSTATUS(status)
def __str__(self):
return self.msg
diff --git a/py/mock/util.py b/py/mock/util.py
index ee40994..cbb3653 100644
--- a/py/mock/util.py
+++ b/py/mock/util.py
@@ -184,11 +184,13 @@ def chomp(line):
return line
# taken from sys/personality.h
-personality_defs = {}
-personality_defs['x86_64'] = 0x0000
-personality_defs['ppc64'] = 0x0000
-personality_defs['i386'] = 0x0008
-personality_defs['ppc'] = 0x0008
+PER_LINUX32=0x0008
+PER_LINUX=0x0000
+personality_defs = {
+ 'x86_64': PER_LINUX, 'ppc64': PER_LINUX, 'sparc64': PER_LINUX,
+ 'i386': PER_LINUX32, 'i586': PER_LINUX32, 'i686': PER_LINUX32,
+ 'ppc': PER_LINUX32, 'sparc': PER_LINUX32, 'sparcv9': PER_LINUX32,
+}
import ctypes
_libc = ctypes.cdll.LoadLibrary("libc.so.6")
@@ -198,11 +200,16 @@ _libc.personality.restype = ctypes.c_int
decorate(traceLog())
def condPersonality(per=None):
- if personality_defs.get(per, None) is None: return
+ if per is None:
+ return
+ if personality_defs.get(per, None) is None:
+ getLog().warning("Unable to find predefined setarch personality constant for '%s' arch."
+ " You may have to manually run setarch."% per)
+ return
res = _libc.personality(personality_defs[per])
- if res:
+ if res == -1:
raise OSError(_errno.value, os.strerror(_errno.value))
- getLog().debug("set personality (setarch)")
+ getLog().info("Ran setarch '%s'" % per)
CLONE_NEWNS = 0x00020000
@@ -272,11 +279,11 @@ def do(command, chrootPath=None, timeout=0, raiseExc=True, returnOutput=0, uidMa
signal.signal(signal.SIGALRM, oldhandler)
# mask and return just return value, plus child output
- if raiseExc and os.WEXITSTATUS(ret):
+ if raiseExc and ((os.WIFEXITED(ret) and os.WEXITSTATUS(ret)) or os.WIFSIGNALED(ret)):
if returnOutput:
- raise mock.exception.Error, "Command failed: \n # %s\n%s" % (command, output)
+ raise mock.exception.Error, ("Command failed: \n # %s\n%s" % (command, output), ret)
else:
- raise mock.exception.Error, "Command failed. See logs for output.\n # %s" % command
+ raise mock.exception.Error, ("Command failed. See logs for output.\n # %s" % (command,), ret)
return output