Fix: FD leak in liblttng-ust-ctl
[lttng-ust.git] / liblttng-ust-jul / org / lttng / ust / jul / LTTngSessiondCmd2_4.java
index 4b893e0b596662a3ebfd2523fa6acd0577b1039d..6f3cef348a2f9f428af5c493c4d087e3c1db2897 100644 (file)
@@ -20,8 +20,10 @@ package org.lttng.ust.jul;
 
 import java.nio.ByteBuffer;
 import java.nio.ByteOrder;
+import java.lang.Object;
 import java.util.logging.Logger;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Enumeration;
 
@@ -31,6 +33,12 @@ public interface LTTngSessiondCmd2_4 {
         */
        final static int NAME_MAX = 255;
 
+       /*
+        * Size of a primitive type int in byte. Because you know, Java can't
+        * provide that since it does not makes sense...
+        */
+       final static int INT_SIZE = 4;
+
        public interface SessiondResponse {
                /**
                 * Gets a byte array of the command so that it may be streamed
@@ -106,15 +114,21 @@ public interface LTTngSessiondCmd2_4 {
        public class sessiond_enable_handler implements SessiondResponse, SessiondCommand {
                private final static int SIZE = 4;
                public String name;
+               public int lttngLogLevel;
+               public int lttngLogLevelType;
 
                /** Return status code to the session daemon. */
                public lttng_jul_ret_code code;
 
                @Override
                public void populate(byte[] data) {
+                       int data_offset = INT_SIZE * 2;
+
                        ByteBuffer buf = ByteBuffer.wrap(data);
                        buf.order(ByteOrder.LITTLE_ENDIAN);
-                       name = new String(data, 0, data.length);
+                       lttngLogLevel = buf.getInt();
+                       lttngLogLevelType = buf.getInt();
+                       name = new String(data, data_offset, data.length - data_offset);
                }
 
                @Override
@@ -133,7 +147,7 @@ public interface LTTngSessiondCmd2_4 {
                 * @return Event name as a string if the event is NOT found thus was
                 * not enabled.
                 */
-               public String execute(LTTngLogHandler handler) {
+               public String execute(LTTngLogHandler handler, HashMap enabledLoggers) {
                        Logger logger;
 
                        if (name == null) {
@@ -152,17 +166,32 @@ public interface LTTngSessiondCmd2_4 {
                                                continue;
                                        }
 
+                                       if (enabledLoggers.get(loggerName) != null) {
+                                               continue;
+                                       }
+
                                        logger = handler.logManager.getLogger(loggerName);
+                                       handler.setLogLevel(loggerName, lttngLogLevel,
+                                                       lttngLogLevelType);
                                        logger.addHandler(handler);
+                                       enabledLoggers.put(loggerName, logger);
                                }
                                this.code = lttng_jul_ret_code.CODE_SUCCESS_CMD;
-                               return null;
+                               /*
+                                * Return the name as a new string so we can add the * event
+                                * name to the event list that we need to enable for new
+                                * Logger.
+                                */
+                               return new String(name);
                        }
 
                        this.code = lttng_jul_ret_code.CODE_SUCCESS_CMD;
                        logger = handler.logManager.getLogger(name.trim());
                        if (logger != null) {
+                               handler.setLogLevel(name.trim(), lttngLogLevel,
+                                               lttngLogLevelType);
                                logger.addHandler(handler);
+                               enabledLoggers.put(name.trim(), logger);
                                return null;
                        } else {
                                return new String(name);
This page took 0.024855 seconds and 4 git commands to generate.