Changé fonction rcmd pour régler bug avec fpkg
[hvlinux.git] / functions
index 2ccd965..8052648 100644 (file)
--- a/functions
+++ b/functions
@@ -841,7 +841,7 @@ ipkg()
 
     # Checking if package was previously successfully installed
     if grep "^${HVLABEL} successfully installed" ${LFS_LOG_FILE} \
-      1> /dev/null 2>&1; then
+        1> /dev/null 2>&1; then
        return $EXIT_SUCCESS
     fi
     
@@ -962,6 +962,33 @@ rscr()
     return $EXIT_SUCCESS
 }
 
+rcmd_trap_setup()
+{
+    exec 6>&1 # Save current "value" of stdout.
+    trap rcmd_trap_handler INT TERM EXIT ERR
+}
+
+rcmd_trap_end()
+{
+    trap - INT TERM EXIT ERR
+
+    # We do not restore global trap
+}
+
+rcmd_trap_handler()
+{
+    exec 1>&6 6>&- # Restore stdout to fd #6, where it had been saved,
+                   # and close file descriptor #6.
+    print_status failure
+
+    rcmd_trap_end
+    if [ -n "${RCMD_NO_EXIT}" ]; then
+        return ${EXIT_FAILURE}
+    else
+        exit ${EXIT_FAILURE}
+    fi
+}
+
 # Run command, no log
 # First  argument: Message to display during script
 # Second argument: command + arguments
@@ -982,12 +1009,14 @@ rcmd()
 
     display_checkbox_msg ${MSGSTRING}
 
+    rcmd_trap_setup
+
     echo ${CMD_WITH_ARGS} 1>> ${LFS_LOG_FILE}
 
     # Executing command
     ${CMD_WITH_ARGS} 1>> ${LFS_LOG_FILE} 2>&1
+
     if [ $? -ne 0 ]; then
-       print_status failure
         if [ -n "${RCMD_NO_EXIT}" ]; then
             return ${EXIT_FAILURE}
         else
@@ -998,6 +1027,8 @@ rcmd()
     # Displaying build time after the package name
     print_status success
 
+    rcmd_trap_end
+
     return $EXIT_SUCCESS
 }