Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 7FAA4200B2D for ; Thu, 16 Jun 2016 20:16:14 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 7E53B160A51; Thu, 16 Jun 2016 18:16:14 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id C84EF1602C5 for ; Thu, 16 Jun 2016 20:16:13 +0200 (CEST) Received: (qmail 76169 invoked by uid 500); 16 Jun 2016 18:16:13 -0000 Mailing-List: contact commits-help@geode.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@geode.incubator.apache.org Delivered-To: mailing list commits@geode.incubator.apache.org Received: (qmail 76160 invoked by uid 99); 16 Jun 2016 18:16:13 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 Jun 2016 18:16:13 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 991F4C04EF for ; Thu, 16 Jun 2016 18:16:12 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -4.646 X-Spam-Level: X-Spam-Status: No, score=-4.646 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-1.426] autolearn=disabled Received: from mx2-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id l8Mz8gx0Ha6V for ; Thu, 16 Jun 2016 18:16:10 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx2-lw-eu.apache.org (ASF Mail Server at mx2-lw-eu.apache.org) with SMTP id 4C1D15FB2C for ; Thu, 16 Jun 2016 18:16:09 +0000 (UTC) Received: (qmail 75361 invoked by uid 99); 16 Jun 2016 18:16:08 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 Jun 2016 18:16:08 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 57336DFDEF; Thu, 16 Jun 2016 18:16:08 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: klund@apache.org To: commits@geode.incubator.apache.org Date: Thu, 16 Jun 2016 18:16:08 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/3] incubator-geode git commit: GEODE-68: GFSH SYS_HOST_NAME variable should report hostname if available archived-at: Thu, 16 Jun 2016 18:16:14 -0000 Repository: incubator-geode Updated Branches: refs/heads/develop 1c5ba1415 -> ca5b45cc8 GEODE-68: GFSH SYS_HOST_NAME variable should report hostname if available * This closes #157 [klund@apache.org] Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/3c422189 Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/3c422189 Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/3c422189 Branch: refs/heads/develop Commit: 3c4221895a9e0d5daa9da8d5c461b8700c2c1dbe Parents: b3955c1 Author: Kevin J. Duling Authored: Tue Jun 7 13:06:58 2016 -0700 Committer: Kirk Lund Committed: Thu Jun 16 11:15:59 2016 -0700 ---------------------------------------------------------------------- .../management/internal/cli/shell/Gfsh.java | 37 +++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/3c422189/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/shell/Gfsh.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/shell/Gfsh.java b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/shell/Gfsh.java index 6f4e351..da13bd9 100755 --- a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/shell/Gfsh.java +++ b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/shell/Gfsh.java @@ -20,6 +20,7 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; +import java.io.InputStream; import java.io.PrintStream; import java.net.URL; import java.text.MessageFormat; @@ -279,7 +280,7 @@ public class Gfsh extends JLineShell { private void initializeEnvironment() { env.put(ENV_SYS_USER, System.getProperty("user.name")); env.put(ENV_SYS_USER_HOME, System.getProperty("user.home")); - env.put(ENV_SYS_HOST_NAME, System.getProperty("user.name")); + env.put(ENV_SYS_HOST_NAME, determineHostName()); env.put(ENV_SYS_CLASSPATH, System.getProperty("java.class.path")); env.put(ENV_SYS_JAVA_VERSION, System.getProperty("java.version")); env.put(ENV_SYS_OS, System.getProperty("os.name")); @@ -306,6 +307,40 @@ public class Gfsh extends JLineShell { env.put(ENV_APP_RESULT_VIEWER, String.valueOf(DEFAULT_APP_RESULT_VIEWER)); } + private static String execReadToString(String execCommand) throws IOException { + Process proc = Runtime.getRuntime().exec(execCommand); + try (InputStream stream = proc.getInputStream()) { + try (Scanner s = new Scanner(stream).useDelimiter("\\A")) { + return s.hasNext() ? s.next().trim() : ""; + } + } + } + + private String determineHostName() + { + // Windows + String hostname = System.getenv("COMPUTERNAME"); + if (hostname == null) { + // Unix / Mac / Cygwin sometimes has this set + hostname = System.getenv("HOSTNAME"); + } + if (hostname == null) { + try { + // Unix / Mac / Windows / Cygwin + hostname = execReadToString("hostname"); + } + catch (IOException io) { + // happens if hostname binary is not found. + hostname = "unknown"; + } + } + if (hostname == null || hostname.isEmpty()) { + // if it still isn't set, default it. + hostname = "unknown"; + } + return hostname; + } + public static Gfsh getInstance(boolean launchShell, String[] args, GfshConfig gfshConfig) throws ClassNotFoundException, IOException {