From 1ae54625164c4b350524bd6cdbbc8ebb482bc6af Mon Sep 17 00:00:00 2001 From: xcaspar Date: Mon, 16 Aug 2021 14:23:01 +0800 Subject: [PATCH] bugfix: exclude the influence of JAVA_TOOL_OPTIONS variable Signed-off-by: xcaspar --- exec/jvm/sandbox.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/exec/jvm/sandbox.go b/exec/jvm/sandbox.go index d34fd902..a2f4f4ed 100644 --- a/exec/jvm/sandbox.go +++ b/exec/jvm/sandbox.go @@ -104,16 +104,21 @@ func attach(uid, pid, port string, ctx context.Context, javaHome string) (*spec. if err != nil { logrus.Warnf("get current user info failed, %v", err) } - var response *spec.Response + var command string if currUser != nil && (currUser.Username == username) { - response = cl.Run(ctx, javaBin, javaArgs) + command = fmt.Sprintf("%s %s", javaBin, javaArgs) } else { if currUser != nil { logrus.Infof("current user name is %s, not equal %s, so use sudo command to execute", currUser.Username, username) } - response = cl.Run(ctx, "sudo", fmt.Sprintf("-u %s %s %s", username, javaBin, javaArgs)) + command = fmt.Sprintf("sudo -u %s %s %s", username, javaBin, javaArgs) } + javaToolOptions := os.Getenv("JAVA_TOOL_OPTIONS") + if javaToolOptions != "" { + command = fmt.Sprintf("export JAVA_TOOL_OPTIONS='' && %s", command) + } + response := cl.Run(ctx, "", command) if !response.Success { return response, username }