Merge "adb: don't use <error.h>."
This commit is contained in:
commit
33eb652783
|
@ -341,3 +341,33 @@ std::string GetLogFilePath() {
|
|||
return android::base::StringPrintf("%s/adb.%u.log", tmp_dir, getuid());
|
||||
#endif
|
||||
}
|
||||
|
||||
[[noreturn]] static void error_exit_va(int error, const char* fmt, va_list va) {
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "%s: ", android::base::Basename(android::base::GetExecutablePath()).c_str());
|
||||
|
||||
vfprintf(stderr, fmt, va);
|
||||
|
||||
if (error != 0) {
|
||||
fprintf(stderr, ": %s", strerror(error));
|
||||
}
|
||||
|
||||
putc('\n', stderr);
|
||||
fflush(stderr);
|
||||
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
void error_exit(const char* fmt, ...) {
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
error_exit_va(0, fmt, va);
|
||||
va_end(va);
|
||||
}
|
||||
|
||||
void perror_exit(const char* fmt, ...) {
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
error_exit_va(errno, fmt, va);
|
||||
va_end(va);
|
||||
}
|
||||
|
|
|
@ -14,8 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef _ADB_UTILS_H_
|
||||
#define _ADB_UTILS_H_
|
||||
#pragma once
|
||||
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
|
@ -47,9 +46,12 @@ std::string dump_packet(const char* name, const char* func, const apacket* p);
|
|||
|
||||
std::string perror_str(const char* msg);
|
||||
|
||||
[[noreturn]] void error_exit(const char* fmt, ...) __attribute__((__format__(__printf__, 1, 2)));
|
||||
[[noreturn]] void perror_exit(const char* fmt, ...) __attribute__((__format__(__printf__, 1, 2)));
|
||||
|
||||
bool set_file_block_mode(int fd, bool block);
|
||||
|
||||
extern int adb_close(int fd);
|
||||
int adb_close(int fd);
|
||||
|
||||
// Given forward/reverse targets, returns true if they look sane. If an error is found, fills
|
||||
// |error| and returns false.
|
||||
|
@ -92,5 +94,3 @@ class BlockingQueue {
|
|||
};
|
||||
|
||||
std::string GetLogFilePath();
|
||||
|
||||
#endif
|
||||
|
|
|
@ -134,7 +134,7 @@ static int install_app_streamed(int argc, const char** argv, bool use_fastdeploy
|
|||
// The last argument must be the APK file
|
||||
const char* file = argv[argc - 1];
|
||||
if (!android::base::EndsWithIgnoreCase(file, ".apk")) {
|
||||
error(1, 0, "filename doesn't end .apk: %s", file);
|
||||
error_exit("filename doesn't end .apk: %s", file);
|
||||
}
|
||||
|
||||
if (use_fastdeploy == true) {
|
||||
|
@ -224,7 +224,7 @@ static int install_app_legacy(int argc, const char** argv, bool use_fastdeploy,
|
|||
}
|
||||
}
|
||||
|
||||
if (last_apk == -1) error(1, 0, "need APK file on command line");
|
||||
if (last_apk == -1) error_exit("need APK file on command line");
|
||||
|
||||
int result = -1;
|
||||
std::vector<const char*> apk_file = {argv[last_apk]};
|
||||
|
@ -311,7 +311,7 @@ int install_app(int argc, const char** argv) {
|
|||
}
|
||||
|
||||
if (installMode == INSTALL_STREAM && _use_legacy_install() == true) {
|
||||
error(1, 0, "Attempting to use streaming install on unsupported device");
|
||||
error_exit("Attempting to use streaming install on unsupported device");
|
||||
}
|
||||
|
||||
if (use_fastdeploy == true && is_reinstall == false) {
|
||||
|
@ -370,7 +370,7 @@ int install_multiple_app(int argc, const char** argv) {
|
|||
}
|
||||
}
|
||||
|
||||
if (first_apk == -1) error(1, 0, "need APK file on command line");
|
||||
if (first_apk == -1) error_exit("need APK file on command line");
|
||||
|
||||
std::string install_cmd;
|
||||
if (_use_legacy_install()) {
|
||||
|
|
|
@ -197,7 +197,7 @@ class BugreportStandardStreamsCallback : public StandardStreamsCallbackInterface
|
|||
};
|
||||
|
||||
int Bugreport::DoIt(int argc, const char** argv) {
|
||||
if (argc > 2) error(1, 0, "usage: adb bugreport [PATH]");
|
||||
if (argc > 2) error_exit("usage: adb bugreport [PATH]");
|
||||
|
||||
// Gets bugreportz version.
|
||||
std::string bugz_stdout, bugz_stderr;
|
||||
|
|
|
@ -71,7 +71,7 @@ DefaultStandardStreamsCallback DEFAULT_STANDARD_STREAMS_CALLBACK(nullptr, nullpt
|
|||
static std::string product_file(const std::string& file) {
|
||||
const char* ANDROID_PRODUCT_OUT = getenv("ANDROID_PRODUCT_OUT");
|
||||
if (ANDROID_PRODUCT_OUT == nullptr) {
|
||||
error(1, 0, "product directory not specified; set $ANDROID_PRODUCT_OUT");
|
||||
error_exit("product directory not specified; set $ANDROID_PRODUCT_OUT");
|
||||
}
|
||||
return std::string{ANDROID_PRODUCT_OUT} + OS_PATH_SEPARATOR_STR + file;
|
||||
}
|
||||
|
@ -684,7 +684,7 @@ static int adb_shell(int argc, const char** argv) {
|
|||
switch (opt) {
|
||||
case 'e':
|
||||
if (!(strlen(optarg) == 1 || strcmp(optarg, "none") == 0)) {
|
||||
error(1, 0, "-e requires a single-character argument or 'none'");
|
||||
error_exit("-e requires a single-character argument or 'none'");
|
||||
}
|
||||
escape_char = (strcmp(optarg, "none") == 0) ? 0 : optarg[0];
|
||||
break;
|
||||
|
@ -932,21 +932,21 @@ static int adb_sideload_host(const char* filename) {
|
|||
*/
|
||||
static int ppp(int argc, const char** argv) {
|
||||
#if defined(_WIN32)
|
||||
error(1, 0, "adb %s not implemented on Win32", argv[0]);
|
||||
error_exit("adb %s not implemented on Win32", argv[0]);
|
||||
__builtin_unreachable();
|
||||
#else
|
||||
if (argc < 2) error(1, 0, "usage: adb %s <adb service name> [ppp opts]", argv[0]);
|
||||
if (argc < 2) error_exit("usage: adb %s <adb service name> [ppp opts]", argv[0]);
|
||||
|
||||
const char* adb_service_name = argv[1];
|
||||
std::string error_message;
|
||||
int fd = adb_connect(adb_service_name, &error_message);
|
||||
if (fd < 0) {
|
||||
error(1, 0, "could not open adb service %s: %s", adb_service_name, error_message.c_str());
|
||||
error_exit("could not open adb service %s: %s", adb_service_name, error_message.c_str());
|
||||
}
|
||||
|
||||
pid_t pid = fork();
|
||||
if (pid == -1) {
|
||||
error(1, errno, "fork failed");
|
||||
perror_exit("fork failed");
|
||||
}
|
||||
|
||||
if (pid == 0) {
|
||||
|
@ -968,7 +968,7 @@ static int ppp(int argc, const char** argv) {
|
|||
adb_close(fd);
|
||||
|
||||
execvp("pppd", (char* const*)ppp_args);
|
||||
error(1, errno, "exec pppd failed");
|
||||
perror_exit("exec pppd failed");
|
||||
}
|
||||
|
||||
// parent side
|
||||
|
@ -1151,7 +1151,7 @@ static int backup(int argc, const char** argv) {
|
|||
/* find, extract, and use any -f argument */
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (!strcmp("-f", argv[i])) {
|
||||
if (i == argc - 1) error(1, 0, "backup -f passed with no filename");
|
||||
if (i == argc - 1) error_exit("backup -f passed with no filename");
|
||||
filename = argv[i+1];
|
||||
for (int j = i+2; j <= argc; ) {
|
||||
argv[i++] = argv[j++];
|
||||
|
@ -1163,7 +1163,7 @@ static int backup(int argc, const char** argv) {
|
|||
|
||||
// Bare "adb backup" or "adb backup -f filename" are not valid invocations ---
|
||||
// a list of packages is required.
|
||||
if (argc < 2) error(1, 0, "backup either needs a list of packages or -all/-shared");
|
||||
if (argc < 2) error_exit("backup either needs a list of packages or -all/-shared");
|
||||
|
||||
adb_unlink(filename);
|
||||
int outFd = adb_creat(filename, 0640);
|
||||
|
@ -1199,7 +1199,7 @@ static int backup(int argc, const char** argv) {
|
|||
}
|
||||
|
||||
static int restore(int argc, const char** argv) {
|
||||
if (argc != 2) error(1, 0, "restore requires an argument");
|
||||
if (argc != 2) error_exit("restore requires an argument");
|
||||
|
||||
const char* filename = argv[1];
|
||||
int tarFd = adb_open(filename, O_RDONLY);
|
||||
|
@ -1253,7 +1253,7 @@ static void parse_push_pull_args(const char** arg, int narg, std::vector<const c
|
|||
} else if (!strcmp(*arg, "--")) {
|
||||
ignore_flags = true;
|
||||
} else {
|
||||
error(1, 0, "unrecognized option '%s'", *arg);
|
||||
error_exit("unrecognized option '%s'", *arg);
|
||||
}
|
||||
}
|
||||
++arg;
|
||||
|
@ -1331,7 +1331,7 @@ int adb_commandline(int argc, const char** argv) {
|
|||
/* this is a special flag used only when the ADB client launches the ADB Server */
|
||||
is_daemon = true;
|
||||
} else if (!strcmp(argv[0], "--reply-fd")) {
|
||||
if (argc < 2) error(1, 0, "--reply-fd requires an argument");
|
||||
if (argc < 2) error_exit("--reply-fd requires an argument");
|
||||
const char* reply_fd_str = argv[1];
|
||||
argc--;
|
||||
argv++;
|
||||
|
@ -1344,7 +1344,7 @@ int adb_commandline(int argc, const char** argv) {
|
|||
if (isdigit(argv[0][2])) {
|
||||
serial = argv[0] + 2;
|
||||
} else {
|
||||
if (argc < 2 || argv[0][2] != '\0') error(1, 0, "-s requires an argument");
|
||||
if (argc < 2 || argv[0][2] != '\0') error_exit("-s requires an argument");
|
||||
serial = argv[1];
|
||||
argc--;
|
||||
argv++;
|
||||
|
@ -1360,7 +1360,7 @@ int adb_commandline(int argc, const char** argv) {
|
|||
}
|
||||
transport_id = strtoll(id, const_cast<char**>(&id), 10);
|
||||
if (*id != '\0') {
|
||||
error(1, 0, "invalid transport id");
|
||||
error_exit("invalid transport id");
|
||||
}
|
||||
} else if (!strcmp(argv[0],"-d")) {
|
||||
transport_type = kTransportUsb;
|
||||
|
@ -1370,7 +1370,7 @@ int adb_commandline(int argc, const char** argv) {
|
|||
gListenAll = 1;
|
||||
} else if (!strncmp(argv[0], "-H", 2)) {
|
||||
if (argv[0][2] == '\0') {
|
||||
if (argc < 2) error(1, 0, "-H requires an argument");
|
||||
if (argc < 2) error_exit("-H requires an argument");
|
||||
server_host_str = argv[1];
|
||||
argc--;
|
||||
argv++;
|
||||
|
@ -1379,7 +1379,7 @@ int adb_commandline(int argc, const char** argv) {
|
|||
}
|
||||
} else if (!strncmp(argv[0], "-P", 2)) {
|
||||
if (argv[0][2] == '\0') {
|
||||
if (argc < 2) error(1, 0, "-P requires an argument");
|
||||
if (argc < 2) error_exit("-P requires an argument");
|
||||
server_port_str = argv[1];
|
||||
argc--;
|
||||
argv++;
|
||||
|
@ -1387,7 +1387,7 @@ int adb_commandline(int argc, const char** argv) {
|
|||
server_port_str = argv[0] + 2;
|
||||
}
|
||||
} else if (!strcmp(argv[0], "-L")) {
|
||||
if (argc < 2) error(1, 0, "-L requires an argument");
|
||||
if (argc < 2) error_exit("-L requires an argument");
|
||||
server_socket_str = argv[1];
|
||||
argc--;
|
||||
argv++;
|
||||
|
@ -1400,7 +1400,7 @@ int adb_commandline(int argc, const char** argv) {
|
|||
}
|
||||
|
||||
if ((server_host_str || server_port_str) && server_socket_str) {
|
||||
error(1, 0, "-L is incompatible with -H or -P");
|
||||
error_exit("-L is incompatible with -H or -P");
|
||||
}
|
||||
|
||||
// If -L, -H, or -P are specified, ignore environment variables.
|
||||
|
@ -1417,10 +1417,10 @@ int adb_commandline(int argc, const char** argv) {
|
|||
server_port_str = server_port_str ? server_port_str : getenv("ANDROID_ADB_SERVER_PORT");
|
||||
if (server_port_str && strlen(server_port_str) > 0) {
|
||||
if (!android::base::ParseInt(server_port_str, &server_port, 1, 65535)) {
|
||||
error(1, 0,
|
||||
"$ANDROID_ADB_SERVER_PORT must be a positive number less than 65535: "
|
||||
"got \"%s\"",
|
||||
server_port_str);
|
||||
error_exit(
|
||||
"$ANDROID_ADB_SERVER_PORT must be a positive number less than 65535: "
|
||||
"got \"%s\"",
|
||||
server_port_str);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1494,7 +1494,7 @@ int adb_commandline(int argc, const char** argv) {
|
|||
} else if (argc == 2 && !strcmp(argv[1], "-l")) {
|
||||
listopt = argv[1];
|
||||
} else {
|
||||
error(1, 0, "adb devices [-l]");
|
||||
error_exit("adb devices [-l]");
|
||||
}
|
||||
|
||||
std::string query = android::base::StringPrintf("host:%s%s", argv[0], listopt);
|
||||
|
@ -1502,13 +1502,13 @@ int adb_commandline(int argc, const char** argv) {
|
|||
return adb_query_command(query);
|
||||
}
|
||||
else if (!strcmp(argv[0], "connect")) {
|
||||
if (argc != 2) error(1, 0, "usage: adb connect <host>[:<port>]");
|
||||
if (argc != 2) error_exit("usage: adb connect <host>[:<port>]");
|
||||
|
||||
std::string query = android::base::StringPrintf("host:connect:%s", argv[1]);
|
||||
return adb_query_command(query);
|
||||
}
|
||||
else if (!strcmp(argv[0], "disconnect")) {
|
||||
if (argc > 2) error(1, 0, "usage: adb disconnect [<host>[:<port>]]");
|
||||
if (argc > 2) error_exit("usage: adb disconnect [<host>[:<port>]]");
|
||||
|
||||
std::string query = android::base::StringPrintf("host:disconnect:%s",
|
||||
(argc == 2) ? argv[1] : "");
|
||||
|
@ -1523,7 +1523,7 @@ int adb_commandline(int argc, const char** argv) {
|
|||
else if (!strcmp(argv[0], "exec-in") || !strcmp(argv[0], "exec-out")) {
|
||||
int exec_in = !strcmp(argv[0], "exec-in");
|
||||
|
||||
if (argc < 2) error(1, 0, "usage: adb %s command", argv[0]);
|
||||
if (argc < 2) error_exit("usage: adb %s command", argv[0]);
|
||||
|
||||
std::string cmd = "exec:";
|
||||
cmd += argv[1];
|
||||
|
@ -1553,17 +1553,17 @@ int adb_commandline(int argc, const char** argv) {
|
|||
return adb_kill_server() ? 0 : 1;
|
||||
}
|
||||
else if (!strcmp(argv[0], "sideload")) {
|
||||
if (argc != 2) error(1, 0, "sideload requires an argument");
|
||||
if (argc != 2) error_exit("sideload requires an argument");
|
||||
if (adb_sideload_host(argv[1])) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else if (!strcmp(argv[0], "tcpip")) {
|
||||
if (argc != 2) error(1, 0, "tcpip requires an argument");
|
||||
if (argc != 2) error_exit("tcpip requires an argument");
|
||||
int port;
|
||||
if (!android::base::ParseInt(argv[1], &port, 1, 65535)) {
|
||||
error(1, 0, "tcpip: invalid port: %s", argv[1]);
|
||||
error_exit("tcpip: invalid port: %s", argv[1]);
|
||||
}
|
||||
return adb_connect_command(android::base::StringPrintf("tcpip:%d", port));
|
||||
}
|
||||
|
@ -1595,7 +1595,7 @@ int adb_commandline(int argc, const char** argv) {
|
|||
} else if (!strcmp(argv[0], "forward") || !strcmp(argv[0], "reverse")) {
|
||||
bool reverse = !strcmp(argv[0], "reverse");
|
||||
--argc;
|
||||
if (argc < 1) error(1, 0, "%s requires an argument", argv[0]);
|
||||
if (argc < 1) error_exit("%s requires an argument", argv[0]);
|
||||
++argv;
|
||||
|
||||
// Determine the <host-prefix> for this command.
|
||||
|
@ -1616,37 +1616,37 @@ int adb_commandline(int argc, const char** argv) {
|
|||
|
||||
std::string cmd, error_message;
|
||||
if (strcmp(argv[0], "--list") == 0) {
|
||||
if (argc != 1) error(1, 0, "--list doesn't take any arguments");
|
||||
if (argc != 1) error_exit("--list doesn't take any arguments");
|
||||
return adb_query_command(host_prefix + ":list-forward");
|
||||
} else if (strcmp(argv[0], "--remove-all") == 0) {
|
||||
if (argc != 1) error(1, 0, "--remove-all doesn't take any arguments");
|
||||
if (argc != 1) error_exit("--remove-all doesn't take any arguments");
|
||||
cmd = host_prefix + ":killforward-all";
|
||||
} else if (strcmp(argv[0], "--remove") == 0) {
|
||||
// forward --remove <local>
|
||||
if (argc != 2) error(1, 0, "--remove requires an argument");
|
||||
if (argc != 2) error_exit("--remove requires an argument");
|
||||
cmd = host_prefix + ":killforward:" + argv[1];
|
||||
} else if (strcmp(argv[0], "--no-rebind") == 0) {
|
||||
// forward --no-rebind <local> <remote>
|
||||
if (argc != 3) error(1, 0, "--no-rebind takes two arguments");
|
||||
if (argc != 3) error_exit("--no-rebind takes two arguments");
|
||||
if (forward_targets_are_valid(argv[1], argv[2], &error_message)) {
|
||||
cmd = host_prefix + ":forward:norebind:" + argv[1] + ";" + argv[2];
|
||||
}
|
||||
} else {
|
||||
// forward <local> <remote>
|
||||
if (argc != 2) error(1, 0, "forward takes two arguments");
|
||||
if (argc != 2) error_exit("forward takes two arguments");
|
||||
if (forward_targets_are_valid(argv[0], argv[1], &error_message)) {
|
||||
cmd = host_prefix + ":forward:" + argv[0] + ";" + argv[1];
|
||||
}
|
||||
}
|
||||
|
||||
if (!error_message.empty()) {
|
||||
error(1, 0, "error: %s", error_message.c_str());
|
||||
error_exit("error: %s", error_message.c_str());
|
||||
}
|
||||
|
||||
int fd = adb_connect(cmd, &error_message);
|
||||
if (fd < 0 || !adb_status(fd, &error_message)) {
|
||||
adb_close(fd);
|
||||
error(1, 0, "error: %s", error_message.c_str());
|
||||
error_exit("error: %s", error_message.c_str());
|
||||
}
|
||||
|
||||
// Server or device may optionally return a resolved TCP port number.
|
||||
|
@ -1660,7 +1660,7 @@ int adb_commandline(int argc, const char** argv) {
|
|||
}
|
||||
/* do_sync_*() commands */
|
||||
else if (!strcmp(argv[0], "ls")) {
|
||||
if (argc != 2) error(1, 0, "ls requires an argument");
|
||||
if (argc != 2) error_exit("ls requires an argument");
|
||||
return do_sync_ls(argv[1]) ? 0 : 1;
|
||||
}
|
||||
else if (!strcmp(argv[0], "push")) {
|
||||
|
@ -1670,7 +1670,7 @@ int adb_commandline(int argc, const char** argv) {
|
|||
const char* dst = nullptr;
|
||||
|
||||
parse_push_pull_args(&argv[1], argc - 1, &srcs, &dst, ©_attrs, &sync);
|
||||
if (srcs.empty() || !dst) error(1, 0, "push requires an argument");
|
||||
if (srcs.empty() || !dst) error_exit("push requires an argument");
|
||||
return do_sync_push(srcs, dst, sync) ? 0 : 1;
|
||||
}
|
||||
else if (!strcmp(argv[0], "pull")) {
|
||||
|
@ -1679,19 +1679,19 @@ int adb_commandline(int argc, const char** argv) {
|
|||
const char* dst = ".";
|
||||
|
||||
parse_push_pull_args(&argv[1], argc - 1, &srcs, &dst, ©_attrs, nullptr);
|
||||
if (srcs.empty()) error(1, 0, "pull requires an argument");
|
||||
if (srcs.empty()) error_exit("pull requires an argument");
|
||||
return do_sync_pull(srcs, dst, copy_attrs) ? 0 : 1;
|
||||
}
|
||||
else if (!strcmp(argv[0], "install")) {
|
||||
if (argc < 2) error(1, 0, "install requires an argument");
|
||||
if (argc < 2) error_exit("install requires an argument");
|
||||
return install_app(argc, argv);
|
||||
}
|
||||
else if (!strcmp(argv[0], "install-multiple")) {
|
||||
if (argc < 2) error(1, 0, "install-multiple requires an argument");
|
||||
if (argc < 2) error_exit("install-multiple requires an argument");
|
||||
return install_multiple_app(argc, argv);
|
||||
}
|
||||
else if (!strcmp(argv[0], "uninstall")) {
|
||||
if (argc < 2) error(1, 0, "uninstall requires an argument");
|
||||
if (argc < 2) error_exit("uninstall requires an argument");
|
||||
return uninstall_app(argc, argv);
|
||||
}
|
||||
else if (!strcmp(argv[0], "sync")) {
|
||||
|
@ -1705,7 +1705,7 @@ int adb_commandline(int argc, const char** argv) {
|
|||
} else if (argc == 2) {
|
||||
src = argv[1];
|
||||
} else {
|
||||
error(1, 0, "usage: adb sync [-l] [PARTITION]");
|
||||
error_exit("usage: adb sync [-l] [PARTITION]");
|
||||
}
|
||||
|
||||
if (src.empty()) src = "all";
|
||||
|
@ -1720,7 +1720,7 @@ int adb_commandline(int argc, const char** argv) {
|
|||
if (!do_sync_sync(src_dir, "/" + partition, list_only)) return 1;
|
||||
}
|
||||
}
|
||||
if (!found) error(1, 0, "don't know how to sync %s partition", src.c_str());
|
||||
if (!found) error_exit("don't know how to sync %s partition", src.c_str());
|
||||
return 0;
|
||||
}
|
||||
/* passthrough commands */
|
||||
|
@ -1752,7 +1752,7 @@ int adb_commandline(int argc, const char** argv) {
|
|||
return restore(argc, argv);
|
||||
}
|
||||
else if (!strcmp(argv[0], "keygen")) {
|
||||
if (argc != 2) error(1, 0, "keygen requires an argument");
|
||||
if (argc != 2) error_exit("keygen requires an argument");
|
||||
// Always print key generation information for keygen command.
|
||||
adb_trace_enable(AUTH);
|
||||
return adb_auth_keygen(argv[1]);
|
||||
|
@ -1767,7 +1767,7 @@ int adb_commandline(int argc, const char** argv) {
|
|||
return adb_connect_command("host:track-devices");
|
||||
} else if (!strcmp(argv[0], "raw")) {
|
||||
if (argc != 2) {
|
||||
error(1, 0, "usage: adb raw SERVICE");
|
||||
error_exit("usage: adb raw SERVICE");
|
||||
}
|
||||
return adb_connect_command(argv[1]);
|
||||
}
|
||||
|
@ -1810,11 +1810,11 @@ int adb_commandline(int argc, const char** argv) {
|
|||
std::string err;
|
||||
return adb_query_command("host:reconnect-offline");
|
||||
} else {
|
||||
error(1, 0, "usage: adb reconnect [device|offline]");
|
||||
error_exit("usage: adb reconnect [device|offline]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
error(1, 0, "unknown command %s", argv[0]);
|
||||
error_exit("unknown command %s", argv[0]);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
|
|
@ -28,7 +28,8 @@
|
|||
#include "commandline.h"
|
||||
#include "fastdeploycallbacks.h"
|
||||
#include "sysdeps.h"
|
||||
#include "utils/String16.h"
|
||||
|
||||
#include "adb_utils.h"
|
||||
|
||||
static constexpr long kRequiredAgentVersion = 0x00000001;
|
||||
|
||||
|
@ -73,14 +74,14 @@ void fastdeploy_set_local_agent(bool use_localagent) {
|
|||
static std::string get_agent_component_host_path(const char* local_path, const char* sdk_path) {
|
||||
std::string adb_dir = android::base::GetExecutableDirectory();
|
||||
if (adb_dir.empty()) {
|
||||
error(1, 0, "Could not determine location of adb!");
|
||||
error_exit("Could not determine location of adb!");
|
||||
}
|
||||
|
||||
if (g_use_localagent) {
|
||||
const char* product_out = getenv("ANDROID_PRODUCT_OUT");
|
||||
if (product_out == nullptr) {
|
||||
error(1, 0, "Could not locate %s because $ANDROID_PRODUCT_OUT is not defined",
|
||||
local_path);
|
||||
error_exit("Could not locate %s because $ANDROID_PRODUCT_OUT is not defined",
|
||||
local_path);
|
||||
}
|
||||
return android::base::StringPrintf("%s%s", product_out, local_path);
|
||||
} else {
|
||||
|
@ -105,10 +106,10 @@ static bool deploy_agent(bool checkTimeStamps) {
|
|||
android::base::StringPrintf(kChmodCommandPattern, kDeviceAgentPath);
|
||||
int ret = send_shell_command(chmodCommand);
|
||||
if (ret != 0) {
|
||||
error(1, 0, "Error executing %s returncode: %d", chmodCommand.c_str(), ret);
|
||||
error_exit("Error executing %s returncode: %d", chmodCommand.c_str(), ret);
|
||||
}
|
||||
} else {
|
||||
error(1, 0, "Error pushing agent files to device");
|
||||
error_exit("Error pushing agent files to device");
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -138,8 +139,8 @@ void update_agent(FastDeploy_AgentUpdateStrategy agentUpdateStrategy) {
|
|||
|
||||
agent_version = get_agent_version();
|
||||
if (agent_version != kRequiredAgentVersion) {
|
||||
error(1, 0, "After update agent version remains incorrect! Expected %ld but version is %ld",
|
||||
kRequiredAgentVersion, agent_version);
|
||||
error_exit("After update agent version remains incorrect! Expected %ld but version is %ld",
|
||||
kRequiredAgentVersion, agent_version);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -159,24 +160,24 @@ static std::string get_packagename_from_apk(const char* apkPath) {
|
|||
std::unique_ptr<android::ZipFileRO> zipFile(android::ZipFileRO::open(apkPath));
|
||||
#define open ___xxx_unix_open
|
||||
if (zipFile == nullptr) {
|
||||
error(1, errno, "Could not open %s", apkPath);
|
||||
perror_exit("Could not open %s", apkPath);
|
||||
}
|
||||
android::ZipEntryRO entry = zipFile->findEntryByName("AndroidManifest.xml");
|
||||
if (entry == nullptr) {
|
||||
error(1, 0, "Could not find AndroidManifest.xml inside %s", apkPath);
|
||||
error_exit("Could not find AndroidManifest.xml inside %s", apkPath);
|
||||
}
|
||||
uint32_t manifest_len = 0;
|
||||
if (!zipFile->getEntryInfo(entry, NULL, &manifest_len, NULL, NULL, NULL, NULL)) {
|
||||
error(1, 0, "Could not read AndroidManifest.xml inside %s", apkPath);
|
||||
error_exit("Could not read AndroidManifest.xml inside %s", apkPath);
|
||||
}
|
||||
std::vector<char> manifest_data(manifest_len);
|
||||
if (!zipFile->uncompressEntry(entry, manifest_data.data(), manifest_len)) {
|
||||
error(1, 0, "Could not uncompress AndroidManifest.xml inside %s", apkPath);
|
||||
error_exit("Could not uncompress AndroidManifest.xml inside %s", apkPath);
|
||||
}
|
||||
android::ResXMLTree tree;
|
||||
android::status_t setto_status = tree.setTo(manifest_data.data(), manifest_len, true);
|
||||
if (setto_status != android::OK) {
|
||||
error(1, 0, "Could not parse AndroidManifest.xml inside %s", apkPath);
|
||||
error_exit("Could not parse AndroidManifest.xml inside %s", apkPath);
|
||||
}
|
||||
android::ResXMLParser::event_code_t code;
|
||||
while ((code = tree.next()) != android::ResXMLParser::BAD_DOCUMENT &&
|
||||
|
@ -217,8 +218,7 @@ static std::string get_packagename_from_apk(const char* apkPath) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
error(1, 0, "Could not find package name tag in AndroidManifest.xml inside %s", apkPath);
|
||||
__builtin_unreachable();
|
||||
error_exit("Could not find package name tag in AndroidManifest.xml inside %s", apkPath);
|
||||
}
|
||||
|
||||
void extract_metadata(const char* apkPath, FILE* outputFp) {
|
||||
|
@ -232,7 +232,7 @@ void extract_metadata(const char* apkPath, FILE* outputFp) {
|
|||
DeployAgentFileCallback cb(outputFp, &extractErrorBuffer, &statusCode);
|
||||
int returnCode = send_shell_command(extractCommand, false, &cb);
|
||||
if (returnCode != 0) {
|
||||
error(1, 0, "Executing %s returned %d", extractCommand.c_str(), returnCode);
|
||||
error_exit("Executing %s returned %d", extractCommand.c_str(), returnCode);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -241,9 +241,9 @@ static std::string get_patch_generator_command() {
|
|||
// This should never happen on a Windows machine
|
||||
const char* host_out = getenv("ANDROID_HOST_OUT");
|
||||
if (host_out == nullptr) {
|
||||
error(1, 0,
|
||||
"Could not locate deploypatchgenerator.jar because $ANDROID_HOST_OUT "
|
||||
"is not defined");
|
||||
error_exit(
|
||||
"Could not locate deploypatchgenerator.jar because $ANDROID_HOST_OUT "
|
||||
"is not defined");
|
||||
}
|
||||
return android::base::StringPrintf("java -jar %s/framework/deploypatchgenerator.jar",
|
||||
host_out);
|
||||
|
@ -251,7 +251,7 @@ static std::string get_patch_generator_command() {
|
|||
|
||||
std::string adb_dir = android::base::GetExecutableDirectory();
|
||||
if (adb_dir.empty()) {
|
||||
error(1, 0, "Could not locate deploypatchgenerator.jar");
|
||||
error_exit("Could not locate deploypatchgenerator.jar");
|
||||
}
|
||||
return android::base::StringPrintf(R"(java -jar "%s/deploypatchgenerator.jar")",
|
||||
adb_dir.c_str());
|
||||
|
@ -263,7 +263,7 @@ void create_patch(const char* apkPath, const char* metadataPath, const char* pat
|
|||
patchPath);
|
||||
int returnCode = system(generatePatchCommand.c_str());
|
||||
if (returnCode != 0) {
|
||||
error(1, 0, "Executing %s returned %d", generatePatchCommand.c_str(), returnCode);
|
||||
error_exit("Executing %s returned %d", generatePatchCommand.c_str(), returnCode);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -282,7 +282,7 @@ void apply_patch_on_device(const char* apkPath, const char* patchPath, const cha
|
|||
std::vector<const char*> srcs = {patchPath};
|
||||
bool push_ok = do_sync_push(srcs, patchDevicePath.c_str(), false);
|
||||
if (!push_ok) {
|
||||
error(1, 0, "Error pushing %s to %s returned", patchPath, patchDevicePath.c_str());
|
||||
error_exit("Error pushing %s to %s returned", patchPath, patchDevicePath.c_str());
|
||||
}
|
||||
|
||||
std::string applyPatchCommand =
|
||||
|
@ -291,7 +291,7 @@ void apply_patch_on_device(const char* apkPath, const char* patchPath, const cha
|
|||
|
||||
int returnCode = send_shell_command(applyPatchCommand);
|
||||
if (returnCode != 0) {
|
||||
error(1, 0, "Executing %s returned %d", applyPatchCommand.c_str(), returnCode);
|
||||
error_exit("Executing %s returned %d", applyPatchCommand.c_str(), returnCode);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -305,7 +305,7 @@ void install_patch(const char* apkPath, const char* patchPath, int argc, const c
|
|||
std::vector<const char*> srcs{patchPath};
|
||||
bool push_ok = do_sync_push(srcs, patchDevicePath.c_str(), false);
|
||||
if (!push_ok) {
|
||||
error(1, 0, "Error pushing %s to %s returned", patchPath, patchDevicePath.c_str());
|
||||
error_exit("Error pushing %s to %s returned", patchPath, patchDevicePath.c_str());
|
||||
}
|
||||
|
||||
std::vector<unsigned char> applyOutputBuffer;
|
||||
|
@ -322,6 +322,6 @@ void install_patch(const char* apkPath, const char* patchPath, int argc, const c
|
|||
patchDevicePath.c_str(), argsString.c_str());
|
||||
int returnCode = send_shell_command(applyPatchCommand);
|
||||
if (returnCode != 0) {
|
||||
error(1, 0, "Executing %s returned %d", applyPatchCommand.c_str(), returnCode);
|
||||
error_exit("Executing %s returned %d", applyPatchCommand.c_str(), returnCode);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
#include "adb.h"
|
||||
#include "adb_io.h"
|
||||
#include "adb_utils.h"
|
||||
#include "fdevent.h"
|
||||
|
||||
/* TODO:
|
||||
|
@ -78,7 +79,7 @@ void framebuffer_service(unique_fd fd) {
|
|||
const char* command = "screencap";
|
||||
const char *args[2] = {command, nullptr};
|
||||
execvp(command, (char**)args);
|
||||
error(1, errno, "exec screencap failed");
|
||||
perror_exit("exec screencap failed");
|
||||
}
|
||||
|
||||
adb_close(fds[1]);
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <error.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
@ -70,8 +69,6 @@
|
|||
#define OS_PATH_SEPARATOR_STR "\\"
|
||||
#define ENV_PATH_SEPARATOR_STR ";"
|
||||
|
||||
void error(int status, int error, const char* fmt, ...) __attribute__((__format__(printf, 3, 4)));
|
||||
|
||||
static __inline__ bool adb_is_separator(char c) {
|
||||
return c == '\\' || c == '/';
|
||||
}
|
||||
|
|
|
@ -2756,24 +2756,3 @@ int adb_thread_setname(const std::string& name) {
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void error(int status, int error, const char* fmt, ...) {
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "%s: ", android::base::Basename(android::base::GetExecutablePath()).c_str());
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (error != 0) {
|
||||
fprintf(stderr, ": %s", strerror(error));
|
||||
}
|
||||
|
||||
putc('\n', stderr);
|
||||
fflush(stderr);
|
||||
|
||||
if (status != 0) {
|
||||
exit(status);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue