summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile.am4
-rw-r--r--docs/mock.18
-rwxr-xr-xdocs/runtests.sh25
-rw-r--r--etc/mock/epel-6-i386.cfg4
-rw-r--r--etc/mock/epel-6-ppc64.cfg4
-rw-r--r--etc/mock/epel-6-x86_64.cfg4
-rw-r--r--etc/mock/fedora-10-i386.cfg39
-rw-r--r--etc/mock/fedora-10-ppc.cfg41
-rw-r--r--etc/mock/fedora-10-ppc64.cfg39
-rw-r--r--etc/mock/fedora-10-s390x.cfg36
-rw-r--r--etc/mock/fedora-10-sparc.cfg38
-rw-r--r--etc/mock/fedora-10-sparc64.cfg36
-rw-r--r--etc/mock/fedora-10-x86_64.cfg43
-rw-r--r--etc/mock/fedora-11-i386.cfg39
-rw-r--r--etc/mock/fedora-11-ppc.cfg41
-rw-r--r--etc/mock/fedora-11-ppc64.cfg39
-rw-r--r--etc/mock/fedora-11-s390x.cfg36
-rw-r--r--etc/mock/fedora-11-sparc.cfg38
-rw-r--r--etc/mock/fedora-11-sparc64.cfg36
-rw-r--r--etc/mock/fedora-11-x86_64.cfg43
-rw-r--r--etc/mock/site-defaults.cfg9
-rwxr-xr-xpy/mock.py53
-rw-r--r--py/mock/backend.py74
-rw-r--r--py/mock/exception.py7
-rw-r--r--py/mock/plugins/root_cache.py3
-rw-r--r--py/mock/plugins/tmpfs.py9
-rw-r--r--py/mock/plugins/yum_cache.py14
-rw-r--r--tests/daemontest.c104
-rw-r--r--tests/functions16
-rwxr-xr-xtests/runtests.sh90
-rw-r--r--tests/test1.tst15
-rw-r--r--tests/test2.tst14
-rw-r--r--tests/test3.tst14
-rw-r--r--tests/test4.tst14
-rw-r--r--tests/test5.tst14
-rw-r--r--tests/test6.tst21
-rw-r--r--tests/test7.tst27
-rw-r--r--tests/test8.tst21
-rw-r--r--tests/test9.tst16
39 files changed, 537 insertions, 591 deletions
diff --git a/Makefile.am b/Makefile.am
index b7f9b1c..ca05ec6 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -15,10 +15,10 @@ RELEASE_STRING = $(RELEASE_NAME)-$(RELEASE_VERSION)
VERSION = $(RELEASE_VERSION)
PACKAGE = $(RELEASE_NAME)
-CLEANFILES=mock-*.tar.gz mock-*.tar.bz2 mock-*.rpm _buildtemp version docs/daemontest
+CLEANFILES=mock-*.tar.gz mock-*.tar.bz2 mock-*.rpm _buildtemp version tests/daemontest
DISTCLEANFILES=*~ mock-unit-test/* x86_64/* noarch/* i386/*
-TESTS=./docs/runtests.sh
+TESTS=./tests/runtests.sh
$(TESTS): srpm
EXTRA_DIST = contrib
diff --git a/docs/mock.1 b/docs/mock.1
index b3e7d4a..6cb45a2 100644
--- a/docs/mock.1
+++ b/docs/mock.1
@@ -43,8 +43,12 @@ etc.) without leading '\-\-' are still accepted, but are deprecated. See
COMMANDS section, below, for detailed listing of all commands.
.LP
To use mock, a user should become a member of the \fBmock\fR group by
-adding their username to the \fBmock\fR line in /etc/group. Mock is
-not intended to be run directly as root.
+adding their username to the \fBmock\fR line in /etc/group. This can
+be done with the following command:
+.P
+ \fBsudo /usr/sbin/usermod -a -G mock $USER\fR
+
+Note that mock is not intended to be run directly as root.
.SH "COMMANDS"
.LP
diff --git a/docs/runtests.sh b/docs/runtests.sh
index c05ba21..a7a7aaa 100755
--- a/docs/runtests.sh
+++ b/docs/runtests.sh
@@ -18,6 +18,17 @@
set -e
set -x
+header() {
+ set +x
+ echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
+ echo $1
+ echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
+ echo ""
+ set -x
+}
+
+#MOCK_EXTRA_ARGS=--trace
+
CURDIR=$(pwd)
MOCKSRPM=${CURDIR}/mock-*.src.rpm
DIR=$(cd $(dirname $0); pwd)
@@ -27,7 +38,7 @@ cd $TOP_SRCTREE
#
# most tests below will use this mock command line
#
-testConfig=fedora-12-x86_64
+testConfig=fedora-13-x86_64
uniqueext="$$-$RANDOM"
outdir=${CURDIR}/mock-unit-test
MOCKCMD="sudo ./py/mock.py --resultdir=$outdir --uniqueext=$uniqueext -r $testConfig $MOCK_EXTRA_ARGS"
@@ -41,6 +52,7 @@ trap '$MOCKCMD --clean' INT HUP QUIT EXIT TERM
#
# pre-populate yum cache for the rest of the commands below
#
+header "pre-populating the cache"
time $MOCKCMD --init
time $MOCKCMD --installdeps $MOCKSRPM
if [ ! -e $CHROOT/usr/include/python* ]; then
@@ -51,6 +63,7 @@ fi
#
# Test that chroot return code is properly passed up
#
+header "testing that chroot return code is passed back correctly"
set +e
time $MOCKCMD --offline --chroot -- bash -c "exit 5"
res=$?
@@ -63,6 +76,7 @@ set -e
#
# test mock shell (interactive) and return code passing
#
+header "testing interactive shell and return code"
set +e
echo exit 5 | time $MOCKCMD --offline --shell
res=$?
@@ -75,6 +89,7 @@ set -e
#
# Test that chroot with one arg is getting passed though a shell (via os.system())
#
+header "testing that args are passed correctly to a shell"
time $MOCKCMD --offline --chroot 'touch /tmp/{foo,bar,baz}'
if [ ! -f $CHROOT/tmp/foo ] || [ ! -f $CHROOT/tmp/bar ] || [ ! -f $CHROOT/tmp/baz ]; then
echo "'mock --chroot' with one argument is not being passed to os.system()"
@@ -84,6 +99,7 @@ fi
#
# Test that chroot with more than one arg is not getting passed through a shell
#
+header "Test that chroot with more than one arg is not getting passed through a shell"
time $MOCKCMD --offline --chroot touch '/tmp/{quux,wibble}'
if [ ! -f $CHROOT/tmp/\{quux,wibble\} ] || [ -f $CHROOT/tmp/quux ] || [ -f $CHROOT/tmp/wibble ]; then
echo "'mock --chroot' with more than one argument is being passed to os.system()"
@@ -93,6 +109,7 @@ fi
#
# Test offline build as well as tmpfs
#
+header "Test offline build as well as tmpfs"
time $MOCKCMD --offline --enable-plugin=tmpfs --rebuild $MOCKSRPM
if [ ! -e $outdir/mock-*.noarch.rpm ]; then
echo "rebuild test FAILED. could not find $outdir/mock-*.noarch.rpm"
@@ -102,6 +119,7 @@ fi
#
# Test orphanskill feature (std)
#
+header "Test orphanskill feature (std)"
if pgrep daemontest; then
echo "Exiting because there is already a daemontest running."
exit 1
@@ -118,6 +136,7 @@ fi
#
# Test orphanskill feature (explicit)
#
+header "Test orphanskill feature (explicit)"
time $MOCKCMD --offline --init
time $MOCKCMD --offline --copyin docs/daemontest.c /tmp
time $MOCKCMD --offline --chroot -- gcc -Wall -o /tmp/daemontest /tmp/daemontest.c
@@ -142,6 +161,7 @@ fi
#
# test init/clean
#
+header "test init/clean"
time $MOCKCMD --offline --clean
if [ -e $CHROOT ]; then
echo "clean test FAILED. still found $CHROOT dir."
@@ -158,6 +178,7 @@ fi
#
# test old-style cmdline options
#
+header "test old-style cmdline options"
time $MOCKCMD --offline clean
time $MOCKCMD --offline init
time $MOCKCMD --offline install ccache
@@ -169,6 +190,7 @@ fi
#
# clean up from first round of tests
#
+header "clean up from first round of tests"
time $MOCKCMD --offline --clean
#
@@ -177,6 +199,7 @@ time $MOCKCMD --offline --clean
for i in $(ls etc/mock | grep .cfg | grep -v default | egrep -v 'ppc|s390|sparc'); do
MOCKCMD="sudo ./py/mock.py --resultdir=$outdir --uniqueext=$uniqueext -r $(basename $i .cfg) $MOCK_EXTRA_ARGS"
if [ "${i#epel-4-x86_64.cfg}" != "" ]; then
+ header "testing config $(basename $i .cfg)"
time $MOCKCMD --enable-plugin=tmpfs --rebuild $MOCKSRPM
fi
time $MOCKCMD --rebuild $MOCKSRPM
diff --git a/etc/mock/epel-6-i386.cfg b/etc/mock/epel-6-i386.cfg
index 8930b77..bbaad35 100644
--- a/etc/mock/epel-6-i386.cfg
+++ b/etc/mock/epel-6-i386.cfg
@@ -19,11 +19,11 @@ syslog_device=
# repos
[beta]
name=beta
-baseurl=ftp://ftp.redhat.com/redhat/rhel/beta/6/i386/os/
+mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=rhel-5.90Server-beta&arch=i386
[beta-optional]
name=optional
-baseurl=ftp://ftp.redhat.com/redhat/rhel/beta/6/optional/i386/os/
+mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=rhel-optional-5.90Server-beta&arch=i386
[base]
name=BaseOS
diff --git a/etc/mock/epel-6-ppc64.cfg b/etc/mock/epel-6-ppc64.cfg
index 39e83f2..adbfc7d 100644
--- a/etc/mock/epel-6-ppc64.cfg
+++ b/etc/mock/epel-6-ppc64.cfg
@@ -19,11 +19,11 @@ syslog_device=
# repos
[beta]
name=beta
-baseurl=ftp://ftp.redhat.com/redhat/rhel/beta/6/i386/os/
+mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=rhel-5.90Server-beta&arch=ppc64
[beta-optional]
name=optional
-baseurl=ftp://ftp.redhat.com/redhat/rhel/beta/6/optional/i386/os/
+mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=rhel-optional-5.90Server-beta&arch=ppc64
[base]
name=BaseOS
diff --git a/etc/mock/epel-6-x86_64.cfg b/etc/mock/epel-6-x86_64.cfg
index d1ca03b..d00dbb6 100644
--- a/etc/mock/epel-6-x86_64.cfg
+++ b/etc/mock/epel-6-x86_64.cfg
@@ -19,11 +19,11 @@ syslog_device=
# repos
[beta]
name=beta
-baseurl=ftp://ftp.redhat.com/redhat/rhel/beta/6/i386/os/
+mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=rhel-5.90Server-beta&arch=x86_64
[beta-optional]
name=optional
-baseurl=ftp://ftp.redhat.com/redhat/rhel/beta/6/optional/i386/os/
+mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=rhel-optional-5.90Server-beta&arch=x86_64
[base]
name=BaseOS
diff --git a/etc/mock/fedora-10-i386.cfg b/etc/mock/fedora-10-i386.cfg
deleted file mode 100644
index 0d41c47..0000000
--- a/etc/mock/fedora-10-i386.cfg
+++ /dev/null
@@ -1,39 +0,0 @@
-config_opts['root'] = 'fedora-10-i386'
-config_opts['target_arch'] = 'i386'
-config_opts['chroot_setup_cmd'] = 'groupinstall buildsys-build'
-config_opts['dist'] = 'fc10' # only useful for --resultdir variable subst
-
-config_opts['yum.conf'] = """
-[main]
-cachedir=/var/cache/yum
-debuglevel=1
-reposdir=/dev/null
-logfile=/var/log/yum.log
-retries=20
-obsoletes=1
-gpgcheck=0
-assumeyes=1
-syslog_ident=mock
-syslog_device=
-
-# repos
-
-[fedora]
-name=fedora
-mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-10&arch=i386
-failovermethod=priority
-
-[updates-released]
-name=updates
-mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=updates-released-f10&arch=i386
-failovermethod=priority
-
-[local]
-name=local
-baseurl=http://kojipkgs.fedoraproject.org/repos/dist-f10-build/latest/i386/
-cost=2000
-enabled=0
-"""
-
-
-
diff --git a/etc/mock/fedora-10-ppc.cfg b/etc/mock/fedora-10-ppc.cfg
deleted file mode 100644
index 3c39e38..0000000
--- a/etc/mock/fedora-10-ppc.cfg
+++ /dev/null
@@ -1,41 +0,0 @@
-config_opts['root'] = 'fedora-10-ppc'
-config_opts['target_arch'] = 'ppc'
-config_opts['chroot_setup_cmd'] = 'groupinstall buildsys-build'
-config_opts['dist'] = 'fc10' # only useful for --resultdir variable subst
-
-config_opts['yum.conf'] = """
-[main]
-cachedir=/var/cache/yum
-debuglevel=1
-reposdir=/dev/null
-logfile=/var/log/yum.log
-retries=20
-obsoletes=1
-gpgcheck=0
-assumeyes=1
-syslog_ident=mock
-syslog_device=
-#exclude=*.ppc64
-# The above is not needed anymore with yum multilib policy of "best" which is the default in Fedora.
-
-# repos
-
-[fedora]
-name=fedora
-mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-10&arch=ppc
-failovermethod=priority
-
-[updates-released]
-name=updates
-mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=updates-released-f10&arch=ppc
-failovermethod=priority
-
-[local]
-name=local
-baseurl=http://kojipkgs.fedoraproject.org/repos/dist-f10-build/latest/ppc/
-cost=2000
-enabled=0
-"""
-
-
-
diff --git a/etc/mock/fedora-10-ppc64.cfg b/etc/mock/fedora-10-ppc64.cfg
deleted file mode 100644
index 078d79c..0000000
--- a/etc/mock/fedora-10-ppc64.cfg
+++ /dev/null
@@ -1,39 +0,0 @@
-config_opts['root'] = 'fedora-10-ppc64'
-config_opts['target_arch'] = 'ppc64'
-config_opts['chroot_setup_cmd'] = 'groupinstall buildsys-build'
-config_opts['dist'] = 'fc10' # only useful for --resultdir variable subst
-
-config_opts['yum.conf'] = """
-[main]
-cachedir=/var/cache/yum
-debuglevel=1
-reposdir=/dev/null
-logfile=/var/log/yum.log
-retries=20
-obsoletes=1
-gpgcheck=0
-assumeyes=1
-syslog_ident=mock
-syslog_device=
-
-# repos
-
-[fedora]
-name=fedora
-mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-10&arch=ppc64
-failovermethod=priority
-
-[updates-released]
-name=updates
-mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=updates-released-f10&arch=ppc64
-failovermethod=priority
-
-[local]
-name=local
-baseurl=http://kojipkgs.fedoraproject.org/repos/dist-f10-build/latest/ppc64/
-cost=2000
-enabled=0
-"""
-
-
-
diff --git a/etc/mock/fedora-10-s390x.cfg b/etc/mock/fedora-10-s390x.cfg
deleted file mode 100644
index f9017eb..0000000
--- a/etc/mock/fedora-10-s390x.cfg
+++ /dev/null
@@ -1,36 +0,0 @@
-config_opts['root'] = 'fedora-10-s390x'
-config_opts['target_arch'] = 's390x'
-config_opts['chroot_setup_cmd'] = 'groupinstall buildsys-build'
-config_opts['dist'] = 'fc10' # only useful for --resultdir variable subst
-
-config_opts['yum.conf'] = """
-[main]
-cachedir=/var/cache/yum
-debuglevel=1
-reposdir=/dev/null
-logfile=/var/log/yum.log
-retries=20
-obsoletes=1
-gpgcheck=0
-assumeyes=1
-syslog_ident=mock
-syslog_device=
-
-# repos
-
-[fedora]
-name=fedora
-mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-10&arch=s390x
-failovermethod=priority
-
-[updates-released]
-name=updates
-mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=updates-released-f10&arch=s390x
-failovermethod=priority
-
-[local]
-name=local
-baseurl=http://s390.koji.fedoraproject.org/repos/dist-f10-build/latest/s390x/
-cost=2000
-enabled=0
-"""
diff --git a/etc/mock/fedora-10-sparc.cfg b/etc/mock/fedora-10-sparc.cfg
deleted file mode 100644
index b091338..0000000
--- a/etc/mock/fedora-10-sparc.cfg
+++ /dev/null
@@ -1,38 +0,0 @@
-config_opts['root'] = 'fedora-10-sparc'
-config_opts['target_arch'] = 'sparcv9'
-config_opts['chroot_setup_cmd'] = 'groupinstall buildsys-build'
-config_opts['dist'] = 'fc10' # only useful for --resultdir variable subst
-
-config_opts['yum.conf'] = """
-[main]
-cachedir=/var/cache/yum
-debuglevel=1
-reposdir=/dev/null
-logfile=/var/log/yum.log
-retries=20
-obsoletes=1
-gpgcheck=0
-assumeyes=1
-syslog_ident=mock
-syslog_device=
-#exclude=*.sparc64
-# The above is not needed anymore with yum multilib policy of "best" which is the default in Fedora.
-
-# repos
-
-[fedora]
-name=fedora
-mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-10&arch=sparc
-failovermethod=priority
-
-[updates-released]
-name=updates
-mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=updates-released-f10&arch=sparc
-failovermethod=priority
-
-[local]
-name=local
-baseurl=http://sparc.koji.fedoraproject.org/repos/dist-f10-build/latest/sparc/
-cost=2000
-enabled=0
-"""
diff --git a/etc/mock/fedora-10-sparc64.cfg b/etc/mock/fedora-10-sparc64.cfg
deleted file mode 100644
index 1b7df2d..0000000
--- a/etc/mock/fedora-10-sparc64.cfg
+++ /dev/null
@@ -1,36 +0,0 @@
-config_opts['root'] = 'fedora-10-sparc64'
-config_opts['target_arch'] = 'sparc64'
-config_opts['chroot_setup_cmd'] = 'groupinstall buildsys-build'
-config_opts['dist'] = 'fc10' # only useful for --resultdir variable subst
-
-config_opts['yum.conf'] = """
-[main]
-cachedir=/var/cache/yum
-debuglevel=1
-reposdir=/dev/null
-logfile=/var/log/yum.log
-retries=20
-obsoletes=1
-gpgcheck=0
-assumeyes=1
-syslog_ident=mock
-syslog_device=
-
-# repos
-
-[fedora]
-name=fedora
-mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-10&arch=sparc64
-failovermethod=priority
-
-[updates-released]
-name=updates
-mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=updates-released-f10&arch=sparc64
-failovermethod=priority
-
-[local]
-name=local
-baseurl=http://sparc.koji.fedoraproject.org/repos/dist-f10-build/latest/sparc64/
-cost=2000
-enabled=0
-"""
diff --git a/etc/mock/fedora-10-x86_64.cfg b/etc/mock/fedora-10-x86_64.cfg
deleted file mode 100644
index 6b8ac49..0000000
--- a/etc/mock/fedora-10-x86_64.cfg
+++ /dev/null
@@ -1,43 +0,0 @@
-config_opts['root'] = 'fedora-10-x86_64'
-config_opts['target_arch'] = 'x86_64'
-config_opts['chroot_setup_cmd'] = 'groupinstall buildsys-build'
-config_opts['dist'] = 'fc10' # only useful for --resultdir variable subst
-
-config_opts['yum.conf'] = """
-[main]
-cachedir=/var/cache/yum
-debuglevel=1
-reposdir=/dev/null
-logfile=/var/log/yum.log
-retries=20
-obsoletes=1
-gpgcheck=0
-assumeyes=1
-syslog_ident=mock
-syslog_device=
-# grub/syslinux on x86_64 need glibc-devel.i386 which pulls in glibc.i386, need to exclude all
-# .i?86 packages except these.
-#exclude=[0-9A-Za-fh-z]*.i?86 g[0-9A-Za-km-z]*.i?86 gl[0-9A-Za-hj-z]*.i?86 gli[0-9A-Zac-z]*.i?86 glib[0-9A-Za-bd-z]*.i?86
-# The above is not needed anymore with yum multilib policy of "best" which is the default in Fedora.
-
-# repos
-
-[fedora]
-name=fedora
-mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-10&arch=x86_64
-failovermethod=priority
-
-[updates-released]
-name=updates
-mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=updates-released-f10&arch=x86_64
-failovermethod=priority
-
-[local]
-name=local
-baseurl=http://kojipkgs.fedoraproject.org/repos/dist-f10-build/latest/x86_64/
-cost=2000
-enabled=0
-"""
-
-
-
diff --git a/etc/mock/fedora-11-i386.cfg b/etc/mock/fedora-11-i386.cfg
deleted file mode 100644
index 0e6223d..0000000
--- a/etc/mock/fedora-11-i386.cfg
+++ /dev/null
@@ -1,39 +0,0 @@
-config_opts['root'] = 'fedora-11-i386'
-config_opts['target_arch'] = 'i586'
-config_opts['chroot_setup_cmd'] = 'groupinstall buildsys-build'
-config_opts['dist'] = 'fc11' # only useful for --resultdir variable subst
-
-config_opts['yum.conf'] = """
-[main]
-cachedir=/var/cache/yum
-debuglevel=1
-reposdir=/dev/null
-logfile=/var/log/yum.log
-retries=20
-obsoletes=1
-gpgcheck=0
-assumeyes=1
-syslog_ident=mock
-syslog_device=
-
-# repos
-
-[fedora]
-name=fedora
-mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-11&arch=i386
-failovermethod=priority
-
-[updates-released]
-name=updates
-mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=updates-released-f11&arch=i386
-failovermethod=priority
-
-[local]
-name=local
-baseurl=http://kojipkgs.fedoraproject.org/repos/dist-f11-build/latest/i386/
-cost=2000
-enabled=0
-"""
-
-
-
diff --git a/etc/mock/fedora-11-ppc.cfg b/etc/mock/fedora-11-ppc.cfg
deleted file mode 100644
index d5c8727..0000000
--- a/etc/mock/fedora-11-ppc.cfg
+++ /dev/null
@@ -1,41 +0,0 @@
-config_opts['root'] = 'fedora-11-ppc'
-config_opts['target_arch'] = 'ppc'
-config_opts['chroot_setup_cmd'] = 'groupinstall buildsys-build'
-config_opts['dist'] = 'fc11' # only useful for --resultdir variable subst
-
-config_opts['yum.conf'] = """
-[main]
-cachedir=/var/cache/yum
-debuglevel=1
-reposdir=/dev/null
-logfile=/var/log/yum.log
-retries=20
-obsoletes=1
-gpgcheck=0
-assumeyes=1
-syslog_ident=mock
-syslog_device=
-#exclude=*.ppc64
-# The above is not needed anymore with yum multilib policy of "best" which is the default in Fedora.
-
-# repos
-
-[fedora]
-name=fedora
-mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-11&arch=ppc
-failovermethod=priority
-
-[updates-released]
-name=updates
-mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=updates-released-f11&arch=ppc
-failovermethod=priority
-
-[local]
-name=local
-baseurl=http://kojipkgs.fedoraproject.org/repos/dist-f11-build/latest/ppc/
-cost=2000
-enabled=0
-"""
-
-
-
diff --git a/etc/mock/fedora-11-ppc64.cfg b/etc/mock/fedora-11-ppc64.cfg
deleted file mode 100644
index e7f4c8a..0000000
--- a/etc/mock/fedora-11-ppc64.cfg
+++ /dev/null
@@ -1,39 +0,0 @@
-config_opts['root'] = 'fedora-11-ppc64'
-config_opts['target_arch'] = 'ppc64'
-config_opts['chroot_setup_cmd'] = 'groupinstall buildsys-build'
-config_opts['dist'] = 'fc11' # only useful for --resultdir variable subst
-
-config_opts['yum.conf'] = """
-[main]
-cachedir=/var/cache/yum
-debuglevel=1
-reposdir=/dev/null
-logfile=/var/log/yum.log
-retries=20
-obsoletes=1
-gpgcheck=0
-assumeyes=1
-syslog_ident=mock
-syslog_device=
-
-# repos
-
-[fedora]
-name=fedora
-mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-11&arch=ppc64
-failovermethod=priority
-
-[updates-released]
-name=updates
-mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=updates-released-f11&arch=ppc64
-failovermethod=priority
-
-[local]
-name=local
-baseurl=http://kojipkgs.fedoraproject.org/repos/dist-f11-build/latest/ppc64/
-cost=2000
-enabled=0
-"""
-
-
-
diff --git a/etc/mock/fedora-11-s390x.cfg b/etc/mock/fedora-11-s390x.cfg
deleted file mode 100644
index d37fee0..0000000
--- a/etc/mock/fedora-11-s390x.cfg
+++ /dev/null
@@ -1,36 +0,0 @@
-config_opts['root'] = 'fedora-11-s390x'
-config_opts['target_arch'] = 's390x'
-config_opts['chroot_setup_cmd'] = 'groupinstall buildsys-build'
-config_opts['dist'] = 'fc11' # only useful for --resultdir variable subst
-
-config_opts['yum.conf'] = """
-[main]
-cachedir=/var/cache/yum
-debuglevel=1
-reposdir=/dev/null
-logfile=/var/log/yum.log
-retries=20
-obsoletes=1
-gpgcheck=0
-assumeyes=1
-syslog_ident=mock
-syslog_device=
-
-# repos
-
-[fedora]
-name=fedora
-mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-11&arch=s390x
-failovermethod=priority
-
-[updates-released]
-name=updates
-mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=updates-released-f11&arch=s390x
-failovermethod=priority
-
-[local]
-name=local
-baseurl=http://s390.koji.fedoraproject.org/repos/dist-f11-build/latest/s390x/
-cost=2000
-enabled=0
-"""
diff --git a/etc/mock/fedora-11-sparc.cfg b/etc/mock/fedora-11-sparc.cfg
deleted file mode 100644
index e8d6839..0000000
--- a/etc/mock/fedora-11-sparc.cfg
+++ /dev/null
@@ -1,38 +0,0 @@
-config_opts['root'] = 'fedora-11-sparc'
-config_opts['target_arch'] = 'sparcv9'
-config_opts['chroot_setup_cmd'] = 'groupinstall buildsys-build'
-config_opts['dist'] = 'fc11' # only useful for --resultdir variable subst
-
-config_opts['yum.conf'] = """
-[main]
-cachedir=/var/cache/yum
-debuglevel=1
-reposdir=/dev/null
-logfile=/var/log/yum.log
-retries=20
-obsoletes=1
-gpgcheck=0
-assumeyes=1
-syslog_ident=mock
-syslog_device=
-#exclude=*.sparc64
-# The above is not needed anymore with yum multilib policy of "best" which is the default in Fedora.
-
-# repos
-
-[fedora]
-name=fedora
-mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-11&arch=sparc
-failovermethod=priority
-
-[updates-released]
-name=updates
-mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=updates-released-f11&arch=sparc
-failovermethod=priority
-
-[local]
-name=local
-baseurl=http://sparc.koji.fedoraproject.org/repos/dist-f11-build/latest/sparc/
-cost=2000
-enabled=0
-"""
diff --git a/etc/mock/fedora-11-sparc64.cfg b/etc/mock/fedora-11-sparc64.cfg
deleted file mode 100644
index 71e2d1e..0000000
--- a/etc/mock/fedora-11-sparc64.cfg
+++ /dev/null
@@ -1,36 +0,0 @@
-config_opts['root'] = 'fedora-11-sparc64'
-config_opts['target_arch'] = 'sparc64'
-config_opts['chroot_setup_cmd'] = 'groupinstall buildsys-build'
-config_opts['dist'] = 'fc11' # only useful for --resultdir variable subst
-
-config_opts['yum.conf'] = """
-[main]
-cachedir=/var/cache/yum
-debuglevel=1
-reposdir=/dev/null
-logfile=/var/log/yum.log
-retries=20
-obsoletes=1
-gpgcheck=0
-assumeyes=1
-syslog_ident=mock
-syslog_device=
-
-# repos
-
-[fedora]
-name=fedora
-mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-11&arch=sparc64
-failovermethod=priority
-
-[updates-released]
-name=updates
-mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=updates-released-f11&arch=sparc64
-failovermethod=priority
-
-[local]
-name=local
-baseurl=http://sparc.koji.fedoraproject.org/repos/dist-f11-build/latest/sparc64/
-cost=2000
-enabled=0
-"""
diff --git a/etc/mock/fedora-11-x86_64.cfg b/etc/mock/fedora-11-x86_64.cfg
deleted file mode 100644
index c239539..0000000
--- a/etc/mock/fedora-11-x86_64.cfg
+++ /dev/null
@@ -1,43 +0,0 @@
-config_opts['root'] = 'fedora-11-x86_64'
-config_opts['target_arch'] = 'x86_64'
-config_opts['chroot_setup_cmd'] = 'groupinstall buildsys-build'
-config_opts['dist'] = 'fc11' # only useful for --resultdir variable subst
-
-config_opts['yum.conf'] = """
-[main]
-cachedir=/var/cache/yum
-debuglevel=1
-reposdir=/dev/null
-logfile=/var/log/yum.log
-retries=20
-obsoletes=1
-gpgcheck=0
-assumeyes=1
-syslog_ident=mock
-syslog_device=
-# grub/syslinux on x86_64 need glibc-devel.i386 which pulls in glibc.i386, need to exclude all
-# .i?86 packages except these.
-#exclude=[0-9A-Za-fh-z]*.i?86 g[0-9A-Za-km-z]*.i?86 gl[0-9A-Za-hj-z]*.i?86 gli[0-9A-Zac-z]*.i?86 glib[0-9A-Za-bd-z]*.i?86
-# The above is not needed anymore with yum multilib policy of "best" which is the default in Fedora.
-
-# repos
-
-[fedora]
-name=fedora
-mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-11&arch=x86_64
-failovermethod=priority
-
-[updates-released]
-name=updates
-mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=updates-released-f11&arch=x86_64
-failovermethod=priority
-
-[local]
-name=local
-baseurl=http://kojipkgs.fedoraproject.org/repos/dist-f11-build/latest/x86_64/
-cost=2000
-enabled=0
-"""
-
-
-
diff --git a/etc/mock/site-defaults.cfg b/etc/mock/site-defaults.cfg
index 83d2ea7..6dc4d33 100644
--- a/etc/mock/site-defaults.cfg
+++ b/etc/mock/site-defaults.cfg
@@ -5,7 +5,7 @@
# configurations. Options specified in this config file can be overridden in
# the individual mock config files.
#
-# The defaults.cfg delivered by default has NO options set. Only set options
+# The site-defaults.cfg delivered by default has NO options set. Only set options
# here if you want to override the defaults.
#
# Entries in this file follow the same format as other mock config files.
@@ -13,7 +13,7 @@
#############################################################################
#
-# Things that we recommend you set in defaults.cfg:
+# Things that we recommend you set in site-defaults.cfg:
#
# config_opts['basedir'] = '/var/lib/mock/'
# config_opts['cache_topdir'] = '/var/cache/mock'
@@ -53,7 +53,7 @@
#############################################################################
#
# plugin related. Below are the defaults. Change to suit your site
-# policy. defaults.cfg is a good place to do this.
+# policy. site-defaults.cfg is a good place to do this.
#
# NOTE: Some of the caching options can theoretically affect build
# reproducability. Change with care.
@@ -75,7 +75,8 @@
# config_opts['plugin_conf']['bind_mount_opts']['dirs'].append(('/host/path', '/bind/mount/path/in/chroot/' ))
#
# config_opts['plugin_conf']['tmpfs_enable'] = False
-# config_opts['plugin_conf']['tmpfs_opts'] = {'required_ram_mb': 1024}
+# config_opts['plugin_conf']['tmpfs_opts']['required_ram_mb'] = 1024
+# config_opts['plugin_conf']['tmpfs_opts']['max_fs_size'] = '512m'
#############################################################################
#
diff --git a/py/mock.py b/py/mock.py
index 8f58031..dd002de 100755
--- a/py/mock.py
+++ b/py/mock.py
@@ -20,7 +20,7 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
"""
usage:
- mock [options] {--init|--clean}
+ mock [options] {--init|--clean|--scrub=[all,chroot,cache,root-cache,c-cache,yum-cache]}
mock [options] [--rebuild] /path/to/srpm(s)
mock [options] {--shell|--chroot} <cmd>
mock [options] --installdeps {SRPM|RPM}
@@ -64,6 +64,10 @@ import mock.backend
import mock.uid
import mock.util
+def scrub_callback(option, opt, value, parser):
+ parser.values.scrub.append(value)
+ parser.values.mode = "clean"
+
def command_parse(config_opts):
"""return options and args from parsing the command line"""
parser = OptionParser(usage=__doc__, version=__VERSION__)
@@ -85,6 +89,12 @@ def command_parse(config_opts):
parser.add_option("--clean", action="store_const", const="clean",
dest="mode",
help="completely remove the specified chroot")
+ scrub_choices = ('chroot', 'cache', 'root-cache', 'c-cache', 'yum-cache', 'all')
+ scrub_metavar = "[all|chroot|cache|root-cache|c-cache|yum-cache]"
+ parser.add_option("--scrub", action="callback", type="choice", default=[],
+ choices=scrub_choices, metavar=scrub_metavar,
+ callback=scrub_callback,
+ help="completely remove the specified chroot or cache dir or all of the chroot and cache")
parser.add_option("--init", action="store_const", const="init", dest="mode",
help="initialize the chroot, do not build anything")
parser.add_option("--installdeps", action="store_const", const="installdeps",
@@ -161,10 +171,11 @@ def command_parse(config_opts):
" before running command when using --chroot")
parser.add_option("--spec", action="store",
- help="Specifies spec file to use to build an SRPM (used only with --buildsrpm)")
+ help="Specifies spec file to use to build an SRPM (used only with --buildsrpm)")
parser.add_option("--sources", action="store",
- help="Specifies sources to use to build an SRPM (used only with --buildsrpm)")
-
+ help="Specifies sources (either a single file or a directory of files)"
+ "to use to build an SRPM (used only with --buildsrpm)")
+
# verbosity
parser.add_option("-v", "--verbose", action="store_const", const=2,
dest="verbose", default=1, help="verbose build")
@@ -259,7 +270,9 @@ def setup_default_config_opts(config_opts, unprivUid):
# ('/another/host/path', '/another/bind/mount/path/in/chroot/'),
]},
'tmpfs_enable': False,
- 'tmpfs_opts': {'required_ram_mb': 900},
+ 'tmpfs_opts': {
+ 'required_ram_mb': 900,
+ 'max_fs_size': None},
}
# dependent on guest OS
@@ -353,6 +366,28 @@ def set_config_opts_per_cmdline(config_opts, options, args):
config_opts['online'] = options.online
+legal_arches = {
+ 'i386' : ('i386', 'i686'),
+ 'i686' : ('i386', 'i686'),
+ 'x86_64' : ('i386', 'i686', 'x86_64'),
+ 'ppc' : ('ppc'),
+ 'ppc64' : ('ppc', 'ppc64'),
+ 'sparc' : ('sparc'),
+ 'sparc64': ('sparc', 'sparc64'),
+ 's390x' : ('s390x'),
+}
+
+decorate(traceLog())
+def check_arch_combination(target_arch):
+ host_arch = os.uname()[-1]
+ try:
+ if target_arch not in legal_arches[host_arch]:
+ raise mock.exception.InvalidArchitecture(
+ "Cannot build target %s on arch %s" % (target_arch, host_arch))
+ except KeyError:
+ raise mock.exception.InvalidArchitecture(
+ "Unknown target architcture: %s" % target_arch)
+
decorate(traceLog())
def do_rebuild(config_opts, chroot, srpms):
"rebuilds a list of srpms using provided chroot"
@@ -533,6 +568,9 @@ def main(ret):
# cmdline options override config options
set_config_opts_per_cmdline(config_opts, options, args)
+ # verify that we're not trying to build an arch that we can't
+ check_arch_combination(config_opts['rpmbuild_arch'])
+
# default /etc/hosts contents
if not config_opts['use_host_resolv'] and not config_opts['files'].has_key('etc/hosts'):
config_opts['files']['etc/hosts'] = '''
@@ -576,7 +614,10 @@ def main(ret):
chroot.init()
elif options.mode == 'clean':
- chroot.clean()
+ if len(options.scrub) == 0:
+ chroot.clean()
+ else:
+ chroot.scrub(options.scrub)
elif options.mode == 'shell':
chroot.tryLockBuildRoot()
diff --git a/py/mock/backend.py b/py/mock/backend.py
index ca06f59..7aac040 100644
--- a/py/mock/backend.py
+++ b/py/mock/backend.py
@@ -135,6 +135,29 @@ class Root(object):
self.chrootWasCleaned = True
decorate(traceLog())
+ def scrub(self, scrub_opts):
+ """clean out chroot and/or cache dirs with extreme prejudice :)"""
+ self.tryLockBuildRoot()
+ self.state("clean")
+ self._callHooks('clean')
+ for scrub in scrub_opts:
+ if scrub == 'all':
+ mock.util.rmtree(self.basedir)
+ self.chrootWasCleaned = True
+ mock.util.rmtree(self.cachedir)
+ elif scrub == 'chroot':
+ mock.util.rmtree(self.basedir)
+ self.chrootWasCleaned = True
+ elif scrub == 'cache':
+ mock.util.rmtree(self.cachedir)
+ elif scrub == 'c-cache':
+ mock.util.rmtree(os.path.join(self.cachedir, 'ccache'))
+ elif scrub == 'root-cache':
+ mock.util.rmtree(os.path.join(self.cachedir, 'root_cache'))
+ elif scrub == 'yum-cache':
+ mock.util.rmtree(os.path.join(self.cachedir, 'yum_cache'))
+
+ decorate(traceLog())
def tryLockBuildRoot(self):
self.state("lock buildroot")
try:
@@ -282,24 +305,24 @@ class Root(object):
self._mountall()
if self.chrootWasCleaned:
self._yum(self.chroot_setup_cmd, returnOutput=1)
- finally:
- self._umountall()
- # create user
- self._makeBuildUser()
+ # create user
+ self._makeBuildUser()
- # create rpmbuild dir
- self._buildDirSetup()
+ # create rpmbuild dir
+ self._buildDirSetup()
- # set up timezone to match host
- localtimedir = self.makeChrootPath('etc')
- localtimepath = self.makeChrootPath('etc', 'localtime')
- if os.path.exists(localtimepath):
- os.remove(localtimepath)
- shutil.copy2('/etc/localtime', localtimedir)
+ # set up timezone to match host
+ localtimedir = self.makeChrootPath('etc')
+ localtimepath = self.makeChrootPath('etc', 'localtime')
+ if os.path.exists(localtimepath):
+ os.remove(localtimepath)
+ shutil.copy2('/etc/localtime', localtimedir)
- # done with init
- self._callHooks('postinit')
+ # done with init
+ self._callHooks('postinit')
+ finally:
+ self._umountall()
decorate(traceLog())
def _setupDev(self):
@@ -336,6 +359,10 @@ class Root(object):
os.symlink("/proc/self/fd/1", self.makeChrootPath("dev/stdout"))
os.symlink("/proc/self/fd/2", self.makeChrootPath("dev/stderr"))
+ # don't symlink for RHEL4 systems
+ if kver > '2.6.9':
+ os.symlink("/proc/self/fd", self.makeChrootPath("dev/fd"))
+
# symlink it for FC hosts
if kver >= '2.6.19':
os.symlink("/dev/pts/ptmx", self.makeChrootPath("dev/ptmx"))
@@ -515,8 +542,18 @@ class Root(object):
# copy spec/sources
shutil.copy(spec, self.makeChrootPath(self.builddir, "SPECS"))
- os.rmdir(self.makeChrootPath(self.builddir, "SOURCES"))
- shutil.copytree(sources, self.makeChrootPath(self.builddir, "SOURCES"))
+
+ # Resolve any symlinks
+ sources = os.path.realpath(sources)
+
+ if os.path.isdir(sources):
+ os.rmdir(self.makeChrootPath(self.builddir, "SOURCES"))
+ shutil.copytree(sources, self.makeChrootPath(self.builddir, "SOURCES"))
+ else:
+ shutil.copy(sources, self.makeChrootPath(self.builddir, "SOURCES"))
+
+ spec = self.makeChrootPath(self.builddir, "SPECS", os.path.basename(spec))
+ chrootspec = spec.replace(self.makeChrootPath(), '') # get rid of rootdir prefix
spec = self.makeChrootPath(self.builddir, "SPECS", os.path.basename(spec))
chrootspec = spec.replace(self.makeChrootPath(), '') # get rid of rootdir prefix
@@ -589,7 +626,10 @@ class Root(object):
decorate(traceLog())
def _umountall(self):
"""umount all mounted chroot fs."""
- for cmd in self.umountCmds:
+ # Unwind mounts by umounting in the opposite order of the mounts
+ umountCmds = self.umountCmds
+ umountCmds.reverse()
+ for cmd in umountCmds:
self.root_log.debug(cmd)
mock.util.do(cmd, raiseExc=0, shell=True)
diff --git a/py/mock/exception.py b/py/mock/exception.py
index 16fcbff..d28fdf2 100644
--- a/py/mock/exception.py
+++ b/py/mock/exception.py
@@ -78,6 +78,13 @@ class BadCmdline(Error):
self.msg = msg
self.resultcode = 05
+class InvalidArchitecture(Error):
+ "invalid host/target architecture specified."
+ def __init(self, msg):
+ Error.__init__(self, msg)
+ self.msg = msg
+ self.resultcode = 06
+
class ResultDirNotAccessible(Error):
"""
Could not create output directory for built rpms. The directory specified was:
diff --git a/py/mock/plugins/root_cache.py b/py/mock/plugins/root_cache.py
index ffed12e..8bcff23 100644
--- a/py/mock/plugins/root_cache.py
+++ b/py/mock/plugins/root_cache.py
@@ -115,6 +115,9 @@ class RootCache(object):
mock.util.do(
["tar"] + self.compressArgs + ["-cf", self.rootCacheFile,
"-C", self.rootObj.makeChrootPath(),
+ "--exclude=./proc",
+ "--exclude=./sys",
+ "--exclude=./dev",
"."],
shell=False
)
diff --git a/py/mock/plugins/tmpfs.py b/py/mock/plugins/tmpfs.py
index cf89bc1..1708275 100644
--- a/py/mock/plugins/tmpfs.py
+++ b/py/mock/plugins/tmpfs.py
@@ -33,6 +33,11 @@ class Tmpfs(object):
def __init__(self, rootObj, conf):
self.rootObj = rootObj
self.conf = conf
+ self.maxSize = self.conf['max_fs_size']
+ if self.maxSize:
+ self.optArgs = ['-o', 'size=' + self.maxSize]
+ else:
+ self.optArgs = []
rootObj.addHook("preinit", self._tmpfsPreInitHook)
rootObj.addHook("postbuild", self._tmpfsPostBuildHook)
rootObj.addHook("initfailed", self._tmpfsPostBuildHook)
@@ -40,8 +45,8 @@ class Tmpfs(object):
decorate(traceLog())
def _tmpfsPreInitHook(self):
getLog().info("mounting tmpfs.")
- mountCmd = ["mount", "-n", "-t", "tmpfs", "mock_chroot_tmpfs",
- self.rootObj.makeChrootPath()]
+ mountCmd = ["mount", "-n", "-t", "tmpfs"] + self.optArgs + \
+ ["mock_chroot_tmpfs", self.rootObj.makeChrootPath()]
mock.util.do(mountCmd, shell=False)
decorate(traceLog())
diff --git a/py/mock/plugins/yum_cache.py b/py/mock/plugins/yum_cache.py
index e2a7aa3..0ced767 100644
--- a/py/mock/plugins/yum_cache.py
+++ b/py/mock/plugins/yum_cache.py
@@ -89,13 +89,13 @@ class YumCache(object):
os.unlink(fullPath)
continue
- # yum made an rpmdb cache dir in $cachedir/installed for a while;
- # things can go wrong in a specific mock case if this happened.
- # So - just nuke the dir and all that's in it.
- if os.path.exists(self.yumSharedCachePath + '/installed'):
- for fn in glob.glob(self.yumSharedCachePath + '/installed/*'):
- os.unlink(fn)
- os.rmdir(self.yumSharedCachePath + '/installed')
+ # yum made an rpmdb cache dir in $cachedir/installed for a while;
+ # things can go wrong in a specific mock case if this happened.
+ # So - just nuke the dir and all that's in it.
+ if os.path.exists(self.yumSharedCachePath + '/installed'):
+ for fn in glob.glob(self.yumSharedCachePath + '/installed/*'):
+ os.unlink(fn)
+ os.rmdir(self.yumSharedCachePath + '/installed')
self._yumCachePostYumHook()
diff --git a/tests/daemontest.c b/tests/daemontest.c
new file mode 100644
index 0000000..3a31825
--- /dev/null
+++ b/tests/daemontest.c
@@ -0,0 +1,104 @@
+/* test program to test orhphanskill feature
+ * compile it (per below) and put it in /tmp/ of the chroot.
+ * Then:
+ * mock -r CFG chroot /tmp/daemontest
+ *
+ * Expected output:
+ * INFO: mock suid wrapper version 0.8.0
+ * INFO: mock.py version 0.8.0 starting...
+ * State Changed: start
+ * State Changed: init
+ * WARNING: Process ID 12180 still running in chroot. Killing...
+ *
+ */
+
+
+/*
+ * UNIX Daemon Server Programming Sample Program
+ * Levent Karakas <levent at mektup dot at> May 2001
+ *
+ * To compile: cc -o exampled examped.c
+ * To run: ./exampled
+ * To test daemon: ps -ef|grep exampled (or ps -aux on BSD systems)
+ * To test log: tail -f /tmp/exampled.log
+ * To test signal: kill -HUP `cat /tmp/exampled.lock`
+ * To terminate: kill `cat /tmp/exampled.lock`
+ * */
+
+#include <stdio.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+
+#define RUNNING_DIR "/tmp"
+#define LOCK_FILE "exampled.lock"
+#define LOG_FILE "exampled.log"
+
+void log_message(filename,message)
+char *filename;
+char *message;
+{
+FILE *logfile;
+ logfile=fopen(filename,"a");
+ if(!logfile) return;
+ fprintf(logfile,"%s\n",message);
+ fclose(logfile);
+}
+
+void signal_handler(sig)
+int sig;
+{
+ switch(sig) {
+ case SIGHUP:
+ log_message(LOG_FILE,"hangup signal catched");
+ break;
+ case SIGTERM:
+ log_message(LOG_FILE,"terminate signal catched");
+ exit(0);
+ break;
+ }
+}
+
+void daemonize()
+{
+int i,lfp;
+char str[10];
+ if(getppid()==1) return; /* already a daemon */
+ i=fork();
+ if (i<0) exit(1); /* fork error */
+ if (i>0) exit(0); /* parent exits */
+ /* child (daemon) continues */
+ setsid(); /* obtain a new process group */
+ for (i=getdtablesize();i>=0;--i) close(i); /* close all descriptors */
+ i=open("/dev/null",O_RDWR); dup(i); dup(i); /* handle standart I/O */
+ umask(027); /* set newly created file permissions */
+ chdir(RUNNING_DIR); /* change running directory */
+ lfp=open(LOCK_FILE,O_RDWR|O_CREAT,0640);
+ if (lfp<0) exit(1); /* can not open */
+ if (lockf(lfp,F_TLOCK,0)<0) exit(0); /* can not lock */
+ /* first instance continues */
+ sprintf(str,"%d\n",getpid());
+ write(lfp,str,strlen(str)); /* record pid to lockfile */
+ signal(SIGCHLD,SIG_IGN); /* ignore child */
+ signal(SIGTSTP,SIG_IGN); /* ignore tty signals */
+ signal(SIGTTOU,SIG_IGN);
+ signal(SIGTTIN,SIG_IGN);
+ signal(SIGHUP,signal_handler); /* catch hangup signal */
+ signal(SIGTERM,signal_handler); /* catch kill signal */
+}
+
+int main()
+{
+ daemonize();
+ // 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);
+ return 0;
+}
+
+/* EOF */
diff --git a/tests/functions b/tests/functions
new file mode 100644
index 0000000..ca597ac
--- /dev/null
+++ b/tests/functions
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+header() {
+ echo ""
+ echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
+ echo $1
+ echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
+ echo ""
+}
+
+runcmd() {
+ echo $1
+ ret=time sh -c "$1"
+ return $ret
+}
+
diff --git a/tests/runtests.sh b/tests/runtests.sh
new file mode 100755
index 0000000..c4d04bd
--- /dev/null
+++ b/tests/runtests.sh
@@ -0,0 +1,90 @@
+#!/bin/sh
+# vim:tw=0:ts=4:sw=4
+
+# this is a test script to run everything through its paces before you do a
+# release. The basic idea is:
+
+# 1) make distcheck to ensure that all autoconf stuff is setup properly
+# 2) run some basic tests to test different mock options.
+# 3) rebuild mock srpm using this version of mock under all distributed configs
+
+# This test will only run on a machine with full access to internet.
+# might work with http_proxy= env var, but I havent tested that.
+#
+# This test script expects to be run on an x86_64 machine. It will *not* run
+# properly on an i386 machine.
+#
+
+CURDIR=$(pwd)
+
+source ${CURDIR}/tests/functions
+
+MOCKSRPM=${CURDIR}/mock-*.src.rpm
+DIR=$(cd $(dirname $0); pwd)
+TOP_SRCTREE=$DIR/../
+cd $TOP_SRCTREE
+
+#
+# most tests below will use this mock command line
+#
+testConfig=fedora-13-x86_64
+uniqueext="$$-$RANDOM"
+outdir=${CURDIR}/mock-unit-test
+MOCKCMD="sudo ./py/mock.py --resultdir=$outdir --uniqueext=$uniqueext -r $testConfig $MOCK_EXTRA_ARGS"
+CHROOT=/var/lib/mock/${testConfig}-$uniqueext/root
+
+trap '$MOCKCMD --clean; exit 1' INT HUP QUIT EXIT TERM
+
+export CURDIR MOCKSRPM DIR TOP_SRCTREE testConfig uniqueext outdir MOCKCMD CHROOT
+
+# clear out root cache so we get at least run without root cache present
+#sudo rm -rf /var/lib/mock/cache/${testConfig}/root_cache
+
+#
+# pre-populate yum cache for the rest of the commands below
+#
+header "pre-populating the cache"
+runcmd "$MOCKCMD --init"
+runcmd "$MOCKCMD --installdeps $MOCKSRPM"
+if [ ! -e $CHROOT/usr/include/python* ]; then
+ echo "installdeps test FAILED. could not find /usr/include/python*"
+ exit 1
+fi
+
+fails=0
+
+#
+# run regression tests
+#
+for i in ${CURDIR}/tests/*.tst; do
+ sh $i
+ if [ $? != 0 ]; then
+ fails=$(($fails + 1))
+ echo "**************** %i failed"
+ fi
+done
+
+printf "%d regression failures\n" $fails
+
+#
+# clean up
+#
+header "clean up from first round of tests"
+runcmd "$MOCKCMD --offline --clean"
+
+#
+# Test build all configs we ship.
+#
+for i in $(ls etc/mock | grep .cfg | grep -v default | egrep -v 'ppc|s390|sparc'); do
+ MOCKCMD="sudo ./py/mock.py --resultdir=$outdir --uniqueext=$uniqueext -r $(basename $i .cfg) $MOCK_EXTRA_ARGS"
+ if [ "${i#epel-4-x86_64.cfg}" != "" ]; then
+ header "testing config $(basename $i .cfg) with tmpfs plugin"
+ runcmd "$MOCKCMD --enable-plugin=tmpfs --rebuild $MOCKSRPM "
+ if [ $? != 0 ]; then fails=$(($fails+1)); fi
+ fi
+ header "testing config $(basename $i .cfg) *without* tmpfs plugin"
+ runcmd "$MOCKCMD --rebuild $MOCKSRPM"
+ if [ $? != 0 ]; then fails=$(($fails+1)); fi
+done
+
+printf "%d total failures\n" $fails
diff --git a/tests/test1.tst b/tests/test1.tst
new file mode 100644
index 0000000..0eb547d
--- /dev/null
+++ b/tests/test1.tst
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+source ${CURDIR}/tests/functions
+
+#
+# Test that chroot return code is properly passed up
+#
+
+header "testing that chroot return code is passed back correctly"
+runcmd "$MOCKCMD --offline --chroot -- bash -c 'exit 5'"
+res=$?
+if [ $res -ne 5 ]; then
+ echo "'mock --chroot' return code not properly passed back: $res"
+ exit 1
+fi
diff --git a/tests/test2.tst b/tests/test2.tst
new file mode 100644
index 0000000..0b68af6
--- /dev/null
+++ b/tests/test2.tst
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+source ${CURDIR}/tests/functions
+
+#
+# test mock shell (interactive) and return code passing
+#
+header "testing interactive shell and return code"
+echo exit 5 | runcmd "$MOCKCMD --offline --shell"
+res=$?
+if [ $res -ne 5 ]; then
+ echo "'mock --chroot' return code not properly passed back: $res"
+ exit 1
+fi
diff --git a/tests/test3.tst b/tests/test3.tst
new file mode 100644
index 0000000..20ecce1
--- /dev/null
+++ b/tests/test3.tst
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+source ${CURDIR}/tests/functions
+
+#
+# Test that chroot with one arg is getting passed though a shell (via os.system())
+#
+header "testing that args are passed correctly to a shell"
+runcmd "$MOCKCMD --offline --chroot 'touch /tmp/{foo,bar,baz}'"
+if [ ! -f $CHROOT/tmp/foo ] || [ ! -f $CHROOT/tmp/bar ] || [ ! -f $CHROOT/tmp/baz ]; then
+ echo "'mock --chroot' with one argument is not being passed to os.system()"
+ exit 1
+fi
+
diff --git a/tests/test4.tst b/tests/test4.tst
new file mode 100644
index 0000000..c72bdf0
--- /dev/null
+++ b/tests/test4.tst
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+source ${CURDIR}/tests/functions
+
+#
+# Test that chroot with more than one arg is not getting passed through a shell
+#
+header "Test that chroot with more than one arg is not getting passed through a shell"
+runcmd "$MOCKCMD --offline --chroot touch '/tmp/{quux,wibble}'"
+if [ ! -f $CHROOT/tmp/\{quux,wibble\} ] || [ -f $CHROOT/tmp/quux ] || [ -f $CHROOT/tmp/wibble ]; then
+ echo "'mock --chroot' with more than one argument is being passed to os.system()"
+ exit 1
+fi
+
diff --git a/tests/test5.tst b/tests/test5.tst
new file mode 100644
index 0000000..0724d01
--- /dev/null
+++ b/tests/test5.tst
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+source ${CURDIR}/tests/functions
+
+#
+# Test offline build as well as tmpfs
+#
+header "Test offline build as well as tmpfs"
+runcmd "$MOCKCMD --offline --enable-plugin=tmpfs --rebuild $MOCKSRPM"
+if [ ! -e $outdir/mock-*.noarch.rpm ]; then
+ echo "rebuild test FAILED. could not find $outdir/mock-*.noarch.rpm"
+ exit 1
+fi
+
diff --git a/tests/test6.tst b/tests/test6.tst
new file mode 100644
index 0000000..9c116e3
--- /dev/null
+++ b/tests/test6.tst
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+source ${CURDIR}/tests/functions
+
+#
+# Test orphanskill feature (std)
+#
+header "Test orphanskill feature (std)"
+if pgrep daemontest; then
+ echo "Exiting because there is already a daemontest running."
+ exit 1
+fi
+runcmd "$MOCKCMD --offline --init"
+runcmd "$MOCKCMD --offline --copyin tests/daemontest.c /tmp"
+runcmd "$MOCKCMD --offline --chroot -- gcc -Wall -o /tmp/daemontest /tmp/daemontest.c"
+runcmd "$MOCKCMD --offline --chroot -- /tmp/daemontest"
+if pgrep daemontest; then
+ echo "Daemontest FAILED. found a daemontest process running after exit."
+ exit 1
+fi
+
diff --git a/tests/test7.tst b/tests/test7.tst
new file mode 100644
index 0000000..7dab5fc
--- /dev/null
+++ b/tests/test7.tst
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+source ${CURDIR}/tests/functions
+
+#
+# Test orphanskill feature (explicit)
+#
+header "Test orphanskill feature (explicit)"
+runcmd "$MOCKCMD --offline --init"
+runcmd "$MOCKCMD --offline --copyin tests/daemontest.c /tmp"
+runcmd "$MOCKCMD --offline --chroot -- gcc -Wall -o /tmp/daemontest /tmp/daemontest.c"
+echo -e "#!/bin/sh\n/tmp/daemontest\nsleep 60\n" >> $CHROOT/tmp/try
+# the following should launch about three processes in the chroot: bash, sleep, daemontest
+$MOCKCMD --offline --chroot -- bash /tmp/try &
+mockpid=$!
+sleep 1
+# now we 'prematurely' kill mock. This should leave the three orphans above
+sudo kill -9 $mockpid
+if ! pgrep daemontest; then
+ echo "Daemontest failed. daemontest should be running now but is not."
+ exit 1
+fi
+$MOCKCMD --offline --orphanskill
+if pgrep daemontest; then
+ echo "Daemontest FAILED. found a daemontest process running after exit."
+ exit 1
+fi
diff --git a/tests/test8.tst b/tests/test8.tst
new file mode 100644
index 0000000..dd91ee7
--- /dev/null
+++ b/tests/test8.tst
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+source ${CURDIR}/tests/functions
+
+#
+# test init/clean
+#
+header "test init/clean"
+runcmd "$MOCKCMD --offline --clean"
+if [ -e $CHROOT ]; then
+ echo "clean test FAILED. still found $CHROOT dir."
+ exit 1
+fi
+
+runcmd "$MOCKCMD --offline --init"
+runcmd "$MOCKCMD --offline --install ccache"
+if [ ! -e $CHROOT/usr/bin/ccache ]; then
+ echo "init/clean test FAILED. ccache not found."
+ exit 1
+fi
+
diff --git a/tests/test9.tst b/tests/test9.tst
new file mode 100644
index 0000000..1a5ed6e
--- /dev/null
+++ b/tests/test9.tst
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+source ${CURDIR}/tests/functions
+
+#
+# test old-style cmdline options
+#
+header "test old-style cmdline options"
+runcmd "$MOCKCMD --offline clean"
+runcmd "$MOCKCMD --offline init"
+runcmd "$MOCKCMD --offline install ccache"
+if [ ! -e $CHROOT/usr/bin/ccache ]; then
+ echo "init/clean test FAILED. ccache not found."
+ exit 1
+fi
+