From b34c3eee2bf5cb05a6f47c0ed9e318632c8dc534 Mon Sep 17 00:00:00 2001 From: Luke Gorrie Date: Mon, 22 Feb 2016 13:06:18 +0000 Subject: [PATCH] engine: Set shm path to "app/$name" Set the shared memory path (shm.path) to a private namespace for each app with prefix "app/$name". This means that apps can create shm objects such as counters and by default these will appear in a local namespace for that app. --- src/core/app.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/core/app.lua b/src/core/app.lua index 35a5305631..099fc3125a 100644 --- a/src/core/app.lua +++ b/src/core/app.lua @@ -5,6 +5,7 @@ local lib = require("core.lib") local link = require("core.link") local config = require("core.config") local timer = require("core.timer") +local shm = require("core.shm") local counter = require("core.counter") local zone = require("jit.zone") local ffi = require("ffi") @@ -65,6 +66,8 @@ end -- Run app:methodname() in protected mode (pcall). If it throws an -- error app will be marked as dead and restarted eventually. local function with_restart (app, method) + local oldshm = shm.path + shm.path = app.shmpath if use_restart then -- Run fn in protected mode using pcall. local status, err = pcall(method, app) @@ -75,6 +78,7 @@ local function with_restart (app, method) else method(app) end + shm.path = oldshm end -- Restart dead apps. @@ -162,7 +166,11 @@ function apply_config_actions (actions, conf) function ops.start (name) local class = conf.apps[name].class local arg = conf.apps[name].arg + local shmpath, shmorig = "app/"..name, shm.path + shm.path = shmpath local app = class:new(arg) + shm.path = shmorig + local shmpath = "app/"..name if type(app) ~= 'table' then error(("bad return value from app '%s' start() method: %s"):format( name, tostring(app))) @@ -171,6 +179,7 @@ function apply_config_actions (actions, conf) app.appname = name app.output = {} app.input = {} + app.shmpath = shmpath new_app_table[name] = app table.insert(new_app_array, app) app_name_to_index[name] = #new_app_array