Make all globals start with a "g_" prefix

This makes it easier to spot them in code, and is shorter than using explicit
namespacing.
This commit is contained in:
Christian Kreibich 2021-11-29 11:56:03 -08:00
parent 14a8c979c1
commit b57be021b7
3 changed files with 32 additions and 32 deletions

View file

@ -9,8 +9,8 @@
redef ClusterController::role = ClusterController::Types::CONTROLLER;
global config_current: ClusterController::Types::Configuration;
global config_reqid_pending: string = "";
global g_config_current: ClusterController::Types::Configuration;
global g_config_reqid_pending: string = "";
function send_config_to_agents(req: ClusterController::Request::Request,
config: ClusterController::Types::Configuration)
@ -90,15 +90,15 @@ event ClusterAgent::API::notify_agent_hello(instance: string, host: addr, api_ve
# If we have a pending configuration request, check in on it now to see whether
# we have all agents required, and finalize the config request.
if ( config_reqid_pending == "" )
if ( g_config_reqid_pending == "" )
return;
local req = ClusterController::Request::lookup(config_reqid_pending);
local req = ClusterController::Request::lookup(g_config_reqid_pending);
if ( ClusterController::Request::is_null(req) || ! req?$set_configuration_state )
{
# Odd, just clear out pending state.
config_reqid_pending = "";
g_config_reqid_pending = "";
return;
}
@ -117,7 +117,7 @@ event ClusterAgent::API::notify_agent_hello(instance: string, host: addr, api_ve
# update the request state and eventually send the response event
# to the client.
send_config_to_agents(req, req$set_configuration_state$config);
config_reqid_pending = "";
g_config_reqid_pending = "";
}
@ -216,11 +216,11 @@ event ClusterController::API::set_configuration_request(reqid: string, config: C
req$set_configuration_state = ClusterController::Request::SetConfigurationState($config = config);
# At the moment there can only be one pending request.
if ( config_reqid_pending != "" )
if ( g_config_reqid_pending != "" )
{
res = ClusterController::Types::Result($reqid=reqid);
res$success = F;
res$error = fmt("request %s still pending", config_reqid_pending);
res$error = fmt("request %s still pending", g_config_reqid_pending);
req$results += res;
ClusterController::Log::info(fmt("tx ClusterController::API::set_configuration_response %s",
@ -312,7 +312,7 @@ event ClusterController::API::set_configuration_request(reqid: string, config: C
ClusterController::connect_retry);
}
config_reqid_pending = req$id;
g_config_reqid_pending = req$id;
return;
}

View file

@ -49,30 +49,30 @@ export {
}
# XXX this needs a mechanism for expiring stale requests
global requests: table[string] of Request;
global g_requests: table[string] of Request;
function create(reqid: string): Request
{
local ret = Request($id=reqid);
requests[reqid] = ret;
g_requests[reqid] = ret;
return ret;
}
function lookup(reqid: string): Request
{
if ( reqid in requests )
return requests[reqid];
if ( reqid in g_requests )
return g_requests[reqid];
return null_req;
}
function finish(reqid: string): bool
{
if ( reqid !in requests )
if ( reqid !in g_requests )
return F;
local req = requests[reqid];
delete requests[reqid];
local req = g_requests[reqid];
delete g_requests[reqid];
req$finished = T;