Package: pbuilder
Version: 0.176
Severity: wishlist
Tags: patch

--- Please enter the report below this line. ---

Hi,

we need a feature to kill the build if the free disk (or memory) space is 
running low.
I am attaching a preliminary patch, that implements this feature, it applies 
cleanly
against the pbuilder in unstable (and also against the git version).

Documentation needs to be written, but before I do so, I wanted to check if 
you'd accept such a patch at all. What do you think about it?

If you like it, I'll polish it some more, include documentation and send a new 
patch.
If you don't like it - what is the right way to get this feature in pbuilder?

Thanks,
Ondrej

--- System information. ---
Architecture: i386
Kernel:       Linux 2.6.21-1-686

Debian Release: lenny/sid
  500 unstable        ftp.cz.debian.org 

--- Package information. ---
Depends             (Version) | Installed
=============================-+-=============
cdebootstrap                  | 0.4.3
 OR debootstrap               | 1.0.7
coreutils        (>= 4.5.8-1) | 5.97-5.5
debianutils       (>= 1.13.1) | 2.28
gcc                           | 4:4.2.1-6
wget                          | 1.10.2-3

diff -r f440f896c1a3 -r 0b0efbd08687 pbuilder-buildpackage
--- a/pbuilder-buildpackage	Thu Nov 29 18:36:41 2007 +0100
+++ b/pbuilder-buildpackage	Fri Nov 30 17:56:02 2007 +0100
@@ -138,6 +138,33 @@ else
     KILL_WAIT_PID=""
 fi
 
+check_size()
+{
+    size_ok=0
+    #disk
+    size=`df $dir| tail -n 1|awk '{print $4}'`
+    if [ "$size" -lt "$dir_min_free" ]
+    then
+        return
+    fi
+    #memory
+    size=`free |tail -n 2 | head -n 1 | awk '{print $4}'`
+    if [ "$size" -lt "$mem_min_free" ]
+    then
+        return
+    fi
+    size_ok=1
+}
+
+while [ `ps -p ${BUILD_PID} -o comm= | wc -l` -ne "0" ]; do
+    check_size
+    if [ "$size_ok" -eq "0" ]
+    then
+        kill "${BUILD_PID}" || true; echo "  -> Terminate process (out of memory/disk)";
+    fi
+    sleep 1
+done
+
 if ! wait ${BUILD_PID}; then
     trap umountproc_cleanbuildplace_trap exit sighup
     eval "${KILL_WAIT_PID}"
diff -r f440f896c1a3 -r 0b0efbd08687 pbuilder-checkparams
--- a/pbuilder-checkparams	Thu Nov 29 18:36:41 2007 +0100
+++ b/pbuilder-checkparams	Fri Nov 30 17:56:02 2007 +0100
@@ -37,6 +37,12 @@ AUTOCLEANAPTCACHE=
 AUTOCLEANAPTCACHE=
 #option for user-mode-linux only.
 IGNORE_UMOUNT=""
+
+dir=/var
+#in kbytes:
+dir_min_free=80000000
+mem_min_free=800
+
 
 while [ -n "$1" ]; do 
     case "$1" in 
@@ -216,6 +222,18 @@ while [ -n "$1" ]; do
 	    IGNORE_UMOUNT="no"
 	    shift; 
 	    ;;
+	--disk-dir)
+	    disk_dir="$2";
+	    shift; shift;
+	    ;;
+	--disk-min-free)
+	    dir_min_free="$2";
+	    shift; shift;
+	    ;;
+	--mem-min-free)
+	    mem_min_free="$2";
+	    shift; shift;
+	    ;;
 	--) # end of processing for this
 	    shift;
 	    break;

Reply via email to