switch (headerCmd.cmd) {
case CMD_REG_DONE:
{
+ /*
+ * Check command version:
+ *
+ * * 0: Connected to a non-fixed session daemon,
+ * which could send multiple disable
+ * event commands: do not decrement
+ * reference count on disable event command
+ * (original behaviour).
+ * * >0: Connected to a fixed session daemon:
+ * do decrement reference count on disable
+ * event command.
+ */
+ if (headerCmd.cmd_version > 0) {
+ this.log.setEnableRefCountDecrement(true);
+ }
+
/*
* Release semaphore so meaning registration is done and we
* can proceed to continue tracing.
/* A map of event name and reference count */
private Map<String, Integer> enabledLoggers;
+ /*
+ * If the following attribute is false, the internal ref count is
+ * never decremented when disabling a logger. This was the original
+ * behaviour of this agent, and this bug worked in concert with a
+ * bug in the session daemon which would send multiple disable
+ * commands for the same event name (manual disable + another
+ * disable on session destroy). The following attribute is needed
+ * because this version of the agent could be connected to a
+ * fixed session daemon, or a non-fixed session daemon, and it needs
+ * to work in both situations.
+ */
+ private boolean enableRefCountDecrement = false;
+
public LogFrameworkSkeleton() {
this.enabledLoggers = new HashMap<String, Integer>();
}
refcount--;
assert (refcount >= 0);
+ if (enableRefCountDecrement) {
+ /* Effectively decrement reference count. */
+ enabledLoggers.put(name, refcount);
+ }
+
if (refcount == 0) {
/* Event is not used anymore, remove it from the map */
Integer oldval = enabledLoggers.remove(name);
protected Integer getEventCount() {
return enabledLoggers.size();
}
+
+ public void setEnableRefCountDecrement(boolean enableRefCountDecrement) {
+ this.enableRefCountDecrement = enableRefCountDecrement;
+ }
}