Close process on check success
The interruptible version of the function to check process success (sc_process_check_success_intr()) did not accept a close parameter to avoid a race condition. But as the result, the processes were not closed at all. Add a close parameter, and close the process separately to avoid the race condition.
This commit is contained in:
parent
ee93d2aac1
commit
de50846905
4 changed files with 15 additions and 7 deletions
|
@ -13,27 +13,29 @@ static bool
|
||||||
enable_tunnel_reverse(struct sc_intr *intr, const char *serial,
|
enable_tunnel_reverse(struct sc_intr *intr, const char *serial,
|
||||||
uint16_t local_port) {
|
uint16_t local_port) {
|
||||||
sc_pid pid = adb_reverse(serial, SC_SOCKET_NAME, local_port);
|
sc_pid pid = adb_reverse(serial, SC_SOCKET_NAME, local_port);
|
||||||
return sc_process_check_success_intr(intr, pid, "adb reverse");
|
return sc_process_check_success_intr(intr, pid, "adb reverse", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
disable_tunnel_reverse(struct sc_intr *intr, const char *serial) {
|
disable_tunnel_reverse(struct sc_intr *intr, const char *serial) {
|
||||||
sc_pid pid = adb_reverse_remove(serial, SC_SOCKET_NAME);
|
sc_pid pid = adb_reverse_remove(serial, SC_SOCKET_NAME);
|
||||||
return sc_process_check_success_intr(intr, pid, "adb reverse --remove");
|
return sc_process_check_success_intr(intr, pid, "adb reverse --remove",
|
||||||
|
true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
enable_tunnel_forward(struct sc_intr *intr, const char *serial,
|
enable_tunnel_forward(struct sc_intr *intr, const char *serial,
|
||||||
uint16_t local_port) {
|
uint16_t local_port) {
|
||||||
sc_pid pid = adb_forward(serial, local_port, SC_SOCKET_NAME);
|
sc_pid pid = adb_forward(serial, local_port, SC_SOCKET_NAME);
|
||||||
return sc_process_check_success_intr(intr, pid, "adb forward");
|
return sc_process_check_success_intr(intr, pid, "adb forward", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
disable_tunnel_forward(struct sc_intr *intr, const char *serial,
|
disable_tunnel_forward(struct sc_intr *intr, const char *serial,
|
||||||
uint16_t local_port) {
|
uint16_t local_port) {
|
||||||
sc_pid pid = adb_forward_remove(serial, local_port);
|
sc_pid pid = adb_forward_remove(serial, local_port);
|
||||||
return sc_process_check_success_intr(intr, pid, "adb forward --remove");
|
return sc_process_check_success_intr(intr, pid, "adb forward --remove",
|
||||||
|
true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
|
|
|
@ -114,7 +114,7 @@ push_server(struct sc_intr *intr, const char *serial) {
|
||||||
}
|
}
|
||||||
sc_pid pid = adb_push(serial, server_path, SC_DEVICE_SERVER_PATH);
|
sc_pid pid = adb_push(serial, server_path, SC_DEVICE_SERVER_PATH);
|
||||||
free(server_path);
|
free(server_path);
|
||||||
return sc_process_check_success_intr(intr, pid, "adb push");
|
return sc_process_check_success_intr(intr, pid, "adb push", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
bool
|
bool
|
||||||
sc_process_check_success_intr(struct sc_intr *intr, sc_pid pid,
|
sc_process_check_success_intr(struct sc_intr *intr, sc_pid pid,
|
||||||
const char *name) {
|
const char *name, bool close) {
|
||||||
if (!sc_intr_set_process(intr, pid)) {
|
if (!sc_intr_set_process(intr, pid)) {
|
||||||
// Already interrupted
|
// Already interrupted
|
||||||
return false;
|
return false;
|
||||||
|
@ -12,5 +12,11 @@ sc_process_check_success_intr(struct sc_intr *intr, sc_pid pid,
|
||||||
bool ret = sc_process_check_success(pid, name, false);
|
bool ret = sc_process_check_success(pid, name, false);
|
||||||
|
|
||||||
sc_intr_set_process(intr, SC_PROCESS_NONE);
|
sc_intr_set_process(intr, SC_PROCESS_NONE);
|
||||||
|
|
||||||
|
if (close) {
|
||||||
|
// Close separately
|
||||||
|
sc_process_close(pid);
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,6 @@
|
||||||
|
|
||||||
bool
|
bool
|
||||||
sc_process_check_success_intr(struct sc_intr *intr, sc_pid pid,
|
sc_process_check_success_intr(struct sc_intr *intr, sc_pid pid,
|
||||||
const char *name);
|
const char *name, bool close);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue