From: Steven Baltakatei Sandoval Date: Thu, 2 Jul 2020 16:05:04 +0000 (+0000) Subject: feat(bkgpslog):Force ordered write operations with wait X-Git-Url: https://zdv2.bktei.com/gitweb/EVA-2020-02.git/commitdiff_plain/872c737e707a757ea1e33d3b7a0ed96881d72de4?ds=inline feat(bkgpslog):Force ordered write operations with wait Use `wait` built-in to force each detached process that appends location data to the output tar to wait until all other detached processes complete. This will prevent the magicWriteBuffer() and appendArgTar() functions from attempting to append to the same tar at the same time, causing script failure. --- diff --git a/exec/bkgpslog b/exec/bkgpslog index 6308e09..c7cae36 100755 --- a/exec/bkgpslog +++ b/exec/bkgpslog @@ -664,6 +664,7 @@ appendArgTar(){ magicWriteBuffer() { # Desc: bkgpslog-specific meta function for writing data to DIR_TMP then appending each file to PATHOUT_TAR local FN="${FUNCNAME[0]}"; + wait; # Wait to avoid collision with older magicWriteBuffer() instances (see https://www.tldp.org/LDP/abs/html/x9644.html ) yell "DEBUG:STATUS:$FN:Started magicWriteBuffer()."; appendArgTar "$bufferBash" "$FILEOUT_NMEA" "$PATHOUT_TAR" "$DIR_TMP" "$CMD_CONV_NMEA" "$CMD_COMPRESS" "$CMD_ENCRYPT"; # Write NMEA data appendArgTar "$bufferBash" "$FILEOUT_GPX" "$PATHOUT_TAR" "$DIR_TMP" "$CMD_CONV_GPX" "$CMD_COMPRESS" "$CMD_ENCRYPT"; # Write GPX file diff --git a/exec/bkgpslog-plan.org b/exec/bkgpslog-plan.org index bc98f9a..7eb5514 100644 --- a/exec/bkgpslog-plan.org +++ b/exec/bkgpslog-plan.org @@ -1,3 +1,21 @@ +* bkgpslog task list +** DONE Add job control for short buffer length + CLOSED: [2020-07-02 Thu 16:04] +2020-07-02T14:56Z; bktei> File write operations were bundled into a +magicWriteBuffer function that is called then detached from the script +shell (job control), but the detached job is not tracked by the main +script. A problem may arise if two instances of magicWriteBuffer +attempt to write to the same tar simultaneously. Two instances of +magicWriteBuffer may exist if the buffer length is low (ex: 1 second); +the default buffer length of 60 seconds should reduce the probability +of a collision but it should be possible for the main script to track +the process ID of a magicWriteBuffer() as soon as it detaches and then +checking (via ~$!~ as described [[https://bashitout.com/2013/05/18/Ampersands-on-the-command-line.html][here]]) that the process is still alive. +2020-07-02T15:23Z; bktei> I found that the Bash ~wait~ built-in can be +used to delay processing until a specified job completes. The ~wait~ +command will pause script execution until all backgrounded processes +complete. +2020-07-02T16:03Z; bktei> Added ~wait~. * bkgpslog narrative ** Initialize environment *** Init variables