Load ADB value using sc_get_env()
Contrary to getenv(), the result of sc_get_env() is encoded in UTF-8 on all platforms. Since it is allocated, it requires an explicit init() and destroy() functions. PR #5560 <https://github.com/Genymobile/scrcpy/pull/5560>
This commit is contained in:
parent
131372d2c4
commit
beee42fb06
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#include "adb_device.h"
|
#include "adb_device.h"
|
||||||
#include "adb_parser.h"
|
#include "adb_parser.h"
|
||||||
|
#include "util/env.h"
|
||||||
#include "util/file.h"
|
#include "util/file.h"
|
||||||
#include "util/log.h"
|
#include "util/log.h"
|
||||||
#include "util/process_intr.h"
|
#include "util/process_intr.h"
|
||||||
@ -24,15 +25,31 @@
|
|||||||
*/
|
*/
|
||||||
#define SC_ADB_COMMAND(...) { sc_adb_get_executable(), __VA_ARGS__, NULL }
|
#define SC_ADB_COMMAND(...) { sc_adb_get_executable(), __VA_ARGS__, NULL }
|
||||||
|
|
||||||
static const char *adb_executable;
|
static char *adb_executable;
|
||||||
|
|
||||||
|
bool
|
||||||
|
sc_adb_init(void) {
|
||||||
|
adb_executable = sc_get_env("ADB");
|
||||||
|
if (adb_executable) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
adb_executable = strdup("adb");
|
||||||
|
if (!adb_executable) {
|
||||||
|
LOG_OOM();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sc_adb_destroy(void) {
|
||||||
|
free(adb_executable);
|
||||||
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
sc_adb_get_executable(void) {
|
sc_adb_get_executable(void) {
|
||||||
if (!adb_executable) {
|
|
||||||
adb_executable = getenv("ADB");
|
|
||||||
if (!adb_executable)
|
|
||||||
adb_executable = "adb";
|
|
||||||
}
|
|
||||||
return adb_executable;
|
return adb_executable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,6 +15,12 @@
|
|||||||
|
|
||||||
#define SC_ADB_SILENT (SC_ADB_NO_STDOUT | SC_ADB_NO_STDERR | SC_ADB_NO_LOGERR)
|
#define SC_ADB_SILENT (SC_ADB_NO_STDOUT | SC_ADB_NO_STDERR | SC_ADB_NO_LOGERR)
|
||||||
|
|
||||||
|
bool
|
||||||
|
sc_adb_init(void);
|
||||||
|
|
||||||
|
void
|
||||||
|
sc_adb_destroy(void);
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
sc_adb_get_executable(void);
|
sc_adb_get_executable(void);
|
||||||
|
|
||||||
|
@ -485,14 +485,21 @@ sc_server_init(struct sc_server *server, const struct sc_server_params *params,
|
|||||||
// end of the program
|
// end of the program
|
||||||
server->params = *params;
|
server->params = *params;
|
||||||
|
|
||||||
bool ok = sc_mutex_init(&server->mutex);
|
bool ok = sc_adb_init();
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ok = sc_mutex_init(&server->mutex);
|
||||||
|
if (!ok) {
|
||||||
|
sc_adb_destroy();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
ok = sc_cond_init(&server->cond_stopped);
|
ok = sc_cond_init(&server->cond_stopped);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
sc_mutex_destroy(&server->mutex);
|
sc_mutex_destroy(&server->mutex);
|
||||||
|
sc_adb_destroy();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -500,6 +507,7 @@ sc_server_init(struct sc_server *server, const struct sc_server_params *params,
|
|||||||
if (!ok) {
|
if (!ok) {
|
||||||
sc_cond_destroy(&server->cond_stopped);
|
sc_cond_destroy(&server->cond_stopped);
|
||||||
sc_mutex_destroy(&server->mutex);
|
sc_mutex_destroy(&server->mutex);
|
||||||
|
sc_adb_destroy();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1141,4 +1149,6 @@ sc_server_destroy(struct sc_server *server) {
|
|||||||
sc_intr_destroy(&server->intr);
|
sc_intr_destroy(&server->intr);
|
||||||
sc_cond_destroy(&server->cond_stopped);
|
sc_cond_destroy(&server->cond_stopped);
|
||||||
sc_mutex_destroy(&server->mutex);
|
sc_mutex_destroy(&server->mutex);
|
||||||
|
|
||||||
|
sc_adb_destroy();
|
||||||
}
|
}
|
||||||
|
@ -95,9 +95,14 @@ scrcpy_otg(struct scrcpy_options *options) {
|
|||||||
// On Windows, only one process could open a USB device
|
// On Windows, only one process could open a USB device
|
||||||
// <https://github.com/Genymobile/scrcpy/issues/2773>
|
// <https://github.com/Genymobile/scrcpy/issues/2773>
|
||||||
LOGI("Killing adb server (if any)...");
|
LOGI("Killing adb server (if any)...");
|
||||||
unsigned flags = SC_ADB_NO_STDOUT | SC_ADB_NO_STDERR | SC_ADB_NO_LOGERR;
|
if (sc_adb_init()) {
|
||||||
// uninterruptible (intr == NULL), but in practice it's very quick
|
unsigned flags = SC_ADB_NO_STDOUT | SC_ADB_NO_STDERR | SC_ADB_NO_LOGERR;
|
||||||
sc_adb_kill_server(NULL, flags);
|
// uninterruptible (intr == NULL), but in practice it's very quick
|
||||||
|
sc_adb_kill_server(NULL, flags);
|
||||||
|
sc_adb_destroy();
|
||||||
|
} else {
|
||||||
|
LOGW("Could not call adb executable, adb server not killed");
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const struct sc_usb_callbacks cbs = {
|
static const struct sc_usb_callbacks cbs = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user