[kexec-tools/f19] mkdumprd: check return value of subshell

Baoquan He baoquan at fedoraproject.org
Mon Jul 15 09:33:19 UTC 2013


commit 9fa104e73abcb860ee5cacc06a47cf1f5bd5634a
Author: WANG Chao <chaowang at redhat.com>
Date:   Wed Jun 26 17:52:40 2013 +0800

    mkdumprd: check return value of subshell
    
    Currently some functions are used in subshell to assign string to a
    variable. For example:
     _mnt=$(to_mount "$1")
    
    In this case if we call perror_exit in the subshell, subshell will exit
    1, but the parent process (mkdumprd) won't exit.
    
    So we should handle the exit code of a subshell if the subshell calls
    perror_exit over a failure.
    
    Signed-off-by: WANG Chao <chaowang at redhat.com>
    Acked-by: Vivek Goyal <vgoyal at redhat.com>

 mkdumprd |   17 ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 deletions(-)
---
diff --git a/mkdumprd b/mkdumprd
index 69c91a5..26fe5af 100644
--- a/mkdumprd
+++ b/mkdumprd
@@ -106,6 +106,10 @@ to_mount() {
     #for non-nfs _dev converting to use udev persistent name
     if [ -b "$_s" ]; then
         _pdev="$(get_persistent_dev $_s)"
+        if [ $? -ne 0 ]; then
+            return 1
+        fi
+
     else
         _pdev=$_dev
     fi
@@ -229,6 +233,10 @@ check_size() {
             return
     esac
 
+    if [ $? -ne 0 ]; then
+            perror_exit "Check dump target size failed"
+    fi
+
     if [ $avail -lt $memtotal ]; then
         echo "Warning: There might not be enough space to save a vmcore."
         echo "         The size of $2 should be greater than $memtotal kilo bytes."
@@ -267,6 +275,9 @@ verify_core_collector() {
 add_mount() {
     if ! target_is_root "$1"; then
         local _mnt=$(to_mount "$1")
+        if [ $? -ne 0 ]; then
+            exit 1
+        fi
         add_dracut_mount "$_mnt"
     fi
 }
@@ -530,7 +541,11 @@ do
         dd if=$config_val count=1 of=/dev/null > /dev/null 2>&1 || {
             perror_exit "Bad raw disk $config_val"
         }
-        add_dracut_arg "--device" "$(get_persistent_dev $config_val)"
+        _praw=$(get_persistent_dev $config_val)
+        if [ $? -ne 0 ]; then
+            exit 1
+        fi
+        add_dracut_arg "--device" "$_praw"
         check_size raw $config_val
         ;;
     ssh)


More information about the scm-commits mailing list