mirror of
https://gitee.com/openharmony/developtools_hdc
synced 2024-11-30 10:41:25 +00:00
fix: Resolve commit conflicts.
Signed-off-by: liurantao <liurantao@huawei.com>
This commit is contained in:
commit
9abb2b607f
@ -36,7 +36,7 @@ static bool DropRootPrivileges()
|
||||
{
|
||||
int ret;
|
||||
const char *userName = "shell";
|
||||
vector<const char *> groupsNames = { "shell", "log", "readproc", "file_manager", "user_data_rw" };
|
||||
vector<const char *> groupsNames = { "shell", "log", "readproc", "file_manager" };
|
||||
struct passwd *user;
|
||||
gid_t *gids = nullptr;
|
||||
|
||||
|
@ -98,8 +98,8 @@ constexpr uint16_t NEW_SESSION_DROP_USB_DATA_TIME_MS = 1000;
|
||||
// |----------------------------------------------------------------|
|
||||
// | major |reserve| minor |reserve|version| fix | reserve |
|
||||
// |----------------------------------------------------------------|
|
||||
// 0x30100200 is 3.1.0c
|
||||
constexpr uint32_t HDC_VERSION_NUMBER = 0x30100200;
|
||||
// 0x30100300 is 3.1.0d
|
||||
constexpr uint32_t HDC_VERSION_NUMBER = 0x30100300;
|
||||
constexpr uint32_t HDC_BUF_MAX_BYTES = INT_MAX;
|
||||
#ifdef HDC_HOST
|
||||
constexpr uint32_t HOST_SOCKETPAIR_SIZE = 1024 * 1024;
|
||||
@ -132,6 +132,8 @@ const char HUGE_BUF_TAG = 'H'; // support huge buffer
|
||||
const size_t BANNER_FEATURE_TAG_OFFSET = 11;
|
||||
const char WAIT_DEVICE_TAG = 'W';
|
||||
const size_t WAIT_TAG_OFFSET = 11;
|
||||
const size_t SERVICE_KILL_OFFSET = 10;
|
||||
const char SERVICE_KILL_TAG = 'K';
|
||||
// input command
|
||||
const string CMDSTR_SOFTWARE_VERSION = "version";
|
||||
const string CMDSTR_SOFTWARE_HELP = "help";
|
||||
|
@ -348,6 +348,7 @@ struct HdcChannel {
|
||||
bool fromClient = false;
|
||||
bool connectLocalDevice = false;
|
||||
bool isStableBuf = false;
|
||||
bool isSupportedKillServerCmd = false;
|
||||
std::atomic<uint32_t> writeFailedTimes;
|
||||
};
|
||||
using HChannel = struct HdcChannel *;
|
||||
|
@ -90,7 +90,13 @@ uint64_t Header::Size()
|
||||
WRITE_LOG(LOG_DEBUG, "header size octalStr %s", octalStr.c_str());
|
||||
if (!octalStr.empty()) {
|
||||
const int octal = 8;
|
||||
num = stoull(octalStr, nullptr, octal);
|
||||
if (std::find_if(octalStr.begin(), octalStr.end(),
|
||||
[](unsigned char c) { return c < '0' || c > '7'; }) == octalStr.end()) {
|
||||
num = stoull(octalStr, nullptr, octal);
|
||||
} else {
|
||||
num = 0;
|
||||
WRITE_LOG(LOG_WARN, "header size %s is invaild", octalStr.c_str());
|
||||
}
|
||||
}
|
||||
WRITE_LOG(LOG_DEBUG, "header size num %llu", num);
|
||||
return num;
|
||||
|
@ -586,6 +586,7 @@ void HdcSessionBase::FreeSessionContinue(HSession hSession)
|
||||
if (hSession->connType == CONN_TCP) {
|
||||
// Turn off TCP to prevent continuing writing
|
||||
Base::TryCloseHandle((uv_handle_t *)&hSession->hWorkTCP, true, closeSessionTCPHandle);
|
||||
Base::CloseFd(hSession->dataFd[STREAM_WORK]);
|
||||
}
|
||||
hSession->availTailIndex = 0;
|
||||
if (hSession->ioBuf) {
|
||||
|
@ -11,7 +11,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
const.hdc.version = "Ver: 3.1.0c"
|
||||
const.hdc.version = "Ver: 3.1.0d"
|
||||
persist.hdc.mode.usb = "enable"
|
||||
persist.hdc.mode.tcp = "disable"
|
||||
persist.hdc.mode.uart = "disable"
|
||||
|
@ -73,7 +73,7 @@
|
||||
"name" : "hdcd",
|
||||
"path" : ["/system/bin/hdcd"],
|
||||
"uid" : "shell",
|
||||
"gid" : [ "shell", "log", "readproc", "file_manager", "user_data_rw", "netsys_socket" ],
|
||||
"gid" : [ "shell", "log", "readproc", "file_manager", "netsys_socket" ],
|
||||
"socket" : [{
|
||||
"name" : "hdcd",
|
||||
"family" : "AF_UNIX",
|
||||
|
@ -87,7 +87,8 @@
|
||||
"name" : "hdcd",
|
||||
"path" : ["/system/bin/hdcd"],
|
||||
"uid" : "root",
|
||||
"gid" : [ "root", "shell", "log", "readproc", "file_manager", "user_data_rw" ],
|
||||
"gid" : [ "root", "shell", "log", "readproc", "file_manager" ],
|
||||
"setuid" : true,
|
||||
"socket" : [{
|
||||
"name" : "hdcd",
|
||||
"family" : "AF_UNIX",
|
||||
|
@ -193,7 +193,7 @@ bool DropRootPrivileges()
|
||||
{
|
||||
int ret;
|
||||
const char *userName = "shell";
|
||||
vector<const char *> groupsNames = { "shell", "log", "readproc", "file_manager", "user_data_rw" };
|
||||
vector<const char *> groupsNames = { "shell", "log", "readproc", "file_manager" };
|
||||
struct passwd *user;
|
||||
gid_t *gids = nullptr;
|
||||
|
||||
|
@ -176,6 +176,7 @@ string HdcClient::AutoConnectKey(string &doCommand, const string &preConnectKey)
|
||||
vecNoConnectKeyCommand.push_back(CMDSTR_SOFTWARE_VERSION);
|
||||
vecNoConnectKeyCommand.push_back(CMDSTR_SOFTWARE_HELP);
|
||||
vecNoConnectKeyCommand.push_back(CMDSTR_TARGET_DISCOVER);
|
||||
vecNoConnectKeyCommand.push_back(CMDSTR_SERVICE_KILL);
|
||||
vecNoConnectKeyCommand.push_back(CMDSTR_LIST_TARGETS);
|
||||
vecNoConnectKeyCommand.push_back(CMDSTR_CHECK_SERVER);
|
||||
vecNoConnectKeyCommand.push_back(CMDSTR_CONNECT_TARGET);
|
||||
@ -428,6 +429,14 @@ void HdcClient::CommandWorker(uv_timer_t *handle)
|
||||
return;
|
||||
}
|
||||
uv_timer_stop(handle);
|
||||
|
||||
if (!strncmp(thisClass->command.c_str(), CMDSTR_SERVICE_KILL.c_str(),
|
||||
CMDSTR_SERVICE_KILL.size()) && !thisClass->channel->isSupportedKillServerCmd) {
|
||||
WRITE_LOG(LOG_DEBUG, "uv_kill server");
|
||||
thisClass->CtrlServiceWork(CMDSTR_SERVICE_KILL.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
WRITE_LOG(LOG_DEBUG, "Connect server successful");
|
||||
bool closeInput = false;
|
||||
if (!HostUpdater::ConfirmCommand(thisClass->command, closeInput)) {
|
||||
@ -596,7 +605,10 @@ int HdcClient::PreHandshake(HChannel hChannel, const uint8_t *buf)
|
||||
return ERR_BUF_CHECK;
|
||||
}
|
||||
hChannel->isStableBuf = (hShake->banner[BANNER_FEATURE_TAG_OFFSET] != HUGE_BUF_TAG);
|
||||
WRITE_LOG(LOG_DEBUG, "Channel PreHandshake isStableBuf:%d", hChannel->isStableBuf);
|
||||
hChannel->isSupportedKillServerCmd =
|
||||
(hShake->banner[SERVICE_KILL_OFFSET] == SERVICE_KILL_TAG);
|
||||
WRITE_LOG(LOG_DEBUG, "Channel PreHandshake isStableBuf:%d, killflag:%d",
|
||||
hChannel->isStableBuf, hChannel->isSupportedKillServerCmd);
|
||||
if (this->command == CMDSTR_WAIT_FOR && !connectKey.empty()) {
|
||||
hShake->banner[WAIT_TAG_OFFSET] = WAIT_DEVICE_TAG;
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ public:
|
||||
HSession ConnectDetectDaemon(const HSession hSession, const HDaemonInfo pdi);
|
||||
void Stop();
|
||||
void RemoveIgnoreDevice(string &mountInfo);
|
||||
void SendSoftResetToDaemon(HSession hSession, uint32_t sessionIdOld);
|
||||
|
||||
private:
|
||||
enum UsbCheckStatus {
|
||||
@ -57,7 +58,6 @@ private:
|
||||
void CancelUsbIo(HSession hSession) override;
|
||||
int UsbToHdcProtocol(uv_stream_t *stream, uint8_t *appendData, int dataSize) override;
|
||||
int SubmitUsbBio(HSession hSession, bool sendOrRecv, uint8_t *buf, int bufSize);
|
||||
void SendSoftResetToDaemon(HSession hSession, uint32_t sessionIdOld);
|
||||
|
||||
libusb_context *ctxUSB;
|
||||
uv_timer_t devListWatcher;
|
||||
|
@ -201,8 +201,7 @@ int RunClientMode(string &commands, string &serverListenString, string &connectK
|
||||
std::cerr << TranslateCommand::Usage();
|
||||
return 0;
|
||||
}
|
||||
if (!strncmp(commands.c_str(), CMDSTR_SERVICE_KILL.c_str(), CMDSTR_SERVICE_KILL.size()) ||
|
||||
!strncmp(commands.c_str(), CMDSTR_GENERATE_KEY.c_str(), CMDSTR_GENERATE_KEY.size())) {
|
||||
if (!strncmp(commands.c_str(), CMDSTR_GENERATE_KEY.c_str(), CMDSTR_GENERATE_KEY.size())) {
|
||||
client.CtrlServiceWork(commands.c_str());
|
||||
return 0;
|
||||
}
|
||||
@ -210,6 +209,10 @@ int RunClientMode(string &commands, string &serverListenString, string &connectK
|
||||
// default pullup, just default listenstr.If want to customer listen-string, please use 'hdc -m -s lanip:port'
|
||||
if (!strncmp(commands.c_str(), CMDSTR_SERVICE_START.c_str(), CMDSTR_SERVICE_START.size())) {
|
||||
Base::PrintMessage("hdc start server, listening: %s", serverListenString.c_str());
|
||||
if (!strncmp(commands.c_str(), CMDSTR_SERVICE_KILL.c_str(),
|
||||
CMDSTR_SERVICE_KILL.size())) {
|
||||
WRITE_LOG(LOG_DEBUG, "kill server, but server not exist, so do nothing");
|
||||
return 0;
|
||||
}
|
||||
HdcServer::PullupServer(serverListenString.c_str());
|
||||
uv_sleep(START_SERVER_FOR_CLIENT_TIME); // give time to start serverForClient,at least 200ms
|
||||
|
@ -1063,4 +1063,28 @@ void HdcServer::EchoToClientsForSession(uint32_t targetSessionId, const string &
|
||||
WRITE_LOG(LOG_INFO, "%s:%u %s", __FUNCTION__, targetSessionId, echo.c_str());
|
||||
hSfc->EchoToAllChannelsViaSessionId(targetSessionId, echo);
|
||||
}
|
||||
|
||||
void HdcServer::SessionSoftReset()
|
||||
{
|
||||
uv_rwlock_rdlock(&daemonAdmin);
|
||||
map<string, HDaemonInfo>::iterator iter;
|
||||
for (iter = mapDaemon.begin(); iter != mapDaemon.end(); ++iter) {
|
||||
HDaemonInfo di = iter->second;
|
||||
if (!di) {
|
||||
continue;
|
||||
}
|
||||
string devname = di->devName;
|
||||
if (devname.empty()) {
|
||||
continue;
|
||||
}
|
||||
if (di->connType == CONN_USB) {
|
||||
HSession hSession = di->hSession;
|
||||
if (!hSession) {
|
||||
continue;
|
||||
}
|
||||
clsUSBClt->SendSoftResetToDaemon(hSession, 0);
|
||||
}
|
||||
}
|
||||
uv_rwlock_rdunlock(&daemonAdmin);
|
||||
}
|
||||
} // namespace Hdc
|
||||
|
@ -35,6 +35,7 @@ public:
|
||||
static bool PullupServer(const char *listenString);
|
||||
static void UsbPreConnect(uv_timer_t *handle);
|
||||
void NotifyInstanceSessionFree(HSession hSession, bool freeOrClear) override;
|
||||
void SessionSoftReset();
|
||||
|
||||
HdcHostTCP *clsTCPClt;
|
||||
HdcHostUSB *clsUSBClt;
|
||||
|
@ -80,6 +80,7 @@ void HdcServerForClient::AcceptClient(uv_stream_t *server, int status)
|
||||
struct ChannelHandShake handShake = {};
|
||||
if (EOK == strcpy_s(handShake.banner, sizeof(handShake.banner), HANDSHAKE_MESSAGE.c_str())) {
|
||||
handShake.banner[BANNER_FEATURE_TAG_OFFSET] = HUGE_BUF_TAG; // set feature tag for huge buf size
|
||||
handShake.banner[SERVICE_KILL_OFFSET] = SERVICE_KILL_TAG;
|
||||
handShake.channelId = htonl(hChannel->channelId);
|
||||
string ver = Base::GetVersion() + HDC_MSG_HASH;
|
||||
WRITE_LOG(LOG_DEBUG, "Server ver:%s", ver.c_str());
|
||||
@ -491,6 +492,12 @@ bool HdcServerForClient::DoCommandLocal(HChannel hChannel, void *formatCommandIn
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
case CMD_SERVICE_KILL: {
|
||||
ptrServer->SessionSoftReset();
|
||||
WRITE_LOG(LOG_DEBUG, "server kill");
|
||||
EchoClient(hChannel, MSG_OK, "Kill server finish");
|
||||
_exit(0);
|
||||
}
|
||||
case CMD_CHECK_SERVER: {
|
||||
WRITE_LOG(LOG_DEBUG, "CMD_CHECK_SERVER command");
|
||||
ReportServerVersion(hChannel);
|
||||
|
Loading…
Reference in New Issue
Block a user