User info about runscript and archscript. Added checks for processes running i
authorEric Edgar <rocket@gentoo.org>
Tue, 3 May 2005 14:58:51 +0000 (14:58 +0000)
committerEric Edgar <rocket@gentoo.org>
Tue, 3 May 2005 14:58:51 +0000 (14:58 +0000)
n the chroot and created a script to kill them. Should fix the unmounting issues with gconfd or any other running application in the chroot

git-svn-id: svn+ssh://svn.gentoo.org/var/svnroot/catalyst/trunk@645 d1e1f19c-881f-0410-ab34-b69fee027534

ChangeLog
catalyst
modules/generic_stage_target.py
modules/livecd_stage2_target.py
targets/support/kill-chroot-pids.sh [new file with mode: 0755]

index 5f071407f44a850311ab5aade342543439600c64..c5f1ff215b36f4fcba806c52b2a1c4b0fd69aa8c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 # Copyright 2002-2005 Gentoo Foundation; Distributed under the GPL v2
-# $Header: /var/cvsroot/gentoo/src/catalyst/ChangeLog,v 1.254 2005/04/29 21:31:32 rocket Exp $
+# $Header: /var/cvsroot/gentoo/src/catalyst/ChangeLog,v 1.255 2005/05/03 14:58:51 rocket Exp $
+
+  03 May 2005; Eric Edgar <rocket@gentoo.org> catalyst,
+  modules/generic_stage_target.py, modules/livecd_stage2_target.py,
+  +targets/support/kill-chroot-pids.sh:
+  User info about runscript and archscript. Added checks for processes running
+  in the chroot and created a script to kill them. Should fix the unmounting
+  issues with gconfd or any other running application in the chroot
 
   29 Apr 2005; Eric Edgar <rocket@gentoo.org>
   targets/stage1/stage1-chroot.sh, targets/stage1/stage1-preclean-chroot.sh:
index 851502df2f31159ac5e1ea2b6d6f184484b9665c..1c2112356ec14e810f4d5792e21de60b6c1e75d9 100755 (executable)
--- a/catalyst
+++ b/catalyst
@@ -1,7 +1,7 @@
 #!/usr/bin/python
 # Copyright 1999-2004 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo/src/catalyst/catalyst,v 1.77 2005/04/27 21:04:02 rocket Exp $
+# $Header: /var/cvsroot/gentoo/src/catalyst/catalyst,v 1.78 2005/05/03 14:58:52 rocket Exp $
 
 # Maintained in full by:
 # Eric Edgar <rocket@gentoo.org>
@@ -182,7 +182,11 @@ def build_target(addlargs, targetmap):
                        raise CatalystError,"Target \""+addlargs["target"]+"\" not available."
                
                mytarget=targetmap[addlargs["target"]](conf_values, addlargs)
-               
+       
+               # Kill any pids in the chroot 
+               print "Checking for processes running in chroot and killing them."
+               mytarget.kill_chroot_pids()
+
                # Check for mounts right away and abort if we cannot unmount them.
                mytarget.mount_safety_check()
 
index cc566898123018878cb04245ee27d4d6dceb33d4..2086f2e0eb4509a933da6e12c84a1ebb401ac1dc 100644 (file)
@@ -1,6 +1,6 @@
 # Copyright 1999-2004 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo/src/catalyst/modules/generic_stage_target.py,v 1.44 2005/04/28 16:45:43 rocket Exp $
+# $Header: /var/cvsroot/gentoo/src/catalyst/modules/generic_stage_target.py,v 1.45 2005/05/03 14:58:52 rocket Exp $
 
 """
 This class does all of the chroot setup, copying of files, etc. It is
@@ -120,6 +120,8 @@ class generic_stage_target(generic_target):
                self.set_iso_volume_id()
                self.set_build_kernel_vars(addlargs)    
                self.set_fsscript()
+               self.set_archscript()
+               self.set_runscript()
                self.set_install_mask()
                self.set_rcadd()
                self.set_rcdel()
@@ -219,7 +221,15 @@ class generic_stage_target(generic_target):
                
                        if not os.path.exists(self.settings["storedir"]+"/builds/"):
                                os.makedirs(self.settings["storedir"]+"/builds/")
-       
+       def set_archscript(self):
+           if self.settings.has_key(self.settings["spec_prefix"]+"/archscript"):
+               print "\nWarning!!!  "
+               print "\t"+self.settings["spec_prefix"]+"/archscript" + " is deprecated and no longer used.\n"
+       def set_runscript(self):
+           if self.settings.has_key(self.settings["spec_prefix"]+"/runscript"):
+               print "\nWarning!!!  "
+               print "\t"+self.settings["spec_prefix"]+"/runscript" + " is deprecated and no longer used.\n"
+
        def set_fsscript(self): 
                if self.settings.has_key(self.settings["spec_prefix"]+"/fsscript"):
                        self.settings["fsscript"]=self.settings[self.settings["spec_prefix"]+"/fsscript"]
@@ -380,6 +390,13 @@ class generic_stage_target(generic_target):
            if self.settings.has_key(self.settings["spec_prefix"]+"/gk_mainargs"):
                self.settings["gk_mainargs"]=self.settings[self.settings["spec_prefix"]+"/gk_mainargs"]
                del self.settings[self.settings["spec_prefix"]+"/gk_mainargs"]
+
+       def kill_chroot_pids(self):
+           # Force environment variables to be exported so script can see them
+           self.setup_environment()
+
+           if os.path.exists(self.settings["sharedir"]+"/targets/support/kill-chroot-pids.sh"):
+                           cmd("/bin/bash "+self.settings["sharedir"]+"/targets/support/kill-chroot-pids.sh","kill-chroot-pids script failed.")
        
        def mount_safety_check(self):
                mypath=self.settings["chroot_path"]
@@ -391,7 +408,7 @@ class generic_stage_target(generic_target):
                """
                if not os.path.exists(mypath):
                        return
-                       
+               
                for x in self.mounts:
                        if not os.path.exists(mypath+x):
                                continue
@@ -519,8 +536,8 @@ class generic_stage_target(generic_target):
                for x in self.settings["portage_overlay"]: 
                        if os.path.exists(x):
                                print "Copying overlay dir " +x
-                               cmd("mkdir -p "+self.settings["chroot_path"]+x)
-                               cmd("cp -R "+x+"/* "+self.settings["chroot_path"]+x)
+                               cmd("mkdir -p "+self.settings["chroot_path"]+x,"Could not make portage_overlay dir")
+                               cmd("cp -R "+x+"/* "+self.settings["chroot_path"]+x,"Could not copy portage_overlay")
        
        def root_overlay(self):
            # copy over the root_overlay
@@ -561,9 +578,16 @@ class generic_stage_target(generic_target):
                        retval=os.system("umount "+mypath+x)
                        
                        if retval!=0:
-                               ouch=1
-                               warn("Couldn't umount bind mount: "+mypath+x)
-                               # keep trying to umount the others, to minimize damage if developer makes a mistake
+                               warn("First attempt to unmount: "+mypath+x+" failed.")
+                               warn("Killing any pids still running in the chroot")
+                               
+                               self.kill_chroot_pids()
+                               
+                               retval2=os.system("umount "+mypath+x)
+                               if retval2!=0:
+                                   ouch=1
+                                   warn("Couldn't umount bind mount: "+mypath+x)
+                                   # keep trying to umount the others, to minimize damage if developer makes a mistake
                
                if ouch:
                        """
@@ -601,7 +625,7 @@ class generic_stage_target(generic_target):
                    self.override_cflags()
                    self.override_cxxflags()    
                    # modify and write out make.conf (for the chroot)
-                   cmd("rm -f "+self.settings["chroot_path"]+"/etc/make.conf")
+                   cmd("rm -f "+self.settings["chroot_path"]+"/etc/make.conf","Could not remove "+self.settings["chroot_path"]+"/etc/make.conf")
                    myf=open(self.settings["chroot_path"]+"/etc/make.conf","w")
                    myf.write("# These settings were set by the catalyst build script that automatically built this stage\n")
                    myf.write("# Please consult /etc/make.conf.example for a more detailed example\n")
@@ -863,7 +887,7 @@ class generic_stage_target(generic_target):
                                mypack=list_bashify(self.settings[self.settings["spec_prefix"]+"/packages"])
                                try:
                                        cmd("/bin/bash "+self.settings["controller_file"]+\
-                                               " build_packages "+mypack)
+                                               " build_packages "+mypack,"Error in attempt to build packages")
                                        touch(self.settings["autoresume_path"]+"build_packages")
                                except CatalystError:
                                        self.unbind()
index 470fa6fe7798bc8edc39f9abe9fbae60153b1a9d..1eb088285aaa248cb2ed38f4387c94e84e162552 100644 (file)
@@ -1,6 +1,6 @@
 # Copyright 1999-2004 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo/src/catalyst/modules/livecd_stage2_target.py,v 1.41 2005/04/29 13:51:39 rocket Exp $
+# $Header: /var/cvsroot/gentoo/src/catalyst/modules/livecd_stage2_target.py,v 1.42 2005/05/03 14:58:52 rocket Exp $
 
 """
 Builder class for a LiveCD stage2 build.
@@ -25,12 +25,11 @@ class livecd_stage2_target(generic_stage_target):
                        "gamecd/conf","livecd/users","portage_overlay","livecd/cdfstype"])
                
                generic_stage_target.__init__(self,spec,addlargs)
-       
                if not self.settings.has_key("livecd/type"):
                    self.settings["livecd/type"] = "generic-livecd"
 
                file_locate(self.settings, ["cdtar","controller_file"])
-               
+       
        def set_source_path(self):
            self.settings["source_path"]=self.settings["storedir"]+"/builds/"+self.settings["source_subpath"]+".tar.bz2"
            if os.path.isfile(self.settings["source_path"]):
diff --git a/targets/support/kill-chroot-pids.sh b/targets/support/kill-chroot-pids.sh
new file mode 100755 (executable)
index 0000000..f6c0be0
--- /dev/null
@@ -0,0 +1,59 @@
+#!/bin/bash
+# Script to kill processes found running in the chroot.
+
+if [ "${clst_chroot_path}" == "/" ]
+then
+    echo "Aborting .... clst_chroot_path is set to /"
+    echo "This is very dangerous"
+    exit 1
+fi
+
+if [ "${clst_chroot_path}" == "" ]
+then
+    echo "Aborting .... clst_chroot_path is NOT set"
+    echo "This is very dangerous"
+    exit 1
+fi
+
+j=0
+declare -a pids
+# get files and dirs in /proc
+for i in `ls /proc`
+do
+    # Test for directories
+    if [ -d /proc/$i ]
+    then
+       # Search for exe containing string inside ${clst_chroot_path}
+       P_NAME=$(ls -la --color=never /proc/$i 2>&1 |grep exe|grep ${clst_chroot_path}|awk '{print $11}')
+       ls -la --color=never /proc/$i 2>&1 |grep exe|grep ${clst_chroot_path} > /dev/null
+
+       # If found
+       if [ $? == 0 ]
+       then
+           # Assign the pid into the pids array
+           pids[$j]=$i
+           j=$(($j+1))
+       fi
+    fi
+done
+
+if [ ${j} -gt 0 ]
+then
+    echo
+    echo "Killing process(es)"
+    echo "pid: process name"
+    for pid in ${pids[@]} 
+    do 
+           P_NAME=$(ls -la --color=never /proc/${pid} 2>&1 |grep exe|grep ${clst_chroot_path}|awk '{print $11}')
+           echo ${pid}: ${P_NAME}
+    done
+    echo 
+    echo "Press Ctrl-C within 10 seconds to abort"
+    
+    sleep 10
+
+    for pid in ${pids[@]} 
+    do
+           kill -9 ${pid}
+    done
+fi