#! /opt/bin/dash # # os/prog/freespace/post.sh # requires change from end='' to end=' ' in two places in malloc.py export PATH="/opt/bin:/bin:/usr/bin" #echo "Content-type: text/plain\n"; in=$(cat); echo "in = \"$in\""; exit echo "Content-type: text/html\n\nfreespace" user=`echo "${REMOTE_USER}" | tr -dc '[:alnum:]' | tr '[:upper:]' '[:lower:]'` if [ -z "$user" ]; then echo "Bad user: ${REMOTE_USER} -> $user"; exit 1; fi if [ -n "$HTTP_HOST" ]; then cd /os/prog/malloc || exit 1; fi # tomato = #FF6347 # lightgreen = #90EE90 # in=$(cat | egrep -v '#FF6347|#90EE90') h=$(echo "$in" | awk '{ if( $2 == "P") { print $3; exit; }}') useed=$(echo "$in" | awk '{ if( $2 == "useed") { gsub(/[^0-9]/,"",$3); print $3; exit; }}') case "$h" in "FIRST") p="FIRST"; s="123456789";; "WORST") p="WORST"; s="123456789";; *) p="BEST"; s="123456789";; esac if [ -n "$useed" ]; then seed="$useed" msg="- seed = $seed" else x=$(perl -e "print unpack(\"C*\",$user);"); seed="${s}${x}" #echo "
s = $s, x = $x, seed = $seed
" msg="" fi #echo "
in = $in
" #exit echo "$user - freespace results $msg

policy $p

green = correct
    red = wrong

" size=$(python3 ./malloc.py -s "$seed" -p "$p" -c | awk 'BEGIN { size=1; } { if( $4 == "Size" && $5 > size) size=$5; } END { print size }') out=$( (echo "$in"; python3 ./malloc.py -s "$seed" -p "$p" -c) | awk -v "size=$size" 'BEGIN { v=1; print ""; print ""; } { # each line of user input from malloc-post looks like: U name val if( $1 != "") { if( $1 == "U") u[$2]=$3; else { e=0; if( $1 ~ /^ptr/) { e=1; print ""; t=$5; } else if( $1 ~ /^Free\(/) { e=1; print ""; t=$3; } if(e) { r=u["r"v"r"]; if( r != "" && r == t) color="#90EE90"; else color="#FF6347"; print ""; } if( $1" "$2 == "Free List") { addr=8; sz=addr+1; for(i=1;i<=size;++i) { a=u["a"v"a"i"a"]; s=u["s"v"s"i"s"]; split($addr,ta,":"); split($sz,ts,":"); if( a == ta[2] && s == ts[2]) color="#90EE90"; else color="#FF6347"; print ""; addr+=4; sz=addr+1; } print ""; ++v; } }} } END { print "
OperationReturnedFree List
"$1 $2 $3"
"$1"   "r" addr: "a"
  size: "s"
"; }' ) if [ -z "$useed" ]; then bad=$(echo "$out" | grep "#FF6347" | wc -l) good=$(echo "$out" | grep "#90EE90" | wc -l) log=$(echo "$in" | tr -dc '[:alnum:]') echo "$(date) $user ${p}: good $good bad $bad in: $log" >> log fi echo "$out\n"