From f6f6fd3d6e96c520c4c3250b34ee7bcf96650b93 Mon Sep 17 00:00:00 2001 From: Bart Van Der Meerssche Date: Mon, 4 Apr 2011 12:35:34 +0200 Subject: [PATCH] [fluksod + fsync] acquire a write lock on the delta and ctrl fifos when in use --- mote/v2/openwrt/package/flukso/luasrc/fluksod.lua | 12 ++++++++---- mote/v2/openwrt/package/flukso/luasrc/fsync.lua | 9 +++++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/mote/v2/openwrt/package/flukso/luasrc/fluksod.lua b/mote/v2/openwrt/package/flukso/luasrc/fluksod.lua index 19928ec..6c61b23 100755 --- a/mote/v2/openwrt/package/flukso/luasrc/fluksod.lua +++ b/mote/v2/openwrt/package/flukso/luasrc/fluksod.lua @@ -32,6 +32,8 @@ local data = require 'flukso.data' local arg = arg or {} -- needed when this code is not loaded via the interpreter local DEBUG = (arg[1] == '-d') +local LOGMASK = 'debug' +nixio.setlogmask(LOGMASK) local DAEMON = os.getenv('DAEMON') or 'fluksod' local DAEMON_PATH = os.getenv('DAEMON_PATH') or '/var/run/' .. DAEMON @@ -83,13 +85,15 @@ function dispatch(wan_child, lan_child) fdout = nixio.open(DELTA_PATH_OUT, O_RDWR) } if delta.fdin == nil or delta.fdout == nil then - -- TODO output to syslog - print('Error. Unable to open the delta fifos.') - print('Exiting...') + nixio.syslog('alert', 'cannot open the delta fifos') os.exit(1) end - -- TODO acquire an exclusive lock on the delta fifos or exit + -- acquire an exclusive lock on the delta fifos or exit + if not (delta.fdin:lock('tlock') and delta.fdout:lock('tlock')) then + nixio.syslog('alert', 'detected a lock on the delta fifos') + os.exit(2) + end local function tolua(num) return num + 1 diff --git a/mote/v2/openwrt/package/flukso/luasrc/fsync.lua b/mote/v2/openwrt/package/flukso/luasrc/fsync.lua index 0d11f9d..0180609 100755 --- a/mote/v2/openwrt/package/flukso/luasrc/fsync.lua +++ b/mote/v2/openwrt/package/flukso/luasrc/fsync.lua @@ -49,11 +49,16 @@ if ctrl.fdin == nil or ctrl.fdout == nil then os.exit(1) end +-- acquire an exclusive lock on the ctrl fifos or exit +if not (ctrl.fdin:lock('tlock') and ctrl.fdout:lock('tlock')) then + print('Error. Detected a lock on one of the ctrl fifos.') + print('Exiting...') + os.exit(1) +end + ctrl.fd = ctrl.fdout -- need this entry for nixio.poll ctrl.line = ctrl.fdout:linesource() --- TODO acquire an exclusive lock on the ctrl fifos or exit - local function send(ctrl, cmd) while ctrl.line() do end -- flush the out fifo