Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Behaviour difference between Mono and CoreCLR #9839

Closed
Therzok opened this issue Aug 1, 2018 · 10 comments · Fixed by #9843

Comments

@Therzok
Copy link
Member

@Therzok Therzok commented Aug 1, 2018

using System;

namespace envrinoment_test
{
    class Program
    {
        static void Main(string[] args)
        {
			Console.WriteLine(Environment.UserDomainName);
			Console.WriteLine(Environment.MachineName);
        }
    }
}

Steps to Reproduce

  1. Given the code above, run this under both dotnet and mono
  2. Dotnet prints:
MININT-8D14Q3D
MININT-8D14Q3D
  1. Mono prints:
MININT-8D14Q3D.redmond.corp.microsoft.com
MININT-8D14Q3D.redmond.corp.microsoft.com

They should be matching, not sure what full framework CLR prints

On which platforms did you notice this

[x] macOS
[ ] Linux
[ ] Windows

Version Used:

Mono JIT compiler version 5.17.0.84 (pull-request-8951/ab1aafc1d80 Fri Jun 15 11:11:39 EDT 2018)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com

@Therzok

This comment has been minimized.

Copy link
Member Author

@Therzok Therzok commented Aug 1, 2018

This is probably a blocker for @jsuarezruiz for TFS support in VSMac

@marek-safar marek-safar added this to Bugs Pool in Bugs Week via automation Aug 1, 2018
@NattyNarwhal

This comment has been minimized.

Copy link
Contributor

@NattyNarwhal NattyNarwhal commented Aug 1, 2018

What's the value of domainname and hostname commands? My guess is Mono is just passing through the value of the hostname, which can itself include the domain name.

@NattyNarwhal

This comment has been minimized.

Copy link
Contributor

@NattyNarwhal NattyNarwhal commented Aug 1, 2018

FWIW, csi for .NET 4.6, running on a non-domain joined Windows 10 system:

Microsoft (R) Roslyn C# Compiler version 1.3.4.60902
Loading context from 'CSharpInteractive.rsp'.
Type "#help" for more information.
> Environment.UserDomainName
"AZIMUTH"
> Environment.MachineName
"AZIMUTH"
@Therzok

This comment has been minimized.

Copy link
Member Author

@Therzok Therzok commented Aug 1, 2018

➜  monodevelop git:(master-fix593840) ✗ hostname
MININT-8D14Q3D.redmond.corp.microsoft.com
➜  monodevelop git:(master-fix593840) ✗ domainname

@Therzok

This comment has been minimized.

Copy link
Member Author

@Therzok Therzok commented Aug 1, 2018

Non-domain joined values

➜  monodevelop git:(master-fix593840) ✗ hostname
Mariuss-MacBook-Pro.local
➜  monodevelop git:(master-fix593840) ✗ domainname

And on repl:

Environment.UserDomainName
"Mariuss-MacBook-Pro.local"
Environment.MachineName
"Mariuss-MacBook-Pro.local"
@NattyNarwhal

This comment has been minimized.

Copy link
Contributor

@NattyNarwhal NattyNarwhal commented Aug 1, 2018

looks like the behaviour when the hostname is actually the hostname and domainname combined should perhaps be:

  • for hostname, truncate at first dot

  • for domainname, use the system domainname value if not empty, otheruse use everything but what was used for the hostname

that should match Windows behaviour more closely?

@NattyNarwhal

This comment has been minimized.

Copy link
Contributor

@NattyNarwhal NattyNarwhal commented Aug 1, 2018

FWIW, can reproduce this on non-Mac; it seems quite common in the Unix world:

csharp> Environment.UserDomainName
"aix.autocoder.local"
csharp> Environment.MachineName 
"aix.autocoder.local"

aix$ hostname
aix.autocoder.local
aix$ domainname

aix$ uname
AIX
@NattyNarwhal

This comment has been minimized.

Copy link
Contributor

@NattyNarwhal NattyNarwhal commented Aug 1, 2018

from mcs/class/corlib/System/Environment.cs:

                /// <summary>
                /// Gets the name of the local computer
                /// </summary>
                public extern static string MachineName {
                        [MethodImplAttribute (MethodImplOptions.InternalCall)]
                        [EnvironmentPermission (SecurityAction.Demand, Read="COMPUTERNAME")]
                        [SecurityPermission (SecurityAction.Demand, UnmanagedCode=true)]
                        get;
                }

                /// <summary>
                /// Get UserDomainName
                /// </summary>
                public static string UserDomainName {
                        // FIXME: this variable doesn't exist (at least not on WinXP) - reported to MS as FDBK20562
                        [EnvironmentPermission (SecurityAction.Demand, Read="USERDOMAINNAME")]
                        get {
                                return MachineName;
                        }
                }

and it's in icalls, let's see if I can come up with a quick and dirty patch...

@NattyNarwhal

This comment has been minimized.

Copy link
Contributor

@NattyNarwhal NattyNarwhal commented Aug 1, 2018

Is this what you'd want?

csharp> Environment.UserDomainName
"aix"
csharp> Environment.MachineName
"aix"
diff --git a/mono/metadata/icall.c b/mono/metadata/icall.c
index 320abc2..5ac3300 100644
--- a/mono/metadata/icall.c
+++ b/mono/metadata/icall.c
@@ -6542,7 +6542,7 @@ mono_icall_get_machine_name (MonoError *error)
 #if !defined(DISABLE_SOCKETS)
 	MonoStringHandle result;
 	char *buf;
-	int n;
+	int n, i;
 #if defined _SC_HOST_NAME_MAX
 	n = sysconf (_SC_HOST_NAME_MAX);
 	if (n == -1)
@@ -6552,6 +6552,13 @@ mono_icall_get_machine_name (MonoError *error)
 	
 	if (gethostname (buf, n) == 0){
 		buf [n] = 0;
+		// try truncating the string at the first dot
+		for (i = 0; i < n; i++) {
+			if (buf[i] == '.') {
+				buf[i] = '\0';
+				break;
+			}
+		}
 		result = mono_string_new_handle (mono_domain_get (), buf, error);
 	} else
 		result = MONO_HANDLE_CAST (MonoString, NULL_HANDLE);
@Therzok

This comment has been minimized.

Copy link
Member Author

@Therzok Therzok commented Aug 1, 2018

Yup, that would be perfect

NattyNarwhal added a commit to NattyNarwhal/mono that referenced this issue Aug 1, 2018
Unix machines often put their FQDN as the host name, and domain
name is used for things such as yp. As such, truncate the FQDN to
just the hostname, as other Unix utilities seem to do.

Matches the .NET Core and .NET Framework behaviour, and MS seems to
require this for a future project. Fixes mono#9839.
Bugs Week automation moved this from Bugs Pool to Done Aug 20, 2018
akoeplinger added a commit that referenced this issue Aug 20, 2018
* Truncate MachineName (and UserDomainName) at first period

Unix machines often put their FQDN as the host name, and domain
name is used for things such as yp. As such, truncate the FQDN to
just the hostname, as other Unix utilities seem to do.

Matches the .NET Core and .NET Framework behaviour, and MS seems to
require this for a future project. Fixes #9839.

* Add a unit test for bug

* Formatting tweaks
monojenkins added a commit to monojenkins/mono that referenced this issue Aug 31, 2018
Unix machines often put their FQDN as the host name, and domain
name is used for things such as yp. As such, truncate the FQDN to
just the hostname, as other Unix utilities seem to do.

Matches the .NET Core and .NET Framework behaviour, and MS seems to
require this for a future project. Fixes mono#9839.
monojenkins added a commit to monojenkins/mono that referenced this issue Aug 31, 2018
Unix machines often put their FQDN as the host name, and domain
name is used for things such as yp. As such, truncate the FQDN to
just the hostname, as other Unix utilities seem to do.

Matches the .NET Core and .NET Framework behaviour, and MS seems to
require this for a future project. Fixes mono#9839.
akoeplinger added a commit that referenced this issue Sep 4, 2018
…10418)

Backport of #9843.

* Truncate MachineName (and UserDomainName) at first period

Unix machines often put their FQDN as the host name, and domain
name is used for things such as yp. As such, truncate the FQDN to
just the hostname, as other Unix utilities seem to do.

Matches the .NET Core and .NET Framework behaviour, and MS seems to
require this for a future project. Fixes #9839.

* Add a unit test for bug

* Formatting tweaks
akoeplinger added a commit that referenced this issue Sep 4, 2018
…10419)

Backport of #9843.

* Truncate MachineName (and UserDomainName) at first period

Unix machines often put their FQDN as the host name, and domain
name is used for things such as yp. As such, truncate the FQDN to
just the hostname, as other Unix utilities seem to do.

Matches the .NET Core and .NET Framework behaviour, and MS seems to
require this for a future project. Fixes #9839.

* Add a unit test for bug

* Formatting tweaks
@marek-safar marek-safar moved this from Done to Archived in Bugs Week Sep 24, 2018
jonpryor added a commit to xamarin/xamarin-android that referenced this issue Oct 9, 2018
Bumps to mono/llvm:release_60@117a508c
Bumps to xamarin/xamarin-android-api-compatibility:master@7ccb4802

	$ git diff --shortstat e1af6ea..ab3c897d       # mono
        1443 files changed, 66049 insertions(+), 45745 deletions(-)
	$ git diff --shortstat bdb3a116..117a508c      # llvm
	 26794 files changed, 4110589 insertions(+), 754376 deletions(-)
	$ git diff --shortstat c550d1bd..7ccb4802      # xamarin-android-api-compatibility
	 2 files changed, 16260 insertions(+), 12347 deletions(-)

Incomplete summary of easily `grep`able fixes:

Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=11199
Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=19436
Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=23668
Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=26983
Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=33728
Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=46917
fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=60065
Fixes: mono/mono#6173
Fixes: mono/mono#6466
Fixes: mono/mono#6647
Fixes: mono/mono#6834
Fixes: mono/mono#7058
Fixes: mono/mono#7137
Fixes: mono/mono#7260
Fixes: mono/mono#7305
Fixes: mono/mono#7402
Fixes: mono/mono#7525
Fixes: mono/mono#7610
Fixes: mono/mono#7649
Fixes: mono/mono#7655
Fixes: mono/mono#7683
Fixes: mono/mono#7685
Fixes: mono/mono#7716
Fixes: mono/mono#7731
Fixes: mono/mono#7785
Fixes: mono/mono#7828
Fixes: mono/mono#7944
Fixes: mono/mono#7947
Fixes: mono/mono#8036
Fixes: mono/mono#8074
Fixes: mono/mono#8089
Fixes: mono/mono#8112
Fixes: mono/mono#8122
Fixes: mono/mono#8143
Fixes: mono/mono#8149
Fixes: mono/mono#8152
Fixes: mono/mono#8175
Fixes: mono/mono#8177
Fixes: mono/mono#8250
Fixes: mono/mono#8267
Fixes: mono/mono#8273
Fixes: mono/mono#8282
Fixes: mono/mono#8310
Fixes: mono/mono#8311
Fixes: mono/mono#8329
Fixes: mono/mono#8340
Fixes: mono/mono#8372
Fixes: mono/mono#8407
Fixes: mono/mono#8409
Fixes: mono/mono#8422
Fixes: mono/mono#8430
Fixes: mono/mono#8439
fixes: mono/mono#8447
Fixes: mono/mono#8469
Fixes: mono/mono#8504
Fixes: mono/mono#8575
Fixes: mono/mono#8597
Fixes: mono/mono#8623
Fixes: mono/mono#8627
Fixes: mono/mono#8698
Fixes: mono/mono#8701
Fixes: mono/mono#8712
Fixes: mono/mono#8721
Fixes: mono/mono#8726
Fixes: mono/mono#8759
Fixes: mono/mono#8787
Fixes: mono/mono#8820
Fixes: mono/mono#8848
Fixes: mono/mono#8866
Fixes: mono/mono#8897
Fixes: mono/mono#8915
Fixes: mono/mono#8970
Fixes: mono/mono#8979
Fixes: mono/mono#9023
Fixes: mono/mono#9031
Fixes: mono/mono#9033
Fixes: mono/mono#9179
Fixes: mono/mono#9234
Fixes: mono/mono#9262
Fixes: mono/mono#9277
Fixes: mono/mono#9318
Fixes: mono/mono#9542
Fixes: mono/mono#9753
Fixes: mono/mono#9839
Fixes: mono/mono#9869
Fixes: mono/mono#9870
Fixes: mono/mono#9943
Fixes: mono/mono#9996
Fixes: mono/mono#10000
Fixes: mono/mono#10303
Fixes: mono/mono#10447
Fixes: mono/mono#10483
Fixes: mono/mono#10488
Fixes: xamarin/maccore#628
Fixes: xamarin/maccore#673
Fixes: #1561 (comment)
Fixes: #1845
Fixes: xamarin/xamarin-macios#4347
Fixes: xamarin/xamarin-macios#4617
Fixes: xamarin/xamarin-macios#4618
jonpryor added a commit to xamarin/xamarin-android that referenced this issue Dec 6, 2018
Bumps to mono/api-snapshot@b99fc87.
Bumps to mono/bockbuild@5af573e.
Bumps to mono/boringssl@41221b4.
Bumps to mono/corefx@23d0b58.
Bumps to mono/corert@af496fc.
Bumps to mono/linker@7af03ce.
Bumps to mono/NUnitLite@00e259a.
Bumps to mono/reference-assemblies@9325826.
Bumps to mono/roslyn-binaries@249709f.
Bumps to mono/xunit-binaries@bb58347.

	$ git diff --shortstat b63e5378..23f2024a      # mono 
	 1630 files changed, 50926 insertions(+), 92212 deletions(-)

Fixes: mono/mono#6352
Fixes: mono/mono#6947
Fixes: mono/mono#6992
Fixes: mono/mono#7615
Fixes: mono/mono#8340
Fixes: mono/mono#8407
Fixes: mono/mono#8575
Fixes: mono/mono#8627
Fixes: mono/mono#8707
Fixes: mono/mono#8766
Fixes: mono/mono#8848
Fixes: mono/mono#8866
Fixes: mono/mono#8935
Fixes: mono/mono#9010
Fixes: mono/mono#9023
Fixes: mono/mono#9031
Fixes: mono/mono#9033
Fixes: mono/mono#9106
Fixes: mono/mono#9109
Fixes: mono/mono#9155
Fixes: mono/mono#9179
Fixes: mono/mono#9232
Fixes: mono/mono#9234
Fixes: mono/mono#9262
Fixes: mono/mono#9277
Fixes: mono/mono#9292
Fixes: mono/mono#9318
Fixes: mono/mono#9318
Fixes: mono/mono#9332
Fixes: mono/mono#9407
Fixes: mono/mono#9421
Fixes: mono/mono#9505
Fixes: mono/mono#9542
Fixes: mono/mono#9581
Fixes: mono/mono#9623
Fixes: mono/mono#9684
Fixes: mono/mono#9750
Fixes: mono/mono#9753
Fixes: mono/mono#9772
Fixes: mono/mono#9839
Fixes: mono/mono#9869
Fixes: mono/mono#9921
Fixes: mono/mono#9943
Fixes: mono/mono#9947
Fixes: mono/mono#9973
Fixes: mono/mono#9996
Fixes: mono/mono#10000
Fixes: mono/mono#10031
Fixes: mono/mono#10035
Fixes: mono/mono#10227
Fixes: mono/mono#10243
Fixes: mono/mono#10303
Fixes: mono/mono#10448
Fixes: mono/mono#10483
Fixes: mono/mono#10488
Fixes: mono/mono#10863
Fixes: mono/mono#11123
Fixes: mono/mono#11138
Fixes? mono/mono#11146
Fixes: mono/mono#11202
Fixes: mono/mono#11378
Fixes: mono/mono#11479
Fixes: mono/mono#11613
Fixes: #1951
Fixes: xamarin/xamarin-macios#4347
Fixes: xamarin/xamarin-macios#4617
Fixes: xamarin/xamarin-macios#4984
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Bugs Week
Archived
3 participants
You can’t perform that action at this time.