Revert "Add getgroups()/setgroups() to libcore.Os"
These (@hide) methods are unused, and the team who initially requested
them no longer need them. Also, the tests for setgroups recently
started failing (b/77599196).
This reverts commit 44177e6982a62506127a857070a2452956c3f0f1.
Bug: 77599196
Test: Treehugger
(cherry picked from commit 1925ee9be8abc4898626a14e54dde70015e0ed53)
Change-Id: Ia22ae6ab91503b221dd9fc8232c6fe651b25689e
Merged-In: Ia22ae6ab91503b221dd9fc8232c6fe651b25689e
diff --git a/luni/src/main/java/libcore/io/ForwardingOs.java b/luni/src/main/java/libcore/io/ForwardingOs.java
index ce88a3b..f141694 100644
--- a/luni/src/main/java/libcore/io/ForwardingOs.java
+++ b/luni/src/main/java/libcore/io/ForwardingOs.java
@@ -91,7 +91,6 @@
public int getegid() { return os.getegid(); }
public int geteuid() { return os.geteuid(); }
public int getgid() { return os.getgid(); }
- public int[] getgroups() throws ErrnoException { return os.getgroups(); }
public String getenv(String name) { return os.getenv(name); }
public String getnameinfo(InetAddress address, int flags) throws GaiException { return os.getnameinfo(address, flags); }
public SocketAddress getpeername(FileDescriptor fd) throws ErrnoException { return os.getpeername(fd); }
@@ -162,7 +161,6 @@
public void setenv(String name, String value, boolean overwrite) throws ErrnoException { os.setenv(name, value, overwrite); }
public void seteuid(int euid) throws ErrnoException { os.seteuid(euid); }
public void setgid(int gid) throws ErrnoException { os.setgid(gid); }
- public void setgroups(int[] gids) throws ErrnoException { os.setgroups(gids); }
public void setpgid(int pid, int pgid) throws ErrnoException { os.setpgid(pid, pgid); }
public void setregid(int rgid, int egid) throws ErrnoException { os.setregid(rgid, egid); }
public void setreuid(int ruid, int euid) throws ErrnoException { os.setreuid(ruid, euid); }
diff --git a/luni/src/main/java/libcore/io/Linux.java b/luni/src/main/java/libcore/io/Linux.java
index de3b103..807e5a2 100644
--- a/luni/src/main/java/libcore/io/Linux.java
+++ b/luni/src/main/java/libcore/io/Linux.java
@@ -82,7 +82,6 @@
public native int getegid();
public native int geteuid();
public native int getgid();
- public native int[] getgroups() throws ErrnoException;
public native String getenv(String name);
public native String getnameinfo(InetAddress address, int flags) throws GaiException;
public native SocketAddress getpeername(FileDescriptor fd) throws ErrnoException;
@@ -236,7 +235,6 @@
public native void setenv(String name, String value, boolean overwrite) throws ErrnoException;
public native void seteuid(int euid) throws ErrnoException;
public native void setgid(int gid) throws ErrnoException;
- public native void setgroups(int[] gids) throws ErrnoException;
public native void setpgid(int pid, int pgid) throws ErrnoException;
public native void setregid(int rgid, int egid) throws ErrnoException;
public native void setreuid(int ruid, int euid) throws ErrnoException;
diff --git a/luni/src/main/java/libcore/io/Os.java b/luni/src/main/java/libcore/io/Os.java
index 194851f..61584b4 100644
--- a/luni/src/main/java/libcore/io/Os.java
+++ b/luni/src/main/java/libcore/io/Os.java
@@ -76,10 +76,6 @@
public int getegid();
public int geteuid();
public int getgid();
- /* Should the number of groups change during the execution of this call, the call may
- return an arbitrary subset. This may be worth reconsidering should this be exposed
- as public API. */
- public int[] getgroups() throws ErrnoException;
public String getenv(String name);
/* TODO: break into getnameinfoHost and getnameinfoService? */
public String getnameinfo(InetAddress address, int flags) throws GaiException;
@@ -152,7 +148,6 @@
public void setenv(String name, String value, boolean overwrite) throws ErrnoException;
public void seteuid(int euid) throws ErrnoException;
public void setgid(int gid) throws ErrnoException;
- public void setgroups(int[] gids) throws ErrnoException;
public void setpgid(int pid, int pgid) throws ErrnoException;
public void setregid(int rgid, int egid) throws ErrnoException;
public void setreuid(int ruid, int euid) throws ErrnoException;
diff --git a/luni/src/main/native/libcore_io_Linux.cpp b/luni/src/main/native/libcore_io_Linux.cpp
index 04954b9..30da35c 100644
--- a/luni/src/main/native/libcore_io_Linux.cpp
+++ b/luni/src/main/native/libcore_io_Linux.cpp
@@ -19,7 +19,6 @@
#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h>
-#include <grp.h>
#include <ifaddrs.h>
#include <linux/rtnetlink.h>
#include <net/if.h>
@@ -1322,24 +1321,6 @@
return getgid();
}
-static jintArray Linux_getgroups(JNIEnv* env, jobject) {
- int ngrps = throwIfMinusOne(env, "getgroups", getgroups(0, nullptr));
- if (ngrps == -1) {
- return NULL;
- }
- std::vector<gid_t> groups(ngrps, 0);
- ngrps = throwIfMinusOne(env, "getgroups", getgroups(ngrps, &groups[0]));
- if (ngrps == -1) {
- return NULL;
- }
- jintArray out = env->NewIntArray(ngrps);
- if ((out != NULL) && (ngrps > 0)) {
- env->SetIntArrayRegion(out, 0, ngrps, reinterpret_cast<int*>(&groups[0]));
- }
-
- return out;
-}
-
static jstring Linux_getenv(JNIEnv* env, jobject, jstring javaName) {
ScopedUtfChars name(env, javaName);
if (name.c_str() == NULL) {
@@ -2179,13 +2160,6 @@
throwIfMinusOne(env, "setgid", TEMP_FAILURE_RETRY(setgid(gid)));
}
-static void Linux_setgroups(JNIEnv* env, jobject, jintArray gids) {
- size_t ngrps = gids == NULL ? 0 : env->GetArrayLength(gids);
- std::vector<gid_t> groups(ngrps, 0);
- env->GetIntArrayRegion(gids, 0, ngrps, reinterpret_cast<int*>(&groups[0]));
- throwIfMinusOne(env, "setgroups", setgroups(ngrps, &groups[0]));
-}
-
static void Linux_setpgid(JNIEnv* env, jobject, jint pid, int pgid) {
throwIfMinusOne(env, "setpgid", TEMP_FAILURE_RETRY(setpgid(pid, pgid)));
}
@@ -2524,7 +2498,6 @@
NATIVE_METHOD(Linux, getegid, "()I"),
NATIVE_METHOD(Linux, geteuid, "()I"),
NATIVE_METHOD(Linux, getgid, "()I"),
- NATIVE_METHOD(Linux, getgroups, "()[I"),
NATIVE_METHOD(Linux, getenv, "(Ljava/lang/String;)Ljava/lang/String;"),
NATIVE_METHOD(Linux, getnameinfo, "(Ljava/net/InetAddress;I)Ljava/lang/String;"),
NATIVE_METHOD(Linux, getpeername, "(Ljava/io/FileDescriptor;)Ljava/net/SocketAddress;"),
@@ -2590,7 +2563,6 @@
NATIVE_METHOD(Linux, setenv, "(Ljava/lang/String;Ljava/lang/String;Z)V"),
NATIVE_METHOD(Linux, seteuid, "(I)V"),
NATIVE_METHOD(Linux, setgid, "(I)V"),
- NATIVE_METHOD(Linux, setgroups, "([I)V"),
NATIVE_METHOD(Linux, setpgid, "(II)V"),
NATIVE_METHOD(Linux, setregid, "(II)V"),
NATIVE_METHOD(Linux, setreuid, "(II)V"),
diff --git a/luni/src/test/java/libcore/libcore/io/OsTest.java b/luni/src/test/java/libcore/libcore/io/OsTest.java
index cc2c81c..ab8f16e 100644
--- a/luni/src/test/java/libcore/libcore/io/OsTest.java
+++ b/luni/src/test/java/libcore/libcore/io/OsTest.java
@@ -926,20 +926,6 @@
return f;
}
- public void test_getgroups() throws Exception {
- int[] gids = Libcore.os.getgroups();
- assertNotNull(gids);
- }
-
- public void test_setgroups() throws Exception {
- try {
- Libcore.os.setgroups(new int[] {-1});
- fail();
- } catch (ErrnoException expected) {
- assertEquals(EPERM, expected.errno);
- }
- }
-
public void test_odirect() throws Exception {
File testFile = createTempFile("test_odirect", "");
try {