diff --git a/bin/launchprocess.sh b/bin/launchprocess.sh index 3c3ababcb..31dac85a9 100644 --- a/bin/launchprocess.sh +++ b/bin/launchprocess.sh @@ -6,51 +6,22 @@ #2:process had already been running #all defaults have been assigned in the q wrspper script: cloudutils.q -#for each cmd line argument, extract the argument and assign to relevant variable -cnt=0 -extra_flag_cnt=0 -IFS='-' -read -ra arg_arr <<< "$@" -for arg in "${arg_arr[@]}" -do - if [ "$cnt" -gt 0 ]; then - IFS=' ' - read -ra sub_arg_arr <<< "$arg" - case ${sub_arg_arr[0]} in - procname ) - procname=${sub_arg_arr[1]} - ;; - proctype ) - proctype=${sub_arg_arr[1]} - ;; - U ) - U_arg=${sub_arg_arr[1]} - ;; - localtime ) - localtime_arg=${sub_arg_arr[1]} - ;; - qcmd ) - qcmd_arg=${sub_arg_arr[1]} - ;; - p ) - p_arg=${sub_arg_arr[1]} - ;; - * ) - extra_flag_cnt=$(($extra_flag_cnt + 1)) - ;; +#for each cmd line argument (-name followed by its value, which can be several words), assign it to the relevant variable +#and keep any other flag, with its value, for the start line +#(this used to split the whole line on '-', so a value with a '-' in it, such as a path, broke every argument after it) +extra_arg_arr="" +while [ $# -gt 0 ]; do + key=${1#-}; shift; val="" + while [ $# -gt 0 ] && [ "${1:0:1}" != "-" ]; do val="${val:+$val }$1"; shift; done + case $key in + procname ) procname=$val ;; + proctype ) proctype=$val ;; + U ) U_arg=$val ;; + localtime ) localtime_arg=$val ;; + qcmd ) qcmd_arg=$val ;; + p ) p_arg=$val ;; + * ) extra_arg_arr+=" -$key${val:+ $val}" ;; esac - fi - cnt=$((cnt+1)) -done - -#to deal with any number of extra flags and args, take the last (extra_flag_cnt) arguments from the arg_arr -extra_arg_arr=" " -i=0 -a=$((extra_flag_cnt * -1)) -while [ $i -lt "$extra_flag_cnt" ] -do - extra_arg_arr+="-"${arg_arr[$(( $a+i ))]} - i=$(($i + 1)) done #define the startline diff --git a/code/common/html.q b/code/common/html.q index c927c8272..cbe6a1262 100644 --- a/code/common/html.q +++ b/code/common/html.q @@ -39,7 +39,7 @@ add:{$[(count w x)>i:w[x;;0]?.z.w;.[`.u.w;(x;i;1);union;y];w[x],:enlist(.z.w;y)] sub:{if[x~`;:sub[;y]each t];if[not x in t;'x];del[x].z.w;add[x;y]} // add wssub method - have to subscribe to everything, don't return anything -wssub:{sub[x;`];} +wssub:{if[x~`;.z.s each t;:(::)];if[not x in t;'x];del[x].z.w;w[x],:enlist(.z.w;`);} end:{(neg union/[w[;;0]])@\:(`.u.end;x)} diff --git a/code/common/os.q b/code/common/os.q index 877a0c038..eef5b35fb 100644 --- a/code/common/os.q +++ b/code/common/os.q @@ -13,7 +13,7 @@ hdeldir:{[dirpath;pdir] if[not pdir;filelist:1_filelist]; .lg.o[`deldir;"deleting from directory : ",dirpath]; hdel each desc filelist} -md:{if[not Fex x;system"mkdir \"",pth[x],"\""]}; +md:{if[not Fex x;system("mkdir -p \"";"mkdir \"")[NT],pth[x],"\""]}; cpy:{system("cp ";"copy ")[NT],pth[x]," ",pth y} Vex:not 0h~type key`.@ df:{(`$("/";"\\")[NT]sv -1_v;`$-1#v:("/";"\\")[NT]vs pth(string x;x)[10h=type x])} diff --git a/code/handlers/trackservers.q b/code/handlers/trackservers.q index fda2115d3..6f0c05b99 100644 --- a/code/handlers/trackservers.q +++ b/code/handlers/trackservers.q @@ -138,7 +138,7 @@ getdetails:{(.z.f;.z.h;system"p";@[value;`.proc.procname;`];@[value;`.proc.proct / add session behind a handle addhw:{[hpuP;W] // Get the information around a process - info:`f`h`port`procname`proctype`attributes!(@[W;({$[`getdetails in key`.servers;.servers.getdetails[];(.z.f;.z.h;system"p";`;`;$[`getattributes in key`.proc;.proc.getattributes[];()!()])]};`);(`;`;0Ni;`;`;()!())]); + info:`f`h`port`procname`proctype`attributes!(@[W;({$[`getdetails in key`.servers;.servers.getdetails[];(.z.f;.z.h;system"p";@[value;`.proc.procname;`];@[value;`.proc.proctype;`];$[`getattributes in key`.proc;.proc.getattributes[];()!()])]};`);(`;`;0Ni;`;`;()!())]); if[0Ni~info`port;'"remote call failed on handle ",string W]; if[null name:info`procname;name:`$last("/"vs string info`f)except enlist""]; if[0=count name;name:`default]; diff --git a/tests/bglaunchprocess/run.sh b/tests/bglaunchprocess/run.sh index cc5c34c72..9b0c9cdfe 100644 --- a/tests/bglaunchprocess/run.sh +++ b/tests/bglaunchprocess/run.sh @@ -3,6 +3,9 @@ #path to test directory testpath=${KDBTESTS}/bglaunchprocess/ +#remove any port files left by an earlier run (written when discovery is off: see settings.q) +rm -f ${KDBLOG}/bglaunchprocess_*.port + #start procs ${TORQHOME}/torq.sh start all -csv ${testpath}/process.csv @@ -15,3 +18,4 @@ ${TORQHOME}/torq.sh start all -csv ${testpath}/process.csv #Shut down procs ${TORQHOME}/torq.sh stop all -csv ${testpath}/process.csv +rm -f ${KDBLOG}/bglaunchprocess_*.port diff --git a/tests/bglaunchprocess/settings.q b/tests/bglaunchprocess/settings.q index b66650ed1..1dfdbe9a5 100644 --- a/tests/bglaunchprocess/settings.q +++ b/tests/bglaunchprocess/settings.q @@ -5,3 +5,18 @@ input1:`procname`proctype`U`localtime`p`T`g`w`qcmd`custom`load!("test2";"test";" input2:`procname`proctype`load!("test3";"test";"${TORQHOME}/tests/bglaunchprocess/settings.q"); .servers.startup[]; +/the messages .sys.bglaunch and .sys.bgkill log, kept through TorQ's logging hook (.lg.ext) for the suite to check +bglogged:(); +.lg.ext:{[loglevel;proctype;proc;id;message;dict] if[id in `launchprocess`killprocess; bglogged,::enlist message]}; + +/the process launched with input2 listens on a port of its own choosing (-p 0W), and the suite finds it in discovery. +/Under a connection limit, such as KDB-X's free licence, TorQ turns discovery off and takes connection details from a +/file instead (DISCOVERYCONNECT in config/settings/default.q). Then each process of the suite writes its port to a file +/in KDBLOG when it starts, and the suite finds the process there. run.sh removes the files +portfile:{hsym`$getenv[`KDBLOG],"/bglaunchprocess_",string[x],".port"}; +if[(not .servers.DISCOVERYCONNECT) and 0