ToolsInstaller: Remove double-checked locking
It can't work and may be crashing the runtime. Use a lock object to avoid exposing the synchronization in the class's interface. Signed-off-by: Samuel Holland <samuel@sholland.org>
This commit is contained in:
parent
d56eda2fd6
commit
09c207b8a3
@ -34,6 +34,7 @@ public final class ToolsInstaller {
|
|||||||
private static final String TAG = "WireGuard/" + ToolsInstaller.class.getSimpleName();
|
private static final String TAG = "WireGuard/" + ToolsInstaller.class.getSimpleName();
|
||||||
|
|
||||||
private final File localBinaryDir;
|
private final File localBinaryDir;
|
||||||
|
private final Object lock = new Object();
|
||||||
private final File nativeLibraryDir;
|
private final File nativeLibraryDir;
|
||||||
private final RootShell rootShell;
|
private final RootShell rootShell;
|
||||||
private Boolean areToolsAvailable;
|
private Boolean areToolsAvailable;
|
||||||
@ -74,10 +75,9 @@ public final class ToolsInstaller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void ensureToolsAvailable() throws FileNotFoundException, NoRootException {
|
public void ensureToolsAvailable() throws FileNotFoundException, NoRootException {
|
||||||
|
synchronized (lock) {
|
||||||
if (areToolsAvailable == null) {
|
if (areToolsAvailable == null) {
|
||||||
synchronized (this) {
|
final int ret = symlink();
|
||||||
if (areToolsAvailable == null) {
|
|
||||||
int ret = symlink();
|
|
||||||
if (ret == OsConstants.EALREADY) {
|
if (ret == OsConstants.EALREADY) {
|
||||||
Log.d(TAG, "Tools were already symlinked into our private binary dir");
|
Log.d(TAG, "Tools were already symlinked into our private binary dir");
|
||||||
areToolsAvailable = true;
|
areToolsAvailable = true;
|
||||||
@ -89,11 +89,10 @@ public final class ToolsInstaller {
|
|||||||
areToolsAvailable = false;
|
areToolsAvailable = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!areToolsAvailable)
|
if (!areToolsAvailable)
|
||||||
throw new FileNotFoundException("Required tools unavailable");
|
throw new FileNotFoundException("Required tools unavailable");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public int install() throws NoRootException {
|
public int install() throws NoRootException {
|
||||||
if (INSTALL_DIR == null)
|
if (INSTALL_DIR == null)
|
||||||
|
Loading…
Reference in New Issue
Block a user