spiritxishi commented on code in PR #12151:
URL: https://github.com/apache/inlong/pull/12151#discussion_r3533409022
##########
inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/utils/ExecuteLinux.java:
##########
@@ -17,40 +17,377 @@
package org.apache.inlong.agent.utils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
/**
- * ExecuteLinux cmd
+ * Utility for executing local OS commands.
+ *
+ * <p>{@link #exeCmd(String[])}, {@link #exeCmd(List, File, long)} and
+ * {@link #exePipedCmd(List, File, long)} are the recommended argv-array /
piped entry points.
+ * They use {@link ProcessBuilder} directly and never go through {@code
/bin/sh -c}, so shell
+ * metacharacters ({@code ;}, {@code |}, {@code &&}, backticks, {@code
$(...)}) are never
+ * interpreted.</p>
+ *
+ * <p>{@link #exeCmd(String)} is a legacy string-based fallback that runs
commands through
+ * {@code /bin/sh -c}; it is {@link Deprecated} and must only be used with
strings already
+ * validated by {@code ModuleCommandValidator}.</p>
+ *
+ * <p>Piping is emulated by chaining several {@link ProcessBuilder} instances
via background
+ * threads that copy stdout to the next process's stdin, so no shell is
required.</p>
*/
public class ExcuteLinux {
Review Comment:
done
##########
inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/utils/AgentUtils.java:
##########
@@ -329,12 +329,11 @@ public static String fetchLocalUuid() {
uuid = localUuid;
return uuid;
}
- String result = ExcuteLinux.exeCmd("dmidecode | grep UUID");
- if (StringUtils.isNotEmpty(result)
- && StringUtils.containsIgnoreCase(result, "UUID")) {
- uuid = result.split(":")[1].trim();
+ String result = ExcuteLinux.exeCmd(new String[]{"dmidecode", "-s",
"system-uuid"});
Review Comment:
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]