Skip to content

Computer field in InformationRecord is incorrect on Ubuntu 18.04 container #9526

Closed

Description

This repros only on container for ubuntu. It works as expected on VMs and containers of other Linux distros

Steps to reproduce

PS /> docker run -it --rm mcr.microsoft.com/powershell:latest
PowerShell 6.2.0
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.

PS /> $result = Write-Information "Test Message" *>&1
PS /> $result.Computer

PS /> [Environment]::MachineName
35dc3ee9a157
PS /> cat /etc/os-release
NAME="Ubuntu"
VERSION="18.04.2 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.2 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic
PS />

Expected behavior

PS /> $result.Computer
35dc3ee9a157

Actual behavior

$result.Computer is an empty string

Environment data

PS /> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.2.0
PSEdition                      Core
GitCommitId                    6.2.0
OS                             Linux 4.9.125-linuxkit #1 SMP Fri Sep 7 08:20:28 UTC 2018
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

  1. added
    Issue-Bug
    on May 2, 2019
  2. added
    WG-Engine
    on May 3, 2019
  3. iSazonov commented on May 3, 2019

    @iSazonov
    Collaborator

    We call GetFullyQualifiedName() from libpsl-native to get computer name. So a root of the issue is there.

    InformationRecord informationRecord = new InformationRecord(messageData, source);

    get { return this._computerName ?? (this._computerName = PsUtils.GetHostName()); }

    return Platform.NonWindowsGetHostName();

    return Unix.NativeMethods.GetFullyQualifiedName() ?? string.Empty;

    [DllImport(psLib, CharSet = CharSet.Ansi, SetLastError = true)]
    [return: MarshalAs(UnmanagedType.LPStr)]
    internal static extern string GetFullyQualifiedName();

  4. SteveL-MSFT commented on May 3, 2019

    @SteveL-MSFT
    Member

    Perhaps if GetFullyQualifiedName() is empty or null, we can fallback to [Environment]::MachineName?

  5. iSazonov commented on May 3, 2019

    @iSazonov
    Collaborator

    Or use [Environment]::MachineName directly and remove pinvoke?

  6. iSazonov commented on May 3, 2019

    @iSazonov
    Collaborator

    I see on Windows we use System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties - the API is ported and we could test it and use for all platforms.

  7. SteveL-MSFT commented on May 3, 2019

    @SteveL-MSFT
    Member

    We should probably see if we can get rid of libpsl-native altogether as .NET Core keeps adding more APIs

  8. iSazonov commented on May 4, 2019

    @iSazonov
    Collaborator

    I'd expect the issue on container for ubuntu is not PowerShell issue and should be fixed on container for ubuntu.

    I reviewed API that we use on Unix-es - we use the same GetHostName() (and CoreFX) to get host name but getaddrinfo() to get domain name - CoreFX uses GetDomainName()

    I think we should follow CoreFX and remove P/Invokes in our code.

  9. iSazonov commented on May 9, 2019

    @iSazonov
    Collaborator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugResolution-FixedWG-Engine

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions