Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
smpirun: gracefuly handle the case where the user forgets to give a program to execute
[simgrid.git] / src / smpi / smpirun.in
index ad8aabe..28ae8b0 100755 (executable)
@@ -241,6 +241,13 @@ while true; do
     esac
 done
 
+# check if we still have at least one parameter beyond options
+if [ $# -eq 0 ]
+then
+    usage
+    exit
+fi
+
 if [ -n "$WRAPPER" ]; then
     EXEC="$WRAPPER $1"
 else
@@ -414,7 +421,7 @@ set -- $hostnames
 ##---- generate <process> tags------------------------------
 #prepare arguments at once
 for ARG in $PROC_ARGS; do
-  ARGS="$ARGS""<argument value=\"${ARG}\"/>
+  XML_ARGS="${XML_ARGS}""<argument value=\"${ARG}\"/>
 "
 done
 
@@ -438,7 +445,7 @@ do
             echo "    <argument value=\"$(echo $hosttraces|cut -d' ' -f1)\"/>" >> ${APPLICATIONTMP}
         fi
     else 
-    echo ${ARGS} >> ${APPLICATIONTMP}
+    echo ${XML_ARGS} >> ${APPLICATIONTMP}
     fi
     echo "  </process>" >> ${APPLICATIONTMP}
 done
@@ -513,6 +520,22 @@ wait $pid
 status=$?
 pid=""
 
+# Keep temporary files on failures to help debugging
+#
+if [ ${status} -ne 0 ] ; then
+    if [ -z ${KEEP} ]; then
+        echo ${EXEC} ${TRACEOPTIONS} ${SIMOPTS} ${PRIVATIZE} ${PLATFORMTMP} ${APPLICATIONTMP}
+        if [ ${HOSTFILETMP} = 1 ] ; then
+            echo "Generated hostfile ${HOSTFILE} kept."
+        fi
+        if [ ${UNROLLEDHOSTFILETMP} = 1 ] ; then
+            echo "Generated unrolled hostfile ${UNROLLEDHOSTFILE} kept."
+        fi
+    fi
+    echo "Execution failed with code ${status}."
+    KEEP=true
+fi
+
 smpirun_cleanup
 
 exit $status