diff --git a/tools/iocsh.bash b/tools/iocsh.bash index fd562ad573c6129adf6f8bc6fe44227f05535474..f65fc222a47bd7e6d08ac72840f1feeda4dfe7bb 100755 --- a/tools/iocsh.bash +++ b/tools/iocsh.bash @@ -32,17 +32,25 @@ # Thursday, October 4 17:00:53 CEST 2018, jhlee # # 0.3.5 : Set the proper limitation of REQUIRE PV name -# Tuesday, October 9 14:36:56 CEST 2018, jhlee -# # 0.3.6 : In case, we know where $0 is, sourcing setE3Env.bash by itself -# +# 0.3.7 : Introduce the local mode with -l +# 0.3.8 : Use mktemp, and protect iocsh.bash when there is no diskspace +# 0.3.9 : LD_BIND_NOW=1 for resolving symbols at startup. +# 0.4.0 : - Fixed registryJLinkAdd failed pva error from base 7.0.3 +# - Enable an exit subroutine for sotfioc +# Wednesday, September 11 17:27:59 CEST 2019 +# 0.4.1 : - Use the one BASHPID for iocsh.bash +# 0.4.2 : - Use the secure path within tmp, but it may create "disk full" in the long +# term if each IOC cannot be closed properly +# 0.4.3 : - Tune REQUIRE-* PV in order to replace - with . easily +# declare -r SC_SCRIPT="$(readlink -e "$0")" declare -r SC_SCRIPTNAME=${0##*/} declare -r SC_TOP="${SC_SCRIPT%/*}" declare SC_VERSION="${E3_REQUIRE_VERSION}" declare STARTUP="" declare BASECODE="" - +declare -r TMP_PATH="/tmp/systemd-private-e3-iocsh" . ${SC_TOP}/iocsh_functions @@ -51,18 +59,24 @@ BASECODE="$(basecode_generator)" check_mandatory_env_settings +# ${BASHPID} returns iocsh.bash PID +iocsh_bash_id=${BASHPID} # -SC_VERSION+=-PID-${BASHPID} +SC_VERSION+=-PID-${iocsh_bash_id} # -# We define HOSTNAME + BASHPID -IOCSH_PS1=$(iocsh_ps1 "${BASHPID}") -REQUIRE_IOC=$(require_ioc "${BASHPID}") +# We define HOSTNAME + iocsh_bash_id +IOCSH_PS1=$(iocsh_ps1 "${iocsh_bash_id}") +REQUIRE_IOC=$(require_ioc "${iocsh_bash_id}") # # Default Initial Startup file for REQUIRE and minimal environment +# Create TMP_PATH path in order to keep tmp files secure until +# an IOC will be closed. -IOC_STARTUP=/tmp/${SC_SCRIPTNAME}-${SC_VERSION}-startup +mkdir -p ${TMP_PATH} +IOC_STARTUP=$(mktemp -p ${TMP_PATH} -q --suffix=_iocsh_${SC_VERSION}) || die 1 "${SC_SCRIPTNAME} CANNOT create the startup file, please check the disk space"; +# # To get the absolute path where iocsh.bash is executed IOCSH_TOP=${PWD} @@ -72,16 +86,18 @@ IOCSH_TOP=${PWD} trap "softIoc_end ${IOC_STARTUP}" EXIT HUP INT TERM - { printIocEnv; printf "# Set REQUIRE_IOC for its internal PVs\n"; printf "epicsEnvSet REQUIRE_IOC \"${REQUIRE_IOC}\"\n"; printf "#\n"; + printf "# Enable an exit subroutine for sotfioc\n"; + printf "dbLoadRecords \"${EPICS_BASE}/db/softIocExit.db\" \"IOC=${REQUIRE_IOC}\"\n"; + printf "#\n"; printf "# Set E3_IOCSH_TOP for the absolute path where %s is executed.\n" "${SC_SCRIPTNAME}" printf "epicsEnvSet E3_IOCSH_TOP \"${IOCSH_TOP}\"\n"; printf "#\n"; - + loadRequire; loadFiles "$@"; @@ -89,7 +105,10 @@ trap "softIoc_end ${IOC_STARTUP}" EXIT HUP INT TERM printf "# Set the IOC Prompt String One \n"; printf "epicsEnvSet IOCSH_PS1 \"$IOCSH_PS1\"\n"; printf "#\n"; - + + if [ "$REALTIME" == "RT" ]; then + printf "# Real Time \"$REALTIME\"\n"; + fi if [ "$init" != NO ]; then printf "# \n"; @@ -100,18 +119,26 @@ trap "softIoc_end ${IOC_STARTUP}" EXIT HUP INT TERM ulimit -c unlimited -# -x "PREFIX" -# PREFIX:exit & PREFIX:BaseVersion PVs are added to softIoc -# We can end this IOC via caput PREFIX:exit 1 - - +if [ "$REALTIME" == "RT" ]; then + export LD_BIND_NOW=1; + __CHRT__="chrt --fifo 1 "; + printf "## \n"; + printf "## Better support for Real-Time IOC Application.\n" + printf "## Now we set 'export LD_BIND_NOW=%s'\n" "$LD_BIND_NOW"; + printf "## If one may meet the 'Operation not permitted' message, \n"; + printf "## please run %s without the real-time option\n" "$SC_SCRIPTNAME"; + printf "##\n"; +else + __CHRT__=""; +fi if [[ ${BASECODE} -ge 07000101 ]]; then - _PVA_="PVA" + __PVA__="PVA" else - _PVA_="" + __PVA__="" fi - -softIoc${_PVA_} -D ${EPICS_BASE}/dbd/softIoc${_PVA_}.dbd "${IOC_STARTUP}" 2>&1 +# +# +${__CHRT__}${EPICS_BASE}/bin/${EPICS_HOST_ARCH}/softIoc${__PVA__} -D ${EPICS_BASE}/dbd/softIoc${__PVA__}.dbd "${IOC_STARTUP}" 2>&1 diff --git a/tools/iocsh_functions b/tools/iocsh_functions index 3b89b4fedee037e6fb5664d5a822e080b2d7fe47..22931839d6c34b9f60097e17ad2bd262187cc053 100644 --- a/tools/iocsh_functions +++ b/tools/iocsh_functions @@ -1,7 +1,7 @@ # -*- mode: sh -*- # # Copyright (c) 2004 - 2017 Paul Scherrer Institute -# Copyright (c) 2017 - Present European Spallation Source ERIC +# Copyright (c) 2017 - 2019 European Spallation Source ERIC # # The program is free software: you can redistribute # it and/or modify it under the terms of the GNU General Public License @@ -27,7 +27,7 @@ ROOT_UID=0 E_NOTROOT=101 EXIST=1 NON_EXIST=0 - +REALTIME= function pushd { builtin pushd "$@" > /dev/null; } function popd { builtin popd "$@" > /dev/null; } @@ -274,7 +274,7 @@ function iocsh_ps1 local host=${HOSTNAME%%.*}; iocsh_ps1+=${host:0:15}; - iocsh_ps1+="."; + iocsh_ps1+="-"; iocsh_ps1+=$pid; iocsh_ps1+=" > "; @@ -304,9 +304,8 @@ function require_ioc local require_ioc="" local pid="$1"; # Keep only short hostname (without domain) - local host=${HOSTNAME%%.*}; + local hostname=${HOSTNAME%%.*}; # Record name should not have . character, because it is used inside reacord - local hostname=$( echo $host | tr /a-z/ /A-Z/ ); require_ioc="REQMOD"; # char 6 ( 6) require_ioc+=":"; # char 1 ( 7) @@ -383,6 +382,9 @@ function loadFiles ( -v | -ver | --ver | -version | --version ) version ;; + ( -rt | -RT | -realtime | --realtime ) + REALTIME="RT" + ;; ( @* ) loadFiles $(cat ${file#@}) ;; @@ -412,10 +414,14 @@ function loadFiles fi echo "seq $1" ;; - ( -r ) + ( -r ) shift echo "require $1" ;; + ( -l ) + shift + printf "epicsEnvSet EPICS_DRIVER_PATH %s:${EPICS_DRIVER_PATH}\n", $1 + ;; ( -* ) printf "Unknown option $1\n\n" >&2 help @@ -508,6 +514,7 @@ function help printf " -?, -h, --help Show this page and exit.\n"; printf " -v, --version Show version and exit.\n"; printf " -c 'cmd args' Ioc shell command.\n"; + printf " -l 'cell path' Run Ioc with a cell path.\n"; printf " -s 'prog m=v' Sequencer program (and arguments), run with 'seq'.\n"; printf " This forces an 'iocInit' before running the program.\n"; printf " -r module[,ver] Modue (optionally with version) loaded via 'require'.\n"; diff --git a/tools/iocsh_gdb.bash b/tools/iocsh_gdb.bash index 5d29775a22dea1f5241bffa661599fa52bab4636..5c0d5c76c25a60bf8bc92d2b31384d4303c13856 100755 --- a/tools/iocsh_gdb.bash +++ b/tools/iocsh_gdb.bash @@ -37,17 +37,18 @@ BASECODE="$(basecode_generator)" check_mandatory_env_settings +# ${BASHPID} returns iocsh.bash PID +iocsh_bash_id=${BASHPID} # -SC_VERSION+=-PID-${BASHPID} +SC_VERSION+=-PID-${iocsh_bash_id} # -# We define HOSTNAME + BASHPID -IOCSH_PS1=$(iocsh_ps1 "${BASHPID}") -REQUIRE_IOC=$(require_ioc "${BASHPID}") +# We define HOSTNAME + iocsh_bash_id +IOCSH_PS1=$(iocsh_ps1 "${iocsh_bash_id}") +REQUIRE_IOC=$(require_ioc "${iocsh_bash_id}") # # Default Initial Startup file for REQUIRE and minimal environment - -IOC_STARTUP=/tmp/${SC_SCRIPTNAME}-${SC_VERSION}-startup +IOC_STARTUP=$(mktemp -q --suffix=_iocsh_${SC_VERSION}) || die 1 "${SC_SCRIPTNAME} CANNOT create the startup file, please check the disk space"; # To get the absolute path where iocsh.bash is executed IOCSH_TOP=${PWD} @@ -58,7 +59,6 @@ IOCSH_TOP=${PWD} trap "softIoc_end ${IOC_STARTUP}" EXIT HUP INT TERM - { printIocEnv; printf "# Set REQUIRE_IOC for its internal PVs\n";