Whamcloud - gitweb
Try to avoid a race where two rpmbuilds on the same node are trying to stage
[fs/lustre-release.git] / build / lmake
index a1e07b8..4aa15d2 100755 (executable)
@@ -10,6 +10,7 @@ TARGET_ARCH=
 TARGET_CONFIG=
 JOBS=1
 CONFIGURE_FLAGS=
+TMPDIR=${TMPDIR:-"/var/tmp"}
 
 # commands to run
 BUILD_LUSTRE=0
@@ -341,6 +342,30 @@ set_make()
     MAKE_J="$MAKE -j $JOBS"
 }
 
+timed_run() {
+    SLEEP_TIME=$1
+    shift
+
+    set -o monitor
+
+    #bash -c "$@" &
+    ("$@") &
+    child_pid=$!
+    
+    (sleep $SLEEP_TIME
+    kill -TERM -$child_pid 2>/dev/null
+    sleep 5
+    kill -KILL -$child_pid 2>/dev/null
+    echo "$1 was killed due to timeout") &
+    dog_pid=$!
+
+    wait $child_pid
+    # status will be set to 143 if the process had to be killed due to timeout
+    status=${PIPESTATUS[0]}
+    kill -KILL -$dog_pid
+    return $status
+}
+
 depend_kernel()
 {
     (( $DEPEND_KERNEL )) || return 0
@@ -354,31 +379,61 @@ depend_kernel()
     $MAKE "$MAKE_CC" mrproper || fatal 1 "Error running make mrproper"
     rm -f rpm-release
     cp "$CONFIG_FILE" .config
-    # find the right file to grep in for the target
-    for makefile in scripts/kconfig/Makefile Makefile; do
-        if [ -f $makefile ]; then
-           break
-       fi
-    done
-    for oc in nonint_oldconfig silentoldconfig oldconfig ; do
-       if grep -q "^$oc:" $makefile ; then
-           $MAKE "$MAKE_CC" $oc || fatal 1 "Error running make oldconfig ($oc)"
-           break
-       fi
+    local UPDATE_OLDCONFIG=
+    for oc in oldconfig_nonint silentoldconfig oldconfig ; do                   
+        if grep -q "$oc" Makefile ; then                                        
+            timed_run 300 $MAKE "$MAKE_CC" $oc || UPDATE_OLDCONFIG=1
+            break
+        fi
     done
-    # now notify if resulting .config is different than $CONFIG_FILE
-    if ! cmp "$CONFIG_FILE" .config; then
-        { cat <<EOF
-The result of a make $oc on file $CONFIG_FILE resulted in a difference when
-compared to $CONFIG_FILE in the following way:
+
+    if [ "$UPDATE_OLDCONFIG" ] ; then
+        # use the expect script to "make oldconfig" and answer the questions for
+        # new items conservatively.  QA will get notified on anything newly added
+        # for them to review and adjust accordingly.
+        local logfile=$(mktemp /tmp/XXXXXX)
+        #timed_run 300 $TOPDIR/build/update_oldconfig $logfile
+        #local RC=${PIPESTATUS[0]}
+        #local RC=$(strace -f -o update_oldconfig.strace bash -c "$TOPDIR/build/update_oldconfig $logfile; echo \$?")
+        $TOPDIR/build/update_oldconfig $logfile
+        local RC=${PIPESTATUS[0]}
+        #$TOPDIR/build/update_oldconfig $logfile
+        #local RC=${PIPESTATUS[0]}
+        if [ $RC -eq 143 ]; then
+            fatal 1 "update_oldconfig timed out"
+        elif [ $RC -ne 0 ]; then
+           # dump the log
+            cat $logfile
+            rm -f $logfile
+           if [ -f update_oldconfig.strace ]; then
+               cat update_oldconfig.strace
+               rm -f update_oldconfig.strace
+            fi
+            fatal 1 "update_oldconfig failed: $RC. See log above."
+        fi
+        rm -f $logfile
+        # now notify if resulting .config is different than $CONFIG_FILE
+        local tmpfile=$(mktemp /tmp/XXXXXX)
+        diff -I '^#.*' -u "$CONFIG_FILE" .config >$tmpfile
+        if [ -s $tmpfile ]; then
+            { cat <<EOF
+To: qa@lists.clusterfs.com
+Subject: kernel_config change 
+
+The result of a make oldconfig on file $CONFIG_FILE resulted in a
+difference when compared to .config in the following way:
 
 EOF
-        diff -ur "$CONFIG_FILE" .config
-        echo "Please consider updating $CONFIG_FILE."
-       echo -e "\nThe entire new .config file:\n"
-        cat .config
-        } | mail -s "kernel_config change" qa@lists.clusterfs.com
+            cat $tmpfile
+            echo -e "\n\nPlease consider updating $CONFIG_FILE."
+           # not sure these are entirely useful.  the above and "patch" are good
+           #echo -e "\nThe entire new .config file:\n"
+            #cat .config
+            } | sendmail -fqa@clusterfs.com -t
+        fi
+        rm -f $tmpfile
     fi
+
     case "$VERSION" in
        2.6*)
             $MAKE "$MAKE_CC" include/asm
@@ -438,6 +493,7 @@ build_lustre()
        < build/lustre.spec.in \
        > build/lustre.spec
     $RPMBUILD --target ${TARGET_ARCH} -bb build/lustre.spec \
+        --define "_tmpdir $TMPDIR" \
        --define "_topdir $(lbuild_topdir)" || \
        fatal 1 "Error building Lustre rpms."
     # $MAKE_J "$MAKE_CC" || fatal 1 "Error building Lustre."
@@ -540,7 +596,7 @@ build_kms()
     mkdir -p "${TOPDIR}/modules-${FULL_VERSION}"
     for dir in /usr/src/kernel-modules/* ; do
        # we are replacing lustre-lite, so don't include it
-       if [ ${dir##*/} != "lustre-lite" -a -e $dir/Makefile ]; then
+       if [ "${dir##*/}" != "lustre-lite" -a -e $dir/Makefile ]; then
            build_dir="${TOPDIR}/modules-${FULL_VERSION}/${dir##*/}"
            cp -a $dir $build_dir
            # these modules are terrible, and don't all build