Merge pull request #4612 from kumpera/android-changes-part2
authorRodrigo Kumpera <kumpera@users.noreply.github.com>
Wed, 5 Apr 2017 23:59:08 +0000 (16:59 -0700)
committerGitHub <noreply@github.com>
Wed, 5 Apr 2017 23:59:08 +0000 (16:59 -0700)
Fix Android compilation and some tests

mcs/class/System/Test/System.Diagnostics/ProcessTest.cs
mcs/class/System/Test/System.Net/DnsTest.cs
mono/metadata/w32file-unix.c
mono/metadata/w32process-unix-default.c
mono/metadata/w32process-unix-osx.c
mono/metadata/w32process-unix.c
mono/utils/mono-os-mutex.h

index be41016a4d2e1325995f6ca240d2c728f152f623..8871d4aa1ea1e3453009d77c825a26a0681eefe9 100644 (file)
@@ -1123,7 +1123,7 @@ namespace MonoTests.System.Diagnostics
                }
 
                [Test]
-               [ExpectedException(typeof(InvalidOperationException))]
+               [NUnit.Framework.Category ("NotWorking")] //Getting the name of init works fine on Android and Linux, but fails on OSX, SELinux and iOS
                public void HigherPrivilegeProcessName ()
                {
                        if (!RunningOnUnix)
@@ -1133,6 +1133,7 @@ namespace MonoTests.System.Diagnostics
                }
 
                [Test]
+               [NUnit.Framework.Category ("AndroidNotWorking")] //SELinux makes probing the parent process impossible
                public void NonChildProcessWaitForExit ()
                {
                        if (!RunningOnUnix)
@@ -1156,6 +1157,7 @@ namespace MonoTests.System.Diagnostics
                }
 
                [Test]
+               [NUnit.Framework.Category ("AndroidNotWorking")] //SELinux makes probing the parent process impossible
                public void NonChildProcessName ()
                {
                        if (!RunningOnUnix)
@@ -1170,6 +1172,7 @@ namespace MonoTests.System.Diagnostics
                }
 
                [Test]
+               [NUnit.Framework.Category ("AndroidNotWorking")] //SELinux makes probing the parent process impossible
                public void NonChildProcessId ()
                {
                        if (!RunningOnUnix)
index fef014541882d3011f1d7bbcd4ea466b8161c2f3..ebafede87590bda64fe31acaa8021f064ef53f5f 100644 (file)
@@ -37,7 +37,7 @@ namespace MonoTests.System.Net
                        IAsyncResult async = Dns.BeginGetHostByName (site1Name, null, null);\r
                        IPHostEntry entry = Dns.EndGetHostByName (async);\r
                        SubTestValidIPHostEntry (entry);\r
-                       Assert.IsTrue (entry.HostName == "google-public-dns-a.google.com");\r
+                       Assert.AreEqual ("google-public-dns-a.google.com", entry.HostName, "#1");\r
                }\r
 \r
                [Test]\r
@@ -219,26 +219,13 @@ namespace MonoTests.System.Net
 #if FEATURE_NO_BSD_SOCKETS\r
                [ExpectedException (typeof (PlatformNotSupportedException))]\r
 #endif\r
+               [NUnit.Framework.Category ("AndroidNotWorking")] //Some Android devices like to return catch-all IPs for invalid host names.\r
                public void GetHostByName ()\r
                {\r
                        SubTestGetHostByName (site1Name, site1Dot);\r
                        SubTestGetHostByName (site2Name, site2Dot);\r
                        try {\r
                                var entry = Dns.GetHostByName (noneExistingSite);\r
-                               /*\r
-                                * Work around broken t-online.de DNS Server.\r
-                                * \r
-                                * T-Online's DNS Server for DSL Customers resolves\r
-                                * non-exisitng domain names to\r
-                                * http://navigationshilfe1.t-online.de/dnserror?url=....\r
-                                * instead of reporting an error.\r
-                                */\r
-                               var navigationshilfe1 = IPAddress.Parse ("80.156.86.78");\r
-                               var navigationshilfe2 = IPAddress.Parse ("62.157.140.133");\r
-                               foreach (var addr in entry.AddressList) {\r
-                                       if (addr.Equals (navigationshilfe1) || addr.Equals (navigationshilfe2))\r
-                                               return;\r
-                               }\r
                                Assert.Fail ("Should raise a SocketException (assuming that '" + noneExistingSite + "' does not exist)");\r
                        } catch (SocketException) {\r
                        }\r
index 734b43b41f629ccad056873ed12050c78d9db1a1..f6e4d2df5138873927882d9bd3cda436dcba411b 100644 (file)
@@ -3111,9 +3111,6 @@ mono_w32file_get_std_handle (gint stdhandle)
                        mono_w32error_set_last (ERROR_NO_MORE_FILES);
                        goto done;
                }
-       } else {
-               /* Add a reference to this handle */
-               mono_w32handle_ref (handle);
        }
        
   done:
index 50384b8424431d01e92ef16a28539efe994486d5..3bc10906b8cf008b7dfeac476ec147708730d5e7 100644 (file)
@@ -152,8 +152,10 @@ mono_w32process_get_modules (pid_t pid)
        guint64 device;
 
        fp = open_process_map (pid, "r");
-       if (!fp)
+       if (!fp) {
+               mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Can't open process map file for pid %d", __func__, pid);
                return NULL;
+       }
 
        while (fgets (buf, sizeof(buf), fp)) {
                p = buf;
index 9c4bdc25f7fc872dbce66531a984a8c61b9384b8..481d228dd2046c9fd15863474f86912295ca7d25 100644 (file)
@@ -8,6 +8,7 @@
 #ifdef USE_OSX_BACKEND
 
 #include <errno.h>
+#include <unistd.h>
 #include <sys/time.h>
 #include <sys/proc.h>
 #include <sys/sysctl.h>
@@ -120,9 +121,13 @@ mono_w32process_get_modules (pid_t pid)
 {
        GSList *ret = NULL;
        MonoW32ProcessModule *mod;
-       guint32 count = _dyld_image_count ();
+       guint32 count;
        int i = 0;
 
+       if (pid != getpid ())
+               return NULL;
+
+       count = _dyld_image_count ();
        for (i = 0; i < count; i++) {
 #if SIZEOF_VOID_P == 8
                const struct mach_header_64 *hdr;
index 642f77a7ac05941f27fb9ce4bb95adc15234b00c..596af9b321d07ae1945e3e4d46e55a52c5b4d8fb 100644 (file)
@@ -1171,10 +1171,10 @@ mono_w32process_module_get_filename (gpointer process, gpointer module, gunichar
        bytes += 2;
 
        if (size < bytes) {
-               mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Size %d smaller than needed (%ld); truncating", __func__, size, bytes);
+               mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Size %d smaller than needed (%zd); truncating", __func__, size, bytes);
                memcpy (basename, proc_path, size);
        } else {
-               mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Size %d larger than needed (%ld)", __func__, size, bytes);
+               mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Size %d larger than needed (%zd)", __func__, size, bytes);
                memcpy (basename, proc_path, bytes);
        }
 
@@ -1197,8 +1197,8 @@ mono_w32process_module_get_name (gpointer process, gpointer module, gunichar2 *b
        char *pname = NULL;
        gboolean res;
 
-       mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Getting module base name, process handle %p module %p",
-                  __func__, process, module);
+       mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Getting module base name, process handle %p module %p basename %p size %d",
+                  __func__, process, module, basename, size);
 
        size = size * sizeof (gunichar2); /* adjust for unicode characters */
 
@@ -1215,7 +1215,8 @@ mono_w32process_module_get_name (gpointer process, gpointer module, gunichar2 *b
        pname = g_strdup (process_handle->pname);
 
        mods = mono_w32process_get_modules (pid);
-       if (!mods) {
+       if (!mods && module != NULL) {
+               mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Can't get modules %p", __func__, process);
                g_free (pname);
                return 0;
        }
@@ -1236,11 +1237,14 @@ mono_w32process_module_get_name (gpointer process, gpointer module, gunichar2 *b
        }
 
        if (procname_ext == NULL) {
+               mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Can't find procname_ext from procmods %p", __func__, process);
                /* If it's *still* null, we might have hit the
                 * case where reading /proc/$pid/maps gives an
                 * empty file for this user.
                 */
                procname_ext = mono_w32process_get_name (pid);
+               if (!procname_ext)
+                       mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Can't find procname_ext from proc_get_name %p pid %d", __func__, process, pid);
        }
 
        g_slist_free (mods);
@@ -1252,6 +1256,7 @@ mono_w32process_module_get_name (gpointer process, gpointer module, gunichar2 *b
 
                procname = mono_unicode_from_external (procname_ext, &bytes);
                if (procname == NULL) {
+                       mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Can't get procname %p", __func__, process);
                        /* bugger */
                        g_free (procname_ext);
                        return 0;
@@ -1263,11 +1268,11 @@ mono_w32process_module_get_name (gpointer process, gpointer module, gunichar2 *b
                bytes += 2;
 
                if (size < bytes) {
-                       mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Size %d smaller than needed (%ld); truncating", __func__, size, bytes);
+                       mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Size %d smaller than needed (%zd); truncating", __func__, size, bytes);
 
                        memcpy (basename, procname, size);
                } else {
-                       mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Size %d larger than needed (%ld)",
+                       mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Size %d larger than needed (%zd)",
                                   __func__, size, bytes);
 
                        memcpy (basename, procname, bytes);
@@ -1279,6 +1284,7 @@ mono_w32process_module_get_name (gpointer process, gpointer module, gunichar2 *b
                return len;
        }
 
+       mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Can't find procname_ext %p", __func__, process);
        return 0;
 }
 
@@ -2314,7 +2320,6 @@ mono_w32process_set_cli_launcher (gchar *path)
 gpointer
 ves_icall_Microsoft_Win32_NativeMethods_GetCurrentProcess (void)
 {
-       mono_w32handle_ref (current_process);
        return current_process;
 }
 
index 86b6926dc3ec8de59f36cce2b10901114cd4ef19..d6c5250256a84f7b504390c2697b3da61df5042c 100644 (file)
@@ -41,6 +41,10 @@ G_BEGIN_DECLS
 
 #if !defined(HOST_WIN32)
 
+#if !defined(CLOCK_MONOTONIC) || defined(PLATFORM_MACOSX) || defined(PLATFORM_ANDROID)
+#define BROKEN_CLOCK_SOURCE
+#endif
+
 typedef pthread_mutex_t mono_mutex_t;
 typedef pthread_cond_t mono_cond_t;
 
@@ -124,7 +128,7 @@ mono_os_cond_init (mono_cond_t *cond)
 {
        int res;
 
-#if !defined(CLOCK_MONOTONIC) || defined(PLATFORM_MACOSX)
+#ifdef BROKEN_CLOCK_SOURCE
        res = pthread_cond_init (cond, NULL);
        if (G_UNLIKELY (res != 0))
                g_error ("%s: pthread_cond_init failed with \"%s\" (%d)", __func__, g_strerror (res), res);
@@ -174,7 +178,7 @@ mono_os_cond_wait (mono_cond_t *cond, mono_mutex_t *mutex)
 static inline int
 mono_os_cond_timedwait (mono_cond_t *cond, mono_mutex_t *mutex, guint32 timeout_ms)
 {
-#if !defined(CLOCK_MONOTONIC) || defined(PLATFORM_MACOSX)
+#ifdef BROKEN_CLOCK_SOURCE
        struct timeval tv;
 #endif
        struct timespec ts;
@@ -187,7 +191,7 @@ mono_os_cond_timedwait (mono_cond_t *cond, mono_mutex_t *mutex, guint32 timeout_
 
        /* ms = 10^-3, us = 10^-6, ns = 10^-9 */
 
-#if !defined(CLOCK_MONOTONIC) || defined(PLATFORM_MACOSX)
+#ifdef BROKEN_CLOCK_SOURCE
        /* clock_gettime is not supported in MAC OS x */
        res = gettimeofday (&tv, NULL);
        if (G_UNLIKELY (res != 0))