From f2ddac4cbc895837ddcc55015fae112f9859cd0a Mon Sep 17 00:00:00 2001 From: Michael Biebl Date: Tue, 20 Oct 2020 22:07:24 +0200 Subject: New upstream version 1.27.91 --- src/platform/nm-linux-platform.c | 25 +++++++++++++++++++- src/platform/tests/test-platform-general.c | 37 ++++++++++++++++++++++++++---- 2 files changed, 57 insertions(+), 5 deletions(-) (limited to 'src/platform') diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 05125fa8..3fa70bbc 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include "nm-std-aux/unaligned.h" @@ -9523,12 +9524,34 @@ constructed(GObject *_object) } } +/* Similar to systemd's path_is_read_only_fs(), at + * https://github.com/systemd/systemd/blob/v246/src/basic/stat-util.c#L132 */ +static int +path_is_read_only_fs(const char *path) +{ + struct statvfs st; + + if (statvfs(path, &st) < 0) + return -errno; + + if (st.f_flag & ST_RDONLY) + return TRUE; + + /* On NFS, statvfs() might not reflect whether we can actually + * write to the remote share. Let's try again with + * access(W_OK) which is more reliable, at least sometimes. */ + if (access(path, W_OK) < 0 && errno == EROFS) + return TRUE; + + return FALSE; +} + NMPlatform * nm_linux_platform_new(gboolean log_with_ptr, gboolean netns_support) { gboolean use_udev = FALSE; - if (nmp_netns_is_initial() && access("/sys", W_OK) == 0) + if (nmp_netns_is_initial() && path_is_read_only_fs("/sys") == FALSE) use_udev = TRUE; return g_object_new(NM_TYPE_LINUX_PLATFORM, diff --git a/src/platform/tests/test-platform-general.c b/src/platform/tests/test-platform-general.c index f98f84c9..703c886e 100644 --- a/src/platform/tests/test-platform-general.c +++ b/src/platform/tests/test-platform-general.c @@ -555,6 +555,20 @@ test_platform_ip_address_pretty_sort_cmp(gconstpointer test_data) gs_free guint64 *rand_map = NULL; gsize i, j; +#if !defined(__amd64__) + /* The test generates a random array of NMPlatformIPXAddress (by crudely randomizing the memory, + * not the structures themself) and then compares the sorted result with the expected output. + * The sole purpose is to ensure that the sorting order stays stable. + * + * This only works on an architecture for which the test was made, otherwise + * the expected data does not match (due to different layout of the structures + * in memory). + * + * That's fine. Skip the test. */ + g_test_skip("skip test on non-amd64 architecture"); + return; +#endif + /* * First we create a list of addresses filled with (stable) random bytes. * We tweak some fields explicitly (stable randomly), so that we cover all @@ -692,14 +706,16 @@ test_platform_ip_address_pretty_sort_cmp(gconstpointer test_data) } if (PRINT_RESULT) { - g_print("\n\n\t\t[%d] = (\n", TEST_DATA_I); + g_print("\n [%d] = (", TEST_DATA_I); for (i = 0; i < ELM_SIZE * N_ADDRESSES;) { - g_print("\t\t\t\""); + if (i > 0) + g_print("\n "); + g_print("\""); for (j = 0; j < 40 && i < ELM_SIZE * N_ADDRESSES; j++, i++) g_print("%02x", addresses[i]); - g_print("\"\n"); + g_print("\""); } - g_print("\t\t),\n\n"); + g_print("),\n"); return; } @@ -713,6 +729,19 @@ test_platform_ip_address_pretty_sort_cmp(gconstpointer test_data) NULL, 0, &bin_len); + + if (bin_len != ELM_SIZE * N_ADDRESSES || memcmp(addresses, bin_arr, bin_len) != 0) { + char *addresses_str = nm_utils_bin2hexstr(addresses, ELM_SIZE * N_ADDRESSES, -1); + + g_error(">>> test_platform_ip_address_pretty_sort_cmp() will fail:\n" + ">>> addresses[%zu]: %s\n" + ">>> expected [%zu]: %s\n", + ELM_SIZE * N_ADDRESSES, + addresses_str, + bin_len, + EXPECTED_BUFFER[TEST_DATA_I]); + } + g_assert_cmpmem(addresses, ELM_SIZE * N_ADDRESSES, bin_arr, bin_len); } } -- cgit 1.3.0-6-gf8a5