From 5186681f58ff0b026dc7228d71b032116c10c8b4 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Wed, 15 Dec 2021 14:55:05 -0800 Subject: [PATCH 1/2] Support building fs_mgr against musl Support building fs_mgr against musl by including the missing sys/types.h header. Bug: 190084016 Test: m USE_HOST_MUSL=true host-native Change-Id: Ie3b3907b1c60ba550c04e8780f11b7adf09a6471 --- fs_mgr/libdm/include/libdm/dm.h | 1 + 1 file changed, 1 insertion(+) diff --git a/fs_mgr/libdm/include/libdm/dm.h b/fs_mgr/libdm/include/libdm/dm.h index 332fcf5bf..1057d7f7a 100644 --- a/fs_mgr/libdm/include/libdm/dm.h +++ b/fs_mgr/libdm/include/libdm/dm.h @@ -24,6 +24,7 @@ #include #include #include +#include #include #include From 9f0e6493e5e75c65cff1d456d11243b1114ce57a Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 16 Dec 2021 13:30:28 -0800 Subject: [PATCH 2/2] Support building diagnose_usb against musl Support building diagnose_usb against musl by reimplementing group_member, which doesn't exist in musl and isn't used anywhere else in the tree. Bug: 190084016 Test: m USE_HOST_MUSL=true host-native Change-Id: Id0fe51d0bd8677561d0bbdb72d3b1a956127a11c --- diagnose_usb/diagnose_usb.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/diagnose_usb/diagnose_usb.cpp b/diagnose_usb/diagnose_usb.cpp index 35edb5e05..5716323ce 100644 --- a/diagnose_usb/diagnose_usb.cpp +++ b/diagnose_usb/diagnose_usb.cpp @@ -19,7 +19,9 @@ #include #include +#include #include +#include #include @@ -45,9 +47,25 @@ static std::string GetUdevProblem() { return ""; } - // getgroups(2) indicates that the GNU group_member(3) may not check the egid so we check it - // additionally just to be sure. - if (group_member(plugdev_group->gr_gid) || getegid() == plugdev_group->gr_gid) { + int ngroups = getgroups(0, nullptr); + if (ngroups < 0) { + perror("failed to get groups list size"); + return ""; + } + + std::vector groups(ngroups); + ngroups = getgroups(groups.size(), groups.data()); + if (ngroups < 0) { + perror("failed to get groups list"); + return ""; + } + + groups.resize(ngroups); + + // getgroups(2) indicates that the egid may not be included so we check it additionally just + // to be sure. + if (std::find(groups.begin(), groups.end(), plugdev_group->gr_gid) != groups.end() || + getegid() == plugdev_group->gr_gid) { // The user is in plugdev so the problem is likely with the udev rules. return "missing udev rules? user is in the plugdev group"; }