[lastbash-cvs] lastbash lastbash,1.65,1.66
Status: Beta
Brought to you by:
cstroie
|
From: Costin S. <cs...@us...> - 2006-11-30 20:50:25
|
Update of /cvsroot/lastbash/lastbash In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv30882 Modified Files: lastbash Log Message: Multiple commands per call and locks during remote calls. Index: lastbash =================================================================== RCS file: /cvsroot/lastbash/lastbash/lastbash,v retrieving revision 1.65 retrieving revision 1.66 diff -u -d -r1.65 -r1.66 --- lastbash 30 Nov 2006 17:06:21 -0000 1.65 +++ lastbash 30 Nov 2006 20:50:21 -0000 1.66 @@ -57,10 +57,11 @@ DEBUG_FILE="${HOME_DIR}/lastbash.debug" PID_FILE="${HOME_DIR}/pid" COMMAND_FILE="${HOME_DIR}/command" +COMMAND_FILE_LOCK="${HOME_DIR}/command.lock" # Internal stuff PLAYERS="mplayer" -REQ_PROGRAMS="tput md5sum dd" +REQ_PROGRAMS="rm tput md5sum dd" declare -a HTTP_HEADERS HTTP_RESPONSE CR=$'\x0d' LF=$'\x0a' @@ -1333,18 +1334,25 @@ return "${RET}" } -# Function: Send a command to the running instance {{{1 +# Function: Send commands to the running instance {{{1 #----------------------------------------------------------------------------- function remote_call() { - # $1 - the command - - local PID + # $@ - the commands - # FIXME add locks - echo "$1" >> "${COMMAND_FILE}" - PID="$(< $PID_FILE)" - kill -HUP ${PID} + if [ -f "${COMMAND_FILE_LOCK}" ] + then + echo "Lockfile present, commands not sent" + else + # Create the lock + echo "$$" > "${COMMAND_FILE_LOCK}" + # Send the commands + echo "$@" >> "${COMMAND_FILE}" + # Remove the lock + rm -f "${COMMAND_FILE_LOCK}" + # Signal the first instance + kill -HUP "$(< $PID_FILE)" + fi } # Function: Execute arbitrary commands {{{1 @@ -1378,15 +1386,32 @@ { local CMD ARGS - # Set the status line - tui_sbar "Remote command received" + if [ -f "${COMMAND_FILE_LOCK}" ] + then + tui_sbar "Lockfile present, remote call ignored" + else + # Create the lock + echo "$$" > "${COMMAND_FILE_LOCK}" - # FIXME enable the read lock - read CMD ARGS < "${COMMAND_FILE}" - execute_command "${CMD}" "${ARGS}" + # Check the command file exists + if [ -f "${COMMAND_FILE}" ] + then + # Read the commands, one per line, and execute them + while read CMD ARGS + do + [ "${CMD}" ] && execute_command "${CMD}" "${ARGS}" + done < "${COMMAND_FILE}" - rm -f "${COMMAND_FILE}" - # FIXME disable the read lock + # Remove the command file + rm -f "${COMMAND_FILE}" + else + # There is no command file + tui_sbar "No commands to execute" + fi + + # Remove the lock + rm -f "${COMMAND_FILE_LOCK}" + fi # Restore the status bar sleep 1 @@ -1445,7 +1470,7 @@ ;; esac # Reset the key - KEY="" + unset KEY done } # }}}1 |