From: Arnaud Giersch Date: Thu, 27 Jul 2017 07:26:55 +0000 (+0200) Subject: smpirun: define function die() to print error message and exit. X-Git-Tag: v3_17~316^2~4^2~5 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/c930b326e49bd59e8b7c13e9a4ed2f9b507429b7 smpirun: define function die() to print error message and exit. --- diff --git a/src/smpi/smpirun.in b/src/smpi/smpirun.in index c3950fe5ae..750e28f0a0 100755 --- a/src/smpi/smpirun.in +++ b/src/smpi/smpirun.in @@ -75,6 +75,11 @@ unset pid trapped_signals="HUP INT QUIT ILL ABRT SEGV FPE ALRM TERM USR1 USR2 BUS" +die () { + printf '[%s] ** error: %s. Aborting.\n' "$(basename $0)" "$*" >&2 + exit 1 +} + smpirun_cleanup() { if [ -z "${KEEP}" ] ; then @@ -138,24 +143,21 @@ while true; do "-platform") PLATFORM="$2" if [ ! -f "${PLATFORM}" ]; then - echo "[`basename $0`] ** error: the file '${PLATFORM}' does not exist. Aborting." - exit 1 + die "the file '${PLATFORM}' does not exist" fi shift 2 ;; "-hostfile") HOSTFILE="$2" if [ ! -f "${HOSTFILE}" ]; then - echo "[`basename $0`] ** error: the file '${HOSTFILE}' does not exist. Aborting." - exit 1 + die "the file '${HOSTFILE}' does not exist" fi shift 2 ;; "-machinefile") HOSTFILE="$2" if [ ! -f "${HOSTFILE}" ]; then - echo "[`basename $0`] ** error: the file '${HOSTFILE}' does not exist. Aborting." - exit 1 + die "the file '${HOSTFILE}' does not exist" fi shift 2 ;; @@ -313,8 +315,7 @@ fi # Don't use wc -l to compute it to avoid issues with trailing \n at EOF hostfile_procs=$(grep -c "[a-zA-Z0-9]" $HOSTFILE) if [ ${hostfile_procs} = 0 ] ; then - echo "[`basename $0`] ** error: the hostfile '${HOSTFILE}' is empty. Aborting." >&2 - exit 1 + die "the hostfile '${HOSTFILE}' is empty" fi if [ -z "${NUMPROCS}" ] ; then