Merge ~alfonsosanchezbeato/snappy-hwe-snaps/+git/network-manager:use-udev into ~snappy-hwe-team/snappy-hwe-snaps/+git/network-manager:network-manager/xenial/1.2.2

Proposed by Alfonso Sanchez-Beato
Status: Merged
Approved by: Alfonso Sanchez-Beato
Approved revision: 6d47c8c73bbd06439fb008ad844cc74aa3f93e84
Merged at revision: c96d6d2be8d333c98b10665f0004bbccfbf073e0
Proposed branch: ~alfonsosanchezbeato/snappy-hwe-snaps/+git/network-manager:use-udev
Merge into: ~snappy-hwe-team/snappy-hwe-snaps/+git/network-manager:network-manager/xenial/1.2.2
Diff against target: 49 lines (+24/-1)
1 file modified
src/platform/nm-linux-platform.c (+24/-1)
Reviewer Review Type Date Requested Status
Alfonso Sanchez-Beato continuous-integration Approve
System Enablement Bot continuous-integration Needs Fixing
Review via email: mp+394268@code.launchpad.net

Commit message

platform: use also statvfs() to check for udevd

Check whether or not there is a running udevd by using statvfs() on
"/sys" and use access() as a fallback. This is in line with what is
done by systemd [1] and helps in case NM is not really running in a
container but has been confined by a MAC so it does not have full
access to sysfs (access() returns EACCES). Fixes LP:#1712918,
LP:#1893184.

Upstream: https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/commit/9c8275bedcc98d789fa83d2817b9e8ff58f3e7b6

[1] https://github.com/systemd/systemd/blob/v246/src/basic/stat-util.c#L132

Description of the change

platform: use also statvfs() to check for udevd

Check whether or not there is a running udevd by using statvfs() on
"/sys" and use access() as a fallback. This is in line with what is
done by systemd [1] and helps in case NM is not really running in a
container but has been confined by a MAC so it does not have full
access to sysfs (access() returns EACCES). Fixes LP:#1712918,
LP:#1893184.

Upstream: https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/commit/9c8275bedcc98d789fa83d2817b9e8ff58f3e7b6

[1] https://github.com/systemd/systemd/blob/v246/src/basic/stat-util.c#L132

To post a comment you must log in.
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Alfonso Sanchez-Beato (alfonsosanchezbeato) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c
2index eade769..391ae2e 100644
3--- a/src/platform/nm-linux-platform.c
4+++ b/src/platform/nm-linux-platform.c
5@@ -24,6 +24,7 @@
6 #include <errno.h>
7 #include <unistd.h>
8 #include <sys/socket.h>
9+#include <sys/statvfs.h>
10 #include <sys/ioctl.h>
11 #include <fcntl.h>
12 #include <dlfcn.h>
13@@ -6164,6 +6165,28 @@ handle_udev_event (GUdevClient *client,
14
15 /******************************************************************/
16
17+/* Similar to systemd's path_is_read_only_fs(), at
18+ * https://github.com/systemd/systemd/blob/v246/src/basic/stat-util.c#L132 */
19+static int
20+path_is_read_only_fs(const char *path)
21+{
22+ struct statvfs st;
23+
24+ if (statvfs (path, &st) < 0)
25+ return -errno;
26+
27+ if (st.f_flag & ST_RDONLY)
28+ return TRUE;
29+
30+ /* On NFS, statvfs() might not reflect whether we can actually
31+ * write to the remote share. Let's try again with
32+ * access(W_OK) which is more reliable, at least sometimes. */
33+ if (access (path, W_OK) < 0 && errno == EROFS)
34+ return TRUE;
35+
36+ return FALSE;
37+}
38+
39 static void
40 nm_linux_platform_init (NMLinuxPlatform *self)
41 {
42@@ -6171,7 +6194,7 @@ nm_linux_platform_init (NMLinuxPlatform *self)
43 gboolean use_udev;
44
45 use_udev = nmp_netns_is_initial ()
46- && access ("/sys", W_OK) == 0;
47+ && path_is_read_only_fs ("/sys") == FALSE;
48
49 self->priv = priv;
50

Subscribers

People subscribed via source and target branches