Merge "Throw an errno exception when open BPF map failed"
This commit is contained in:
@@ -42,6 +42,8 @@ static jint com_android_networkstack_tethering_BpfMap_bpfFdGet(JNIEnv *env, jobj
|
|||||||
|
|
||||||
jint fd = bpf::bpfFdGet(pathname.c_str(), static_cast<unsigned>(mode));
|
jint fd = bpf::bpfFdGet(pathname.c_str(), static_cast<unsigned>(mode));
|
||||||
|
|
||||||
|
if (fd < 0) jniThrowErrnoException(env, "bpfFdGet", errno);
|
||||||
|
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -388,4 +388,15 @@ public final class BpfMapTest {
|
|||||||
assertEquals(OsConstants.E2BIG, expected.errno);
|
assertEquals(OsConstants.E2BIG, expected.errno);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOpenNonexistentMap() throws Exception {
|
||||||
|
try {
|
||||||
|
final BpfMap<TetherDownstream6Key, Tether6Value> nonexistentMap = new BpfMap<>(
|
||||||
|
"/sys/fs/bpf/tethering/nonexistent", BpfMap.BPF_F_RDWR,
|
||||||
|
TetherDownstream6Key.class, Tether6Value.class);
|
||||||
|
} catch (ErrnoException expected) {
|
||||||
|
assertEquals(OsConstants.ENOENT, expected.errno);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user