Skip to content

Commit 9f0e649

Browse files
committed
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
1 parent 5186681 commit 9f0e649

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

diagnose_usb/diagnose_usb.cpp

+21-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
#include <errno.h>
2020
#include <unistd.h>
2121

22+
#include <algorithm>
2223
#include <string>
24+
#include <vector>
2325

2426
#include <android-base/stringprintf.h>
2527

@@ -45,9 +47,25 @@ static std::string GetUdevProblem() {
4547
return "";
4648
}
4749

48-
// getgroups(2) indicates that the GNU group_member(3) may not check the egid so we check it
49-
// additionally just to be sure.
50-
if (group_member(plugdev_group->gr_gid) || getegid() == plugdev_group->gr_gid) {
50+
int ngroups = getgroups(0, nullptr);
51+
if (ngroups < 0) {
52+
perror("failed to get groups list size");
53+
return "";
54+
}
55+
56+
std::vector<gid_t> groups(ngroups);
57+
ngroups = getgroups(groups.size(), groups.data());
58+
if (ngroups < 0) {
59+
perror("failed to get groups list");
60+
return "";
61+
}
62+
63+
groups.resize(ngroups);
64+
65+
// getgroups(2) indicates that the egid may not be included so we check it additionally just
66+
// to be sure.
67+
if (std::find(groups.begin(), groups.end(), plugdev_group->gr_gid) != groups.end() ||
68+
getegid() == plugdev_group->gr_gid) {
5169
// The user is in plugdev so the problem is likely with the udev rules.
5270
return "missing udev rules? user is in the plugdev group";
5371
}

0 commit comments

Comments
 (0)