From 883b5abc7b2a770146683e7e27bf275bd4064511 Mon Sep 17 00:00:00 2001 From: pacien Date: Mon, 20 Jan 2020 17:07:12 +0100 Subject: pass network device fd via unix socket instead of inheritance Workaround for new shared memory restrictions added in Android 10 preventing file descriptor leakage to sub-processes. This change set BREAKS ENCRYPTED PRIVATE KEYS SUPPORT. GitHub: https://github.com/pacien/tincapp/issues/92 --- .../java/org/pacien/tincapp/commands/Executor.kt | 34 +--------------------- 1 file changed, 1 insertion(+), 33 deletions(-) (limited to 'app/src/main/java/org/pacien/tincapp/commands/Executor.kt') diff --git a/app/src/main/java/org/pacien/tincapp/commands/Executor.kt b/app/src/main/java/org/pacien/tincapp/commands/Executor.kt index 29e011f..0a8a774 100644 --- a/app/src/main/java/org/pacien/tincapp/commands/Executor.kt +++ b/app/src/main/java/org/pacien/tincapp/commands/Executor.kt @@ -1,6 +1,6 @@ /* * Tinc App, an Android binding and user interface for the tinc mesh VPN daemon - * Copyright (C) 2017-2018 Pacien TRAN-GIRARD + * Copyright (C) 2017-2020 Pacien TRAN-GIRARD * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -30,42 +30,10 @@ import java.io.InputStreamReader * @author pacien */ internal object Executor { - private const val FAILED = -1 - private const val SUCCESS = 0 - class CommandExecutionException(msg: String) : Exception(msg) - init { - System.loadLibrary("exec") - } - - /** - * @return FAILED (-1) on error, forked child PID otherwise - */ - private external fun forkExec(args: Array): Int - - /** - * @return FAILED (-1) on error, the exit status of the process otherwise - */ - private external fun wait(pid: Int): Int - private fun read(stream: InputStream) = BufferedReader(InputStreamReader(stream)).readLines() - fun forkExec(cmd: Command): CompletableFuture { - val pid = forkExec(cmd.asArray()).also { - if (it == FAILED) throw CommandExecutionException("Could not fork child process.") - } - - return runAsyncTask { - val exitCode = wait(pid) - when (exitCode) { - SUCCESS -> Unit - FAILED -> throw CommandExecutionException("Process terminated abnormally.") - else -> throw CommandExecutionException("Non-zero exit status code ($exitCode).") - } - } - } - fun run(cmd: Command): Process = try { ProcessBuilder(cmd.asList()).start() } catch (e: IOException) { -- cgit v1.2.3