From 59f0b6c3703938fa87ea89f9802938c2f52b038f Mon Sep 17 00:00:00 2001 From: Bert Massop Date: Sun, 1 Dec 2024 13:23:50 +0100 Subject: [PATCH] Remove Logger.OSThread-based PID logging that was always disabled The PID logging is always disabled and there is no API for enabling it. Remove the entire implementation and all the calls to its logPID method, but keep the interface for plugin compatibility. --- .../fcp/FCPConnectionInputHandler.java | 1 - .../fcp/FCPConnectionOutputHandler.java | 1 - src/freenet/clients/fcp/FCPServer.java | 1 - .../clients/http/SimpleToadletServer.java | 1 - src/freenet/io/NetworkInterface.java | 1 - src/freenet/node/CHKInsertHandler.java | 2 - src/freenet/node/CHKInsertSender.java | 3 - src/freenet/node/DNSRequester.java | 1 - src/freenet/node/IPDetectorPluginManager.java | 2 - src/freenet/node/LocationManager.java | 3 - src/freenet/node/LoggingConfigHandler.java | 1 - src/freenet/node/Node.java | 1 - src/freenet/node/PacketSender.java | 1 - src/freenet/node/Persister.java | 1 - src/freenet/node/RequestHandler.java | 1 - src/freenet/node/RequestSender.java | 1 - src/freenet/node/RequestStarter.java | 2 - src/freenet/node/SSKInsertHandler.java | 1 - src/freenet/node/SSKInsertSender.java | 1 - src/freenet/node/TextModeClientInterface.java | 2 - .../node/TextModeClientInterfaceServer.java | 1 - src/freenet/support/Logger.java | 199 +++--------------- src/freenet/support/PrioritizedTicker.java | 1 - .../support/compress/RealCompressor.java | 1 - .../transport/ip/IPAddressDetector.java | 1 - 25 files changed, 34 insertions(+), 197 deletions(-) diff --git a/src/freenet/clients/fcp/FCPConnectionInputHandler.java b/src/freenet/clients/fcp/FCPConnectionInputHandler.java index 11fc6de2a53..196ac5b1cf1 100644 --- a/src/freenet/clients/fcp/FCPConnectionInputHandler.java +++ b/src/freenet/clients/fcp/FCPConnectionInputHandler.java @@ -45,7 +45,6 @@ void start() { @Override public void run() { - freenet.support.Logger.OSThread.logPID(this); try { realRun(); } catch (TooLongException e) { diff --git a/src/freenet/clients/fcp/FCPConnectionOutputHandler.java b/src/freenet/clients/fcp/FCPConnectionOutputHandler.java index 469ee0badf7..ea8db4bca92 100644 --- a/src/freenet/clients/fcp/FCPConnectionOutputHandler.java +++ b/src/freenet/clients/fcp/FCPConnectionOutputHandler.java @@ -46,7 +46,6 @@ void start() { @Override public void run() { - freenet.support.Logger.OSThread.logPID(this); try { realRun(); } catch (IOException e) { diff --git a/src/freenet/clients/fcp/FCPServer.java b/src/freenet/clients/fcp/FCPServer.java index e9a4b77490b..3c6a66f2739 100644 --- a/src/freenet/clients/fcp/FCPServer.java +++ b/src/freenet/clients/fcp/FCPServer.java @@ -192,7 +192,6 @@ public void maybeStart() { @Override public void run() { - freenet.support.Logger.OSThread.logPID(this); while(true) { try { networkInterface.waitBound(); diff --git a/src/freenet/clients/http/SimpleToadletServer.java b/src/freenet/clients/http/SimpleToadletServer.java index fc1696c35db..ca73e1f6c69 100644 --- a/src/freenet/clients/http/SimpleToadletServer.java +++ b/src/freenet/clients/http/SimpleToadletServer.java @@ -1070,7 +1070,6 @@ void start() { @Override public void run() { - freenet.support.Logger.OSThread.logPID(this); if(logMINOR) Logger.minor(this, "Handling connection"); try { ToadletContextImpl.handle(sock, SimpleToadletServer.this, pageMaker, getUserAlertManager(), bookmarkManager); diff --git a/src/freenet/io/NetworkInterface.java b/src/freenet/io/NetworkInterface.java index 3665f5e834e..7aae10b85d1 100644 --- a/src/freenet/io/NetworkInterface.java +++ b/src/freenet/io/NetworkInterface.java @@ -383,7 +383,6 @@ public void close() throws IOException { */ @Override public void run() { - freenet.support.Logger.OSThread.logPID(this); while (!closed) { try { Socket clientSocket = serverSocket.accept(); diff --git a/src/freenet/node/CHKInsertHandler.java b/src/freenet/node/CHKInsertHandler.java index 5004feb3c17..fe2d7f3f733 100644 --- a/src/freenet/node/CHKInsertHandler.java +++ b/src/freenet/node/CHKInsertHandler.java @@ -90,7 +90,6 @@ public String toString() { @Override public void run() { - freenet.support.Logger.OSThread.logPID(this); try { realRun(); } catch (Throwable t) { @@ -573,7 +572,6 @@ public class DataReceiver implements PrioRunnable { @Override public void run() { - freenet.support.Logger.OSThread.logPID(this); if(logMINOR) Logger.minor(this, "Receiving data for "+CHKInsertHandler.this); // Don't log whether the transfer succeeded or failed as the transfer was initiated by the source therefore could be unreliable evidence. br.receive(new BlockReceiverCompletion() { diff --git a/src/freenet/node/CHKInsertSender.java b/src/freenet/node/CHKInsertSender.java index 12b31a3e753..c43ae368234 100644 --- a/src/freenet/node/CHKInsertSender.java +++ b/src/freenet/node/CHKInsertSender.java @@ -116,7 +116,6 @@ void start() { @Override public void run() { - freenet.support.Logger.OSThread.logPID(this); try { this.realRun(); } catch (Throwable t) { @@ -395,7 +394,6 @@ public String toString() { @Override public void run() { - freenet.support.Logger.OSThread.logPID(this); origTag.startedSender(); try { routeRequests(); @@ -917,7 +915,6 @@ public synchronized boolean sentRequest() { private void waitForBackgroundTransferCompletions() { try { - freenet.support.Logger.OSThread.logPID(this); if(logMINOR) Logger.minor(this, "Waiting for background transfer completions: "+this); // We must presently be at such a stage that no more background transfers will be added. diff --git a/src/freenet/node/DNSRequester.java b/src/freenet/node/DNSRequester.java index 1be4b82f63e..e21f07da92b 100644 --- a/src/freenet/node/DNSRequester.java +++ b/src/freenet/node/DNSRequester.java @@ -51,7 +51,6 @@ void start() { @Override public void run() { - freenet.support.Logger.OSThread.logPID(this); while(true) { try { realRun(); diff --git a/src/freenet/node/IPDetectorPluginManager.java b/src/freenet/node/IPDetectorPluginManager.java index ad69bd11c14..e5e05ae629b 100644 --- a/src/freenet/node/IPDetectorPluginManager.java +++ b/src/freenet/node/IPDetectorPluginManager.java @@ -372,7 +372,6 @@ private void tryMaybeRun() { node.getTicker().queueTimedJob(new Runnable() { @Override public void run() { - freenet.support.Logger.OSThread.logPID(this); tryMaybeRun(); } }, MINUTES.toMillis(1)); @@ -718,7 +717,6 @@ public void kill() { @Override public void run() { - freenet.support.Logger.OSThread.logPID(this); try { realRun(); } catch (Throwable t) { diff --git a/src/freenet/node/LocationManager.java b/src/freenet/node/LocationManager.java index a232c378922..331bca8ab3f 100644 --- a/src/freenet/node/LocationManager.java +++ b/src/freenet/node/LocationManager.java @@ -428,7 +428,6 @@ public class SwapRequestSender implements Runnable { @Override public void run() { - freenet.support.Logger.OSThread.logPID(this); Thread.currentThread().setName("SwapRequestSender"); while(true) { try { @@ -556,7 +555,6 @@ public class IncomingSwapRequestHandler implements Runnable { @Override public void run() { - freenet.support.Logger.OSThread.logPID(this); MessageDigest md = SHA256.getMessageDigest(); boolean reachedEnd = false; @@ -716,7 +714,6 @@ public class OutgoingSwapRequestHandler implements Runnable { @Override public void run() { - freenet.support.Logger.OSThread.logPID(this); long uid = r.nextLong(); if(!lock()) return; boolean reachedEnd = false; diff --git a/src/freenet/node/LoggingConfigHandler.java b/src/freenet/node/LoggingConfigHandler.java index a7003ce4733..c88bad65f72 100644 --- a/src/freenet/node/LoggingConfigHandler.java +++ b/src/freenet/node/LoggingConfigHandler.java @@ -357,7 +357,6 @@ void start() { @Override public void run() { - freenet.support.Logger.OSThread.logPID(this); fileLoggerHook.waitForSwitch(); delete(logDir); } diff --git a/src/freenet/node/Node.java b/src/freenet/node/Node.java index 5e7372c7a87..264b954e4f7 100644 --- a/src/freenet/node/Node.java +++ b/src/freenet/node/Node.java @@ -3438,7 +3438,6 @@ private void scheduleVersionTransition() { @Override public void run() { - freenet.support.Logger.OSThread.logPID(this); for(PeerNode pn: peers.myPeers()) { pn.updateVersionRoutablity(); } diff --git a/src/freenet/node/PacketSender.java b/src/freenet/node/PacketSender.java index 5e1cb9c8fba..18963729cff 100644 --- a/src/freenet/node/PacketSender.java +++ b/src/freenet/node/PacketSender.java @@ -112,7 +112,6 @@ public void run() { @Override public void run() { if(logMINOR) Logger.minor(this, "In PacketSender.run()"); - freenet.support.Logger.OSThread.logPID(this); schedulePeriodicJob(); /* diff --git a/src/freenet/node/Persister.java b/src/freenet/node/Persister.java index 18be5ab51ca..8eadbc83e82 100644 --- a/src/freenet/node/Persister.java +++ b/src/freenet/node/Persister.java @@ -48,7 +48,6 @@ void interrupt() { @Override public void run() { - freenet.support.Logger.OSThread.logPID(this); try { persistThrottle(); } catch (Throwable t) { diff --git a/src/freenet/node/RequestHandler.java b/src/freenet/node/RequestHandler.java index b6555783178..91267be65d1 100644 --- a/src/freenet/node/RequestHandler.java +++ b/src/freenet/node/RequestHandler.java @@ -102,7 +102,6 @@ public RequestHandler(PeerNode source, long id, Node n, short htl, Key key, Requ @Override public void run() { - freenet.support.Logger.OSThread.logPID(this); try { realRun(); //The last thing that realRun() does is register as a request-sender listener, so any exception here is the end. diff --git a/src/freenet/node/RequestSender.java b/src/freenet/node/RequestSender.java index 49c72332bc2..f84a1eb4da5 100644 --- a/src/freenet/node/RequestSender.java +++ b/src/freenet/node/RequestSender.java @@ -228,7 +228,6 @@ public void run() { static final int MAX_HIGH_HTL_FAILURES = 5; private void realRun() { - freenet.support.Logger.OSThread.logPID(this); if(isSSK && (pubKey == null)) { pubKey = ((NodeSSK)key).getPubKey(); } diff --git a/src/freenet/node/RequestStarter.java b/src/freenet/node/RequestStarter.java index a691563127d..03d64b873c7 100644 --- a/src/freenet/node/RequestStarter.java +++ b/src/freenet/node/RequestStarter.java @@ -226,7 +226,6 @@ private boolean startRequest(ChosenBlock req, boolean logMINOR) { @Override public void run() { - freenet.support.Logger.OSThread.logPID(this); while(true) { try { realRun(); @@ -248,7 +247,6 @@ public SenderThread(ChosenBlock req, Key key) { @Override public void run() { - freenet.support.Logger.OSThread.logPID(this); // FIXME ? key is not known for inserts here if (key != null) stats.reportOutgoingLocalRequestLocation(key.toNormalizedDouble()); diff --git a/src/freenet/node/SSKInsertHandler.java b/src/freenet/node/SSKInsertHandler.java index ef268673e59..0dd772c60b0 100644 --- a/src/freenet/node/SSKInsertHandler.java +++ b/src/freenet/node/SSKInsertHandler.java @@ -81,7 +81,6 @@ public String toString() { @Override public void run() { - freenet.support.Logger.OSThread.logPID(this); try { realRun(); } catch (Throwable t) { diff --git a/src/freenet/node/SSKInsertSender.java b/src/freenet/node/SSKInsertSender.java index b1f97543fc8..89b988b562d 100644 --- a/src/freenet/node/SSKInsertSender.java +++ b/src/freenet/node/SSKInsertSender.java @@ -107,7 +107,6 @@ void start() { @Override public void run() { - freenet.support.Logger.OSThread.logPID(this); origTag.startedSender(); try { routeRequests(); diff --git a/src/freenet/node/TextModeClientInterface.java b/src/freenet/node/TextModeClientInterface.java index 54db2bc9946..20a22541a25 100644 --- a/src/freenet/node/TextModeClientInterface.java +++ b/src/freenet/node/TextModeClientInterface.java @@ -116,7 +116,6 @@ public TextModeClientInterface(Node n, NodeClientCore core, HighLevelSimpleClien @Override public void run() { - freenet.support.Logger.OSThread.logPID(this); try { realRun(); } catch (IOException e) { @@ -426,7 +425,6 @@ private boolean processLine(BufferedReader reader) throws IOException { n.getTicker().queueTimedJob(new Runnable() { @Override public void run() { - freenet.support.Logger.OSThread.logPID(this); n.getNodeUpdater().arm(); } }, 0); diff --git a/src/freenet/node/TextModeClientInterfaceServer.java b/src/freenet/node/TextModeClientInterfaceServer.java index 63c181505a6..52460c8314b 100644 --- a/src/freenet/node/TextModeClientInterfaceServer.java +++ b/src/freenet/node/TextModeClientInterfaceServer.java @@ -267,7 +267,6 @@ public void set(Integer val) throws InvalidConfigValueException { */ @Override public void run() { - freenet.support.Logger.OSThread.logPID(this); while(true) { int curPort = port; String tempBindTo = this.bindTo; diff --git a/src/freenet/support/Logger.java b/src/freenet/support/Logger.java index f74bbc3cc75..a9fbb42971c 100644 --- a/src/freenet/support/Logger.java +++ b/src/freenet/support/Logger.java @@ -1,204 +1,73 @@ package freenet.support; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; import java.lang.ref.WeakReference; import java.lang.reflect.Field; import java.lang.reflect.Modifier; -import java.nio.charset.StandardCharsets; -import java.util.regex.PatternSyntaxException; import freenet.support.FileLoggerHook.IntervalParseException; import freenet.support.LoggerHook.InvalidThresholdException; -import freenet.support.io.Closer; /** * @author Iakin */ public abstract class Logger { + @Deprecated public final static class OSThread { - - private static boolean getPIDEnabled = false; - private static boolean getPPIDEnabled = false; - private static boolean logToFileEnabled = false; - private static LogLevel logToFileVerbosity = LogLevel.DEBUG; - private static boolean logToStdOutEnabled = false; - private static boolean procSelfStatEnabled = false; - /** - * Get the thread's process ID or return -1 if it's unavailable for some reason + * @deprecated always returns -1 */ - public synchronized static int getPID(Object o) { - if (!getPIDEnabled) { - return -1; - } - return getPIDFromProcSelfStat(o); + @Deprecated + public static int getPID(Object o) { + return -1; } - + /** - * Get the thread's parent process ID or return -1 if it's unavailable for some reason + * @deprecated always returns -1 */ - public synchronized static int getPPID(Object o) { - if (!getPPIDEnabled) { - return -1; - } - return getPPIDFromProcSelfStat(o); + @Deprecated + public static int getPPID(Object o) { + return -1; } - + /** - * Get a specified field from /proc/self/stat or return null if - * it's unavailable for some reason. + * @deprecated always returns null */ - public synchronized static String getFieldFromProcSelfStat(int fieldNumber, Object o) { - String readLine = null; - - if (!procSelfStatEnabled) { - return null; - } - - // read /proc/self/stat and parse for the specified field - InputStream is = null; - BufferedReader br = null; - File procFile = new File("/proc/self/stat"); - if (procFile.exists()) { - try { - is = new FileInputStream(procFile); - br = new BufferedReader(new InputStreamReader(is, StandardCharsets.ISO_8859_1 /* ASCII */)); - } catch (FileNotFoundException e1) { - logStatic(o, "'/proc/self/stat' not found", logToFileVerbosity); - procSelfStatEnabled = false; - br = null; - } - if (null != br) { - try { - readLine = br.readLine(); - } catch (IOException e) { - error(o, "Caught IOException in br.readLine() of OSThread.getFieldFromProcSelfStat()", e); - readLine = null; - } finally { - Closer.close(br); - } - if (null != readLine) { - try { - String[] procFields = readLine.trim().split(" "); - if (4 <= procFields.length) { - return procFields[ fieldNumber ]; - } - } catch (PatternSyntaxException e) { - error(o, "Caught PatternSyntaxException in readLine.trim().split(\" \") of OSThread.getFieldFromProcSelfStat() while parsing '"+readLine+"'", e); - } - } - } else { - Closer.close(is); - } - } + @Deprecated + public static String getFieldFromProcSelfStat(int fieldNumber, Object o) { return null; } - + /** - * Get the thread's process ID using the /proc/self/stat method or - * return -1 if it's unavailable for some reason. This is an ugly - * hack required by Java to get the OS process ID of a thread on - * Linux without using JNI. + * @deprecated always returns -1 */ - public synchronized static int getPIDFromProcSelfStat(Object o) { - int pid = -1; - - if (!getPIDEnabled) { - return -1; - } - if (!procSelfStatEnabled) { - return -1; - } - String pidString = getFieldFromProcSelfStat(0, o); - if (null == pidString) { - return -1; - } - try { - pid = Integer.parseInt( pidString.trim() ); - } catch (NumberFormatException e) { - error(o, "Caught NumberFormatException in Integer.parseInt() of OSThread.getPIDFromProcSelfStat() while parsing '"+pidString+"'", e); - } - return pid; + @Deprecated + public static int getPIDFromProcSelfStat(Object o) { + return -1; } - + /** - * Get the thread's parent process ID using the /proc/self/stat - * method or return -1 if it's unavailable for some reason. This - * is ugly hack required by Java to get the OS parent process ID of - * a thread on Linux without using JNI. + * @deprecated always returns -1 */ - public synchronized static int getPPIDFromProcSelfStat(Object o) { - int ppid = -1; - - if (!getPPIDEnabled) { - return -1; - } - if (!procSelfStatEnabled) { - return -1; - } - String ppidString = getFieldFromProcSelfStat(3, o); - if (null == ppidString) { - return -1; - } - try { - ppid = Integer.parseInt( ppidString.trim() ); - } catch (NumberFormatException e) { - error(o, "Caught NumberFormatException in Integer.parseInt() of OSThread.getPPIDFromProcSelfStat() while parsing '"+ppidString+"'", e); - } - return ppid; + @Deprecated + public static int getPPIDFromProcSelfStat(Object o) { + return -1; } - + /** - * Log the thread's process ID or return -1 if it's unavailable for some reason + * @deprecated always returns -1 */ - public synchronized static int logPID(Object o) { - if (!getPIDEnabled) { - return -1; - } - int pid = getPID(o); - String msg; - if (-1 != pid) { - msg = "This thread's OS PID is " + pid; - } else { - msg = "This thread's OS PID could not be determined"; - } - if (logToStdOutEnabled) { - System.out.println(msg + ": " + o); - } - if (logToFileEnabled) { - logStatic(o, msg, logToFileVerbosity); - } - return pid; + @Deprecated + public static int logPID(Object o) { + return -1; } - + /** - * Log the thread's process ID or return -1 if it's unavailable for some reason + * @deprecated always returns -1 */ - public synchronized static int logPPID(Object o) { - if (!getPPIDEnabled) { - return -1; - } - int ppid = getPPID(o); - String msg; - if (-1 != ppid) { - msg = "This thread's OS PPID is " + ppid; - } else { - msg = "This thread's OS PPID could not be determined"; - } - if (logToStdOutEnabled) { - System.out.println(msg + ": " + o); - } - if (logToFileEnabled) { - logStatic(o, msg, logToFileVerbosity); - } - return ppid; + @Deprecated + public static int logPPID(Object o) { + return -1; } } diff --git a/src/freenet/support/PrioritizedTicker.java b/src/freenet/support/PrioritizedTicker.java index 310320eb030..5c077a92bff 100644 --- a/src/freenet/support/PrioritizedTicker.java +++ b/src/freenet/support/PrioritizedTicker.java @@ -68,7 +68,6 @@ public void start() { @Override public void run() { if(logMINOR) Logger.minor(this, "In Ticker.run()"); - freenet.support.Logger.OSThread.logPID(this); while(true) { try { realRun(); diff --git a/src/freenet/support/compress/RealCompressor.java b/src/freenet/support/compress/RealCompressor.java index 38e784ef1e7..918f9a27803 100644 --- a/src/freenet/support/compress/RealCompressor.java +++ b/src/freenet/support/compress/RealCompressor.java @@ -44,7 +44,6 @@ public void enqueueNewJob(final CompressJob j) { task = executorService.submit(new PrioRunnable() { @Override public void run() { - freenet.support.Logger.OSThread.logPID(this); try { try { j.tryCompress(context); diff --git a/src/freenet/support/transport/ip/IPAddressDetector.java b/src/freenet/support/transport/ip/IPAddressDetector.java index f6e6f27794f..288bd1bd2f6 100644 --- a/src/freenet/support/transport/ip/IPAddressDetector.java +++ b/src/freenet/support/transport/ip/IPAddressDetector.java @@ -279,7 +279,6 @@ protected void onGetAddresses(List addrs) { @Override public void run() { - freenet.support.Logger.OSThread.logPID(this); while(true) { try { Thread.sleep(interval);