Check process success locally for adb commands
Remove sc_process_check_success() from the process API, it is too specific.
This commit is contained in:
parent
680d2cc940
commit
904f0ae61e
5 changed files with 44 additions and 62 deletions
|
@ -111,6 +111,43 @@ show_adb_err_msg(enum sc_process_result err, const char *const argv[]) {
|
|||
free(buf);
|
||||
}
|
||||
|
||||
static bool
|
||||
process_check_success_internal(sc_pid pid, const char *name, bool close) {
|
||||
if (pid == SC_PROCESS_NONE) {
|
||||
LOGE("Could not execute \"%s\"", name);
|
||||
return false;
|
||||
}
|
||||
sc_exit_code exit_code = sc_process_wait(pid, close);
|
||||
if (exit_code) {
|
||||
if (exit_code != SC_EXIT_CODE_NONE) {
|
||||
LOGE("\"%s\" returned with value %" SC_PRIexitcode, name,
|
||||
exit_code);
|
||||
} else {
|
||||
LOGE("\"%s\" exited unexpectedly", name);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
process_check_success_intr(struct sc_intr *intr, sc_pid pid, const char *name) {
|
||||
if (!sc_intr_set_process(intr, pid)) {
|
||||
// Already interrupted
|
||||
return false;
|
||||
}
|
||||
|
||||
// Always pass close=false, interrupting would be racy otherwise
|
||||
bool ret = process_check_success_internal(pid, name, false);
|
||||
|
||||
sc_intr_set_process(intr, SC_PROCESS_NONE);
|
||||
|
||||
// Close separately
|
||||
sc_process_close(pid);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const char **
|
||||
adb_create_argv(const char *serial, const char *const adb_cmd[], size_t len) {
|
||||
const char **argv = malloc((len + 4) * sizeof(*argv));
|
||||
|
@ -255,43 +292,41 @@ bool
|
|||
adb_forward(struct sc_intr *intr, const char *serial, uint16_t local_port,
|
||||
const char *device_socket_name) {
|
||||
sc_pid pid = adb_exec_forward(serial, local_port, device_socket_name);
|
||||
return sc_process_check_success_intr(intr, pid, "adb forward", true);
|
||||
return process_check_success_intr(intr, pid, "adb forward");
|
||||
}
|
||||
|
||||
bool
|
||||
adb_forward_remove(struct sc_intr *intr, const char *serial,
|
||||
uint16_t local_port) {
|
||||
sc_pid pid = adb_exec_forward_remove(serial, local_port);
|
||||
return sc_process_check_success_intr(intr, pid, "adb forward --remove",
|
||||
true);
|
||||
return process_check_success_intr(intr, pid, "adb forward --remove");
|
||||
}
|
||||
|
||||
bool
|
||||
adb_reverse(struct sc_intr *intr, const char *serial,
|
||||
const char *device_socket_name, uint16_t local_port) {
|
||||
sc_pid pid = adb_exec_reverse(serial, device_socket_name, local_port);
|
||||
return sc_process_check_success_intr(intr, pid, "adb reverse", true);
|
||||
return process_check_success_intr(intr, pid, "adb reverse");
|
||||
}
|
||||
|
||||
bool
|
||||
adb_reverse_remove(struct sc_intr *intr, const char *serial,
|
||||
const char *device_socket_name) {
|
||||
sc_pid pid = adb_exec_reverse_remove(serial, device_socket_name);
|
||||
return sc_process_check_success_intr(intr, pid, "adb reverse --remove",
|
||||
true);
|
||||
return process_check_success_intr(intr, pid, "adb reverse --remove");
|
||||
}
|
||||
|
||||
bool
|
||||
adb_push(struct sc_intr *intr, const char *serial, const char *local,
|
||||
const char *remote) {
|
||||
sc_pid pid = adb_exec_push(serial, local, remote);
|
||||
return sc_process_check_success_intr(intr, pid, "adb push", true);
|
||||
return process_check_success_intr(intr, pid, "adb push");
|
||||
}
|
||||
|
||||
bool
|
||||
adb_install(struct sc_intr *intr, const char *serial, const char *local) {
|
||||
sc_pid pid = adb_exec_install(serial, local);
|
||||
return sc_process_check_success_intr(intr, pid, "adb install", true);
|
||||
return process_check_success_intr(intr, pid, "adb install");
|
||||
}
|
||||
|
||||
char *
|
||||
|
@ -307,8 +342,7 @@ adb_get_serialno(struct sc_intr *intr) {
|
|||
ssize_t r = sc_pipe_read_all_intr(intr, pid, pout, buf, sizeof(buf));
|
||||
sc_pipe_close(pout);
|
||||
|
||||
bool ok =
|
||||
sc_process_check_success_intr(intr, pid, "adb get-serialno", true);
|
||||
bool ok = process_check_success_intr(intr, pid, "adb get-serialno");
|
||||
if (!ok) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -9,25 +9,6 @@ sc_process_execute(const char *const argv[], sc_pid *pid) {
|
|||
return sc_process_execute_p(argv, pid, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
bool
|
||||
sc_process_check_success(sc_pid pid, const char *name, bool close) {
|
||||
if (pid == SC_PROCESS_NONE) {
|
||||
LOGE("Could not execute \"%s\"", name);
|
||||
return false;
|
||||
}
|
||||
sc_exit_code exit_code = sc_process_wait(pid, close);
|
||||
if (exit_code) {
|
||||
if (exit_code != SC_EXIT_CODE_NONE) {
|
||||
LOGE("\"%s\" returned with value %" SC_PRIexitcode, name,
|
||||
exit_code);
|
||||
} else {
|
||||
LOGE("\"%s\" exited unexpectedly", name);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
ssize_t
|
||||
sc_pipe_read_all(sc_pipe pipe, char *data, size_t len) {
|
||||
size_t copied = 0;
|
||||
|
|
|
@ -107,14 +107,6 @@ sc_process_wait(sc_pid pid, bool close);
|
|||
void
|
||||
sc_process_close(sc_pid pid);
|
||||
|
||||
/**
|
||||
* Convenience function to wait for a successful process execution
|
||||
*
|
||||
* Automatically log process errors with the provided process name.
|
||||
*/
|
||||
bool
|
||||
sc_process_check_success(sc_pid pid, const char *name, bool close);
|
||||
|
||||
/**
|
||||
* Read from the pipe
|
||||
*
|
||||
|
|
|
@ -1,26 +1,5 @@
|
|||
#include "process_intr.h"
|
||||
|
||||
bool
|
||||
sc_process_check_success_intr(struct sc_intr *intr, sc_pid pid,
|
||||
const char *name, bool close) {
|
||||
if (!sc_intr_set_process(intr, pid)) {
|
||||
// Already interrupted
|
||||
return false;
|
||||
}
|
||||
|
||||
// Always pass close=false, interrupting would be racy otherwise
|
||||
bool ret = sc_process_check_success(pid, name, false);
|
||||
|
||||
sc_intr_set_process(intr, SC_PROCESS_NONE);
|
||||
|
||||
if (close) {
|
||||
// Close separately
|
||||
sc_process_close(pid);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ssize_t
|
||||
sc_pipe_read_intr(struct sc_intr *intr, sc_pid pid, sc_pipe pipe, char *data,
|
||||
size_t len) {
|
||||
|
|
|
@ -6,10 +6,6 @@
|
|||
#include "intr.h"
|
||||
#include "process.h"
|
||||
|
||||
bool
|
||||
sc_process_check_success_intr(struct sc_intr *intr, sc_pid pid,
|
||||
const char *name, bool close);
|
||||
|
||||
ssize_t
|
||||
sc_pipe_read_intr(struct sc_intr *intr, sc_pid pid, sc_pipe pipe, char *data,
|
||||
size_t len);
|
||||
|
|
Loading…
Reference in a new issue