From 9e229e147524f4c84fb6640a6cc7492c2235fd78 Mon Sep 17 00:00:00 2001 From: xionglei6 Date: Tue, 22 Mar 2022 16:37:08 +0800 Subject: [PATCH 1/3] fix: log format print %{public}d Signed-off-by: xionglei6 --- src/appspawn_msg_peer.cpp | 4 +-- src/appspawn_server.cpp | 28 +++++++++--------- src/socket/appspawn_socket.cpp | 16 +++++------ src/socket/client_socket.cpp | 12 ++++---- src/socket/server_socket.cpp | 36 ++++++++++++------------ test/moduletest/appspawn_module_test.cpp | 6 ++-- 6 files changed, 51 insertions(+), 51 deletions(-) diff --git a/src/appspawn_msg_peer.cpp b/src/appspawn_msg_peer.cpp index e658e755..dec21fb6 100644 --- a/src/appspawn_msg_peer.cpp +++ b/src/appspawn_msg_peer.cpp @@ -49,12 +49,12 @@ int AppSpawnMsgPeer::GetConnectFd() const int AppSpawnMsgPeer::Response(pid_t pid) { if ((socket_ == nullptr) || (connectFd_ < 0)) { - HiLog::Error(LABEL, "Invalid socket params: connectFd %d", connectFd_); + HiLog::Error(LABEL, "Invalid socket params: connectFd %{public}d", connectFd_); return -EINVAL; } if (socket_->WriteSocketMessage(connectFd_, &pid, sizeof(pid)) != sizeof(pid)) { - HiLog::Error(LABEL, "Failed to write message: connectFd %d", connectFd_); + HiLog::Error(LABEL, "Failed to write message: connectFd %{public}d", connectFd_); return (-errno); } diff --git a/src/appspawn_server.cpp b/src/appspawn_server.cpp index 7660efe9..d624312a 100644 --- a/src/appspawn_server.cpp +++ b/src/appspawn_server.cpp @@ -117,14 +117,14 @@ static void UninstallSigHandler() sa.sa_handler = nullptr; int err = sigaction(SIGCHLD, &sa, nullptr); if (err < 0) { - HiLog::Error(LABEL, "Error uninstalling SIGCHLD handler: %d", errno); + HiLog::Error(LABEL, "Error uninstalling SIGCHLD handler: %{public}d", errno); } struct sigaction sah = {}; sah.sa_handler = nullptr; err = sigaction(SIGHUP, &sah, nullptr); if (err < 0) { - HiLog::Error(LABEL, "Error uninstalling SIGHUP handler: %d", errno); + HiLog::Error(LABEL, "Error uninstalling SIGHUP handler: %{public}d", errno); } } #ifdef __cplusplus @@ -142,7 +142,7 @@ void AppSpawnServer::MsgPeer(int connectFd) { std::unique_ptr msgPeer = std::make_unique(socket_, connectFd); if (msgPeer == nullptr || msgPeer->MsgPeer() != 0) { - HiLog::Error(LABEL, "Failed to listen connection %d, %d", connectFd, errno); + HiLog::Error(LABEL, "Failed to listen connection %{public}d, %{public}d", connectFd, errno); return; } @@ -201,7 +201,7 @@ void AppSpawnServer::HandleSignal() sigprocmask(SIG_BLOCK, &mask, nullptr); int signalFd = signalfd(-1, &mask, SFD_CLOEXEC); if (signalFd < 0) { - APPSPAWN_LOGE("Error installing SIGHUP handler: %d", errno); + APPSPAWN_LOGE("Error installing SIGHUP handler: %{public}d", errno); } while (isRunning_) { struct signalfd_siginfo fdsi; @@ -212,13 +212,13 @@ void AppSpawnServer::HandleSignal() pid_t pid; int status; while ((pid = waitpid(-1, &status, WNOHANG)) > 0) { - APPSPAWN_LOGE("HandleSignal: %d", pid); + APPSPAWN_LOGE("HandleSignal: %{public}d", pid); } std::lock_guard lock(mut_); isChildDie_ = true; childPid_ = fdsi.ssi_pid; - APPSPAWN_LOGI("exit app pid = %d", childPid_); + APPSPAWN_LOGI("exit app pid = %{public}d", childPid_); dataCond_.notify_one(); } close(signalFd); @@ -309,10 +309,10 @@ int AppSpawnServer::DoColdStartApp(ClientSocket::AppProperty *appProperty, int f std::vector extractedCmds; extractedCmds.push_back(const_cast("/system/bin/appspawntools")); std::string tmp = std::to_string(fd); - APPSPAWN_LOGI("DoColdStartApp::fd %d %s", fd, tmp.c_str()); + APPSPAWN_LOGI("DoColdStartApp::fd %{public}d %s", fd, tmp.c_str()); extractedCmds.push_back(const_cast(tmp.c_str())); std::string uid = std::to_string(appProperty->uid); - APPSPAWN_LOGI("DoColdStartApp::uid %d gid %d %s", appProperty->uid, appProperty->gid, uid.c_str()); + APPSPAWN_LOGI("DoColdStartApp::uid %{public}d gid %{public}d %s", appProperty->uid, appProperty->gid, uid.c_str()); extractedCmds.push_back(const_cast(uid.c_str())); std::string gid = std::to_string(appProperty->gid); extractedCmds.push_back(const_cast(gid.c_str())); @@ -320,7 +320,7 @@ int AppSpawnServer::DoColdStartApp(ClientSocket::AppProperty *appProperty, int f extractedCmds.push_back(const_cast(appProperty->bundleName)); extractedCmds.push_back(const_cast(appProperty->soPath)); std::string accessTokenId = std::to_string(appProperty->accessTokenId); - APPSPAWN_LOGI("DoColdStartApp::accessTokenId %d %s", appProperty->accessTokenId, accessTokenId.c_str()); + APPSPAWN_LOGI("DoColdStartApp::accessTokenId %{public}d %s", appProperty->accessTokenId, accessTokenId.c_str()); extractedCmds.push_back(const_cast(accessTokenId.c_str())); extractedCmds.push_back(const_cast(appProperty->apl)); APPSPAWN_LOGI("DoColdStartApp renderCmd %s", appProperty->renderCmd); @@ -328,13 +328,13 @@ int AppSpawnServer::DoColdStartApp(ClientSocket::AppProperty *appProperty, int f std::string flags = std::to_string(appProperty->flags); extractedCmds.push_back(const_cast(flags.c_str())); std::string gidCount = std::to_string(appProperty->gidCount); - APPSPAWN_LOGI("DoColdStartApp gidCount %d %s", appProperty->gidCount, gidCount.c_str()); + APPSPAWN_LOGI("DoColdStartApp gidCount %{public}d %s", appProperty->gidCount, gidCount.c_str()); extractedCmds.push_back(const_cast(gidCount.c_str())); for (uint32_t i = 0; i < appProperty->gidCount; i++) { extractedCmds.push_back(const_cast(std::string(std::to_string(appProperty->gidTable[i])).c_str())); } extractedCmds.push_back(nullptr); - APPSPAWN_LOGI("DoColdStartApp extractedCmds %d", extractedCmds.size()); + APPSPAWN_LOGI("DoColdStartApp extractedCmds %{public}d", extractedCmds.size()); int ret = execv(extractedCmds[0], extractedCmds.data()); if (ret) { HiLog::Error(LABEL, "Failed to execv, errno = %{public}d", errno); @@ -420,7 +420,7 @@ bool AppSpawnServer::ServerMain(char *longProcName, int64_t longProcNameLen) isChildDie_ = false; auto iter = appMap_.find(childPid_); if (iter != appMap_.end()) { - APPSPAWN_LOGI("delete pid=%d in appMap", iter->first); + APPSPAWN_LOGI("delete pid=%{public}d in appMap", iter->first); appMap_.erase(iter); } } @@ -440,13 +440,13 @@ bool AppSpawnServer::ServerMain(char *longProcName, int64_t longProcNameLen) appMap_[pid] = appProperty->processName; } socket_->CloseConnection(connectFd); // close socket connection - APPSPAWN_LOGI("AppSpawnServer::parent process create app finish, pid = %d uid %d %s %s", + APPSPAWN_LOGI("AppSpawnServer::parent process create app finish, pid = %{public}d uid %{public}d %s %s", pid, appProperty->uid, appProperty->processName, appProperty->bundleName); } while (appMap_.size() > 0) { auto iter = appMap_.begin(); - APPSPAWN_LOGI("kill app, pid = %d, processName = %s", iter->first, iter->second.c_str()); + APPSPAWN_LOGI("kill app, pid = %{public}d, processName = %s", iter->first, iter->second.c_str()); kill(iter->first, SIGKILL); appMap_.erase(iter); } diff --git a/src/socket/appspawn_socket.cpp b/src/socket/appspawn_socket.cpp index 4c0caf6a..95ca6467 100644 --- a/src/socket/appspawn_socket.cpp +++ b/src/socket/appspawn_socket.cpp @@ -92,18 +92,18 @@ int AppSpawnSocket::CreateSocket() { int socketFd = socket(AF_LOCAL, SOCK_SEQPACKET, 0); if (socketFd < 0) { - HiLog::Error(LABEL, "Failed to create socket: %d", errno); + HiLog::Error(LABEL, "Failed to create socket: %{public}d", errno); return (-errno); } - HiLog::Debug(LABEL, "Created socket with fd %d", socketFd); + HiLog::Debug(LABEL, "Created socket with fd %{public}d", socketFd); return socketFd; } void AppSpawnSocket::CloseSocket(int &socketFd) { if (socketFd >= 0) { - HiLog::Debug(LABEL, "Closed socket with fd %d", socketFd); + HiLog::Debug(LABEL, "Closed socket with fd %{public}d", socketFd); close(socketFd); socketFd = -1; } @@ -112,7 +112,7 @@ void AppSpawnSocket::CloseSocket(int &socketFd) int AppSpawnSocket::ReadSocketMessage(int socketFd, void *buf, int len) { if (socketFd < 0 || len <= 0 || buf == nullptr) { - HiLog::Error(LABEL, "Invalid args: socket %d, len %d, buf might be nullptr", socketFd, len); + HiLog::Error(LABEL, "Invalid args: socket %{public}d, len %{public}d, buf might be nullptr", socketFd, len); return -1; } @@ -123,7 +123,7 @@ int AppSpawnSocket::ReadSocketMessage(int socketFd, void *buf, int len) ssize_t rLen = TEMP_FAILURE_RETRY(read(socketFd, buf, len)); if (rLen < 0) { - HiLog::Error(LABEL, "Read message from fd %d error %zd: %d", socketFd, rLen, errno); + HiLog::Error(LABEL, "Read message from fd %{public}d error %zd: %{public}d", socketFd, rLen, errno); return -EFAULT; } @@ -133,7 +133,7 @@ int AppSpawnSocket::ReadSocketMessage(int socketFd, void *buf, int len) int AppSpawnSocket::WriteSocketMessage(int socketFd, const void *buf, int len) { if (socketFd < 0 || len <= 0 || buf == nullptr) { - HiLog::Error(LABEL, "Invalid args: socket %d, len %d, buf might be nullptr", socketFd, len); + HiLog::Error(LABEL, "Invalid args: socket %{public}d, len %{public}d, buf might be nullptr", socketFd, len); return -1; } @@ -142,9 +142,9 @@ int AppSpawnSocket::WriteSocketMessage(int socketFd, const void *buf, int len) const uint8_t *offset = reinterpret_cast(buf); for (ssize_t wLen = 0; remain > 0; offset += wLen, remain -= wLen, written += wLen) { wLen = write(socketFd, offset, remain); - HiLog::Debug(LABEL, "socket fd %d, wLen %zd", socketFd, wLen); + HiLog::Debug(LABEL, "socket fd %{public}d, wLen %zd", socketFd, wLen); if ((wLen <= 0) && (errno != EINTR)) { - HiLog::Error(LABEL, "Failed to write message to fd %d, error %zd: %d", socketFd, wLen, errno); + HiLog::Error(LABEL, "Failed to write message to fd %{public}d, error %zd: %{public}d", socketFd, wLen, errno); return (-errno); } } diff --git a/src/socket/client_socket.cpp b/src/socket/client_socket.cpp index 308f389c..5c44996e 100644 --- a/src/socket/client_socket.cpp +++ b/src/socket/client_socket.cpp @@ -40,14 +40,14 @@ int ClientSocket::CreateClient() } } - HiLog::Debug(LABEL, "Client: CreateClient socket fd %d", socketFd_); + HiLog::Debug(LABEL, "Client: CreateClient socket fd %{public}d", socketFd_); return 0; } void ClientSocket::CloseClient() { if (socketFd_ < 0) { - HiLog::Error(LABEL, "Client: Invalid connectFd %d", socketFd_); + HiLog::Error(LABEL, "Client: Invalid connectFd %{public}d", socketFd_); return; } @@ -58,7 +58,7 @@ void ClientSocket::CloseClient() int ClientSocket::ConnectSocket(int connectFd) { if (connectFd < 0) { - HiLog::Error(LABEL, "Client: Invalid socket fd: %d", connectFd); + HiLog::Error(LABEL, "Client: Invalid socket fd: %{public}d", connectFd); return -1; } @@ -69,18 +69,18 @@ int ClientSocket::ConnectSocket(int connectFd) if ((setsockopt(connectFd, SOL_SOCKET, SO_RCVTIMEO, &SOCKET_TIMEOUT, sizeof(SOCKET_TIMEOUT)) != 0) || (setsockopt(connectFd, SOL_SOCKET, SO_SNDTIMEO, &SOCKET_TIMEOUT, sizeof(SOCKET_TIMEOUT)) != 0)) { - HiLog::Warn(LABEL, "Client: Failed to set opt of socket %d, err %d", connectFd, errno); + HiLog::Warn(LABEL, "Client: Failed to set opt of socket %{public}d, err %{public}d", connectFd, errno); CloseSocket(connectFd); return -1; } if (connect(connectFd, reinterpret_cast(&socketAddr_), socketAddrLen_) < 0) { - HiLog::Warn(LABEL, "Client: Connect on socket fd %d, failed: %d", connectFd, errno); + HiLog::Warn(LABEL, "Client: Connect on socket fd %{public}d, failed: %{public}d", connectFd, errno); CloseSocket(connectFd); return -1; } - HiLog::Debug(LABEL, "Client: Connected on socket fd %d, name '%s'", connectFd, socketAddr_.sun_path); + HiLog::Debug(LABEL, "Client: Connected on socket fd %{public}d, name '%s'", connectFd, socketAddr_.sun_path); return 0; } diff --git a/src/socket/server_socket.cpp b/src/socket/server_socket.cpp index 7a0b1444..0917613c 100644 --- a/src/socket/server_socket.cpp +++ b/src/socket/server_socket.cpp @@ -51,7 +51,7 @@ int ServerSocket::VerifyConnection(int connectFd) void ServerSocket::CloseConnection(int connectFd) { if (connectFd < 0) { - HiLog::Error(LABEL, "Server: Invalid connectFd %d", connectFd); + HiLog::Error(LABEL, "Server: Invalid connectFd %{public}d", connectFd); return; } @@ -65,7 +65,7 @@ void ServerSocket::CloseConnection(int connectFd) close(connectFd); connectFds_.erase(it); - HiLog::Debug(LABEL, "Server: Erase connect fd %d from list", connectFd); + HiLog::Debug(LABEL, "Server: Erase connect fd %{public}d from list", connectFd); } void ServerSocket::SaveConnection(int connectFd) @@ -81,12 +81,12 @@ void ServerSocket::CloseServer() std::lock_guard lock(mutexConnect_); for (const int &fd : connectFds_) { - HiLog::Debug(LABEL, "Server: Closed connection fd %d", fd); + HiLog::Debug(LABEL, "Server: Closed connection fd %{public}d", fd); close(fd); } if ((unlink(socketAddr_.sun_path) != 0) && (errno != ENOENT)) { - HiLog::Error(LABEL, "Server: Failed to unlink, err %d", errno); + HiLog::Error(LABEL, "Server: Failed to unlink, err %{public}d", errno); } connectFds_.clear(); @@ -107,7 +107,7 @@ void ServerSocket::CloseServerMonitor() int ServerSocket::BindSocket(int connectFd) { if (connectFd < 0) { - HiLog::Error(LABEL, "Server: Invalid socket fd: %d", connectFd); + HiLog::Error(LABEL, "Server: Invalid socket fd: %{public}d", connectFd); return -EINVAL; } @@ -116,7 +116,7 @@ int ServerSocket::BindSocket(int connectFd) } if ((unlink(socketAddr_.sun_path) != 0) && (errno != ENOENT)) { - HiLog::Error(LABEL, "Server: Failed to unlink, err %d", errno); + HiLog::Error(LABEL, "Server: Failed to unlink, err %{public}d", errno); return (-errno); } @@ -124,25 +124,25 @@ int ServerSocket::BindSocket(int connectFd) if ((setsockopt(connectFd, SOL_SOCKET, SO_REUSEADDR, &reuseAddr, sizeof(reuseAddr)) != 0) || (setsockopt(connectFd, SOL_SOCKET, SO_RCVTIMEO, &SOCKET_TIMEOUT, sizeof(SOCKET_TIMEOUT)) != 0) || (setsockopt(connectFd, SOL_SOCKET, SO_SNDTIMEO, &SOCKET_TIMEOUT, sizeof(SOCKET_TIMEOUT)) != 0)) { - HiLog::Warn(LABEL, "Server: Failed to set opt of socket %d, err %d", connectFd, errno); + HiLog::Warn(LABEL, "Server: Failed to set opt of socket %{public}d, err %{public}d", connectFd, errno); return (-errno); } if (bind(connectFd, reinterpret_cast(&socketAddr_), socketAddrLen_) < 0) { - HiLog::Error(LABEL, "Server: Bind socket fd %d, failed: %d", connectFd, errno); + HiLog::Error(LABEL, "Server: Bind socket fd %{public}d, failed: %{public}d", connectFd, errno); return (-errno); } if (chown(socketAddr_.sun_path, APPSPAWN_ID_ROOT, APPSPAWN_ID_SYSTEM)) { - HiLog::Error(LABEL, "Server: failed to chown socket fd %d, failed: %d", connectFd, errno); + HiLog::Error(LABEL, "Server: failed to chown socket fd %{public}d, failed: %{public}d", connectFd, errno); return (-errno); } if (chmod(socketAddr_.sun_path, SOCKET_PERM)) { - HiLog::Error(LABEL, "Server: failed to chmod socket fd %d, failed: %d", connectFd, errno); + HiLog::Error(LABEL, "Server: failed to chmod socket fd %{public}d, failed: %{public}d", connectFd, errno); return (-errno); } - HiLog::Debug(LABEL, "Server: Bind socket fd %d success", connectFd); + HiLog::Debug(LABEL, "Server: Bind socket fd %{public}d success", connectFd); return 0; } @@ -165,26 +165,26 @@ int ServerSocket::RegisterServerSocket(int &connectFd) #ifndef NWEB_SPAWN if ((BindSocket(connectFd) != 0) || (listen(connectFd, listenBacklog_) < 0)) { HiLog::Error(LABEL, - "Server: Register socket fd %d with backlog %d error: %d", + "Server: Register socket fd %{public}d with backlog %{public}d error: %{public}d", connectFd, listenBacklog_, errno); if ((unlink(socketAddr_.sun_path) != 0) && (errno != ENOENT)) { - HiLog::Error(LABEL, "Server: Failed to unlink, err %d", errno); + HiLog::Error(LABEL, "Server: Failed to unlink, err %{public}d", errno); } close(connectFd); connectFd = -1; return (-errno); } #endif - HiLog::Debug(LABEL, "Server: Suc to register server socket fd %d", connectFd); + HiLog::Debug(LABEL, "Server: Suc to register server socket fd %{public}d", connectFd); return 0; } int ServerSocket::RegisterServerSocket() { if (socketFd_ >= 0) { - HiLog::Info(LABEL, "Server: Already register server socket %d", socketFd_); + HiLog::Info(LABEL, "Server: Already register server socket %{public}d", socketFd_); return 0; } @@ -194,7 +194,7 @@ int ServerSocket::RegisterServerSocket() int ServerSocket::WaitForConnection(int connectFd) { if (connectFd < 0) { - HiLog::Error(LABEL, "Server: Invalid args: connectFd %d", connectFd); + HiLog::Error(LABEL, "Server: Invalid args: connectFd %{public}d", connectFd); return -EINVAL; } @@ -212,12 +212,12 @@ int ServerSocket::WaitForConnection(int connectFd) if ((setsockopt(connFd, SOL_SOCKET, SO_RCVTIMEO, &SOCKET_TIMEOUT, sizeof(SOCKET_TIMEOUT)) < 0) || (setsockopt(connFd, SOL_SOCKET, SO_SNDTIMEO, &SOCKET_TIMEOUT, sizeof(SOCKET_TIMEOUT)) < 0)) { - HiLog::Warn(LABEL, "Server: Failed to set opt of Connection %d, err %d", connFd, errno); + HiLog::Warn(LABEL, "Server: Failed to set opt of Connection %{public}d, err %{public}d", connFd, errno); close(connFd); return (-errno); } - HiLog::Debug(LABEL, "Server: Connection accepted, connect fd %d", connFd); + HiLog::Debug(LABEL, "Server: Connection accepted, connect fd %{public}d", connFd); return connFd; } diff --git a/test/moduletest/appspawn_module_test.cpp b/test/moduletest/appspawn_module_test.cpp index 33c4e81e..661c09af 100644 --- a/test/moduletest/appspawn_module_test.cpp +++ b/test/moduletest/appspawn_module_test.cpp @@ -71,7 +71,7 @@ bool readFileInfo(char *buffer, const int32_t &pid, const char *fileName) { // Set file path char filePath[FILE_PATH_SIZE]; - if (sprintf_s(filePath, sizeof(filePath), "/proc/%d/%s", pid, fileName) <= 0) { + if (sprintf_s(filePath, sizeof(filePath), "/proc/%{public}d/%s", pid, fileName) <= 0) { HiLog::Error(LABEL, "filePath sprintf_s fail ."); return CHECK_ERROR; } @@ -206,7 +206,7 @@ bool checkProcName(const int32_t &pid, const AppSpawnStartMsg ¶ms) { FILE *fp = nullptr; char cmd[CMD_SIZE]; - if (sprintf_s(cmd, sizeof(cmd), "ps -o ARGS=CMD -p %d |grep -v CMD", pid) <= 0) { + if (sprintf_s(cmd, sizeof(cmd), "ps -o ARGS=CMD -p %{public}d |grep -v CMD", pid) <= 0) { HiLog::Error(LABEL, "cmd sprintf_s fail ."); return CHECK_ERROR; } @@ -245,7 +245,7 @@ bool checkProcName(const int32_t &pid, const AppSpawnStartMsg ¶ms) bool checkProcessIsDestroyed(const int32_t &pid) { char filePath[FILE_PATH_SIZE]; - if (sprintf_s(filePath, sizeof(filePath), "/proc/%d", pid) <= 0) { + if (sprintf_s(filePath, sizeof(filePath), "/proc/%{public}d", pid) <= 0) { HiLog::Error(LABEL, "filePath sprintf_s fail ."); return CHECK_ERROR; } -- Gitee From 4813c70cb4806d519c624e0571eeee10a863e416 Mon Sep 17 00:00:00 2001 From: xionglei6 Date: Tue, 22 Mar 2022 19:33:32 +0800 Subject: [PATCH 2/3] fix: log format print %{public}d Signed-off-by: xionglei6 --- src/appspawn_server.cpp | 22 +++++++++++----------- src/socket/appspawn_socket.cpp | 5 +++-- src/socket/client_socket.cpp | 2 +- test/moduletest/appspawn_module_test.cpp | 6 +++--- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/appspawn_server.cpp b/src/appspawn_server.cpp index d624312a..be8fe78b 100644 --- a/src/appspawn_server.cpp +++ b/src/appspawn_server.cpp @@ -201,7 +201,7 @@ void AppSpawnServer::HandleSignal() sigprocmask(SIG_BLOCK, &mask, nullptr); int signalFd = signalfd(-1, &mask, SFD_CLOEXEC); if (signalFd < 0) { - APPSPAWN_LOGE("Error installing SIGHUP handler: %{public}d", errno); + APPSPAWN_LOGE("Error installing SIGHUP handler: %d", errno); } while (isRunning_) { struct signalfd_siginfo fdsi; @@ -212,13 +212,13 @@ void AppSpawnServer::HandleSignal() pid_t pid; int status; while ((pid = waitpid(-1, &status, WNOHANG)) > 0) { - APPSPAWN_LOGE("HandleSignal: %{public}d", pid); + APPSPAWN_LOGE("HandleSignal: %d", pid); } std::lock_guard lock(mut_); isChildDie_ = true; childPid_ = fdsi.ssi_pid; - APPSPAWN_LOGI("exit app pid = %{public}d", childPid_); + APPSPAWN_LOGI("exit app pid = %d", childPid_); dataCond_.notify_one(); } close(signalFd); @@ -309,10 +309,10 @@ int AppSpawnServer::DoColdStartApp(ClientSocket::AppProperty *appProperty, int f std::vector extractedCmds; extractedCmds.push_back(const_cast("/system/bin/appspawntools")); std::string tmp = std::to_string(fd); - APPSPAWN_LOGI("DoColdStartApp::fd %{public}d %s", fd, tmp.c_str()); + APPSPAWN_LOGI("DoColdStartApp::fd %d %s", fd, tmp.c_str()); extractedCmds.push_back(const_cast(tmp.c_str())); std::string uid = std::to_string(appProperty->uid); - APPSPAWN_LOGI("DoColdStartApp::uid %{public}d gid %{public}d %s", appProperty->uid, appProperty->gid, uid.c_str()); + APPSPAWN_LOGI("DoColdStartApp::uid %d gid %d %s", appProperty->uid, appProperty->gid, uid.c_str()); extractedCmds.push_back(const_cast(uid.c_str())); std::string gid = std::to_string(appProperty->gid); extractedCmds.push_back(const_cast(gid.c_str())); @@ -320,7 +320,7 @@ int AppSpawnServer::DoColdStartApp(ClientSocket::AppProperty *appProperty, int f extractedCmds.push_back(const_cast(appProperty->bundleName)); extractedCmds.push_back(const_cast(appProperty->soPath)); std::string accessTokenId = std::to_string(appProperty->accessTokenId); - APPSPAWN_LOGI("DoColdStartApp::accessTokenId %{public}d %s", appProperty->accessTokenId, accessTokenId.c_str()); + APPSPAWN_LOGI("DoColdStartApp::accessTokenId %d %s", appProperty->accessTokenId, accessTokenId.c_str()); extractedCmds.push_back(const_cast(accessTokenId.c_str())); extractedCmds.push_back(const_cast(appProperty->apl)); APPSPAWN_LOGI("DoColdStartApp renderCmd %s", appProperty->renderCmd); @@ -328,13 +328,13 @@ int AppSpawnServer::DoColdStartApp(ClientSocket::AppProperty *appProperty, int f std::string flags = std::to_string(appProperty->flags); extractedCmds.push_back(const_cast(flags.c_str())); std::string gidCount = std::to_string(appProperty->gidCount); - APPSPAWN_LOGI("DoColdStartApp gidCount %{public}d %s", appProperty->gidCount, gidCount.c_str()); + APPSPAWN_LOGI("DoColdStartApp gidCount %d %s", appProperty->gidCount, gidCount.c_str()); extractedCmds.push_back(const_cast(gidCount.c_str())); for (uint32_t i = 0; i < appProperty->gidCount; i++) { extractedCmds.push_back(const_cast(std::string(std::to_string(appProperty->gidTable[i])).c_str())); } extractedCmds.push_back(nullptr); - APPSPAWN_LOGI("DoColdStartApp extractedCmds %{public}d", extractedCmds.size()); + APPSPAWN_LOGI("DoColdStartApp extractedCmds %d", extractedCmds.size()); int ret = execv(extractedCmds[0], extractedCmds.data()); if (ret) { HiLog::Error(LABEL, "Failed to execv, errno = %{public}d", errno); @@ -420,7 +420,7 @@ bool AppSpawnServer::ServerMain(char *longProcName, int64_t longProcNameLen) isChildDie_ = false; auto iter = appMap_.find(childPid_); if (iter != appMap_.end()) { - APPSPAWN_LOGI("delete pid=%{public}d in appMap", iter->first); + APPSPAWN_LOGI("delete pid=%d in appMap", iter->first); appMap_.erase(iter); } } @@ -440,13 +440,13 @@ bool AppSpawnServer::ServerMain(char *longProcName, int64_t longProcNameLen) appMap_[pid] = appProperty->processName; } socket_->CloseConnection(connectFd); // close socket connection - APPSPAWN_LOGI("AppSpawnServer::parent process create app finish, pid = %{public}d uid %{public}d %s %s", + APPSPAWN_LOGI("AppSpawnServer::parent process create app finish, pid = %d uid %d %s %s", pid, appProperty->uid, appProperty->processName, appProperty->bundleName); } while (appMap_.size() > 0) { auto iter = appMap_.begin(); - APPSPAWN_LOGI("kill app, pid = %{public}d, processName = %s", iter->first, iter->second.c_str()); + APPSPAWN_LOGI("kill app, pid = %d, processName = %s", iter->first, iter->second.c_str()); kill(iter->first, SIGKILL); appMap_.erase(iter); } diff --git a/src/socket/appspawn_socket.cpp b/src/socket/appspawn_socket.cpp index 95ca6467..096fed00 100644 --- a/src/socket/appspawn_socket.cpp +++ b/src/socket/appspawn_socket.cpp @@ -66,7 +66,7 @@ int AppSpawnSocket::PackSocketAddr() } socklen_t pathSize = sizeof(socketAddr_.sun_path); if (pathLen >= pathSize) { - HiLog::Error(LABEL, "Invalid socket name: '%s' too long", socketName_.c_str()); + HiLog::Error(LABEL, "Invalid socket name: '%{public}s' too long", socketName_.c_str()); return -1; } @@ -144,7 +144,8 @@ int AppSpawnSocket::WriteSocketMessage(int socketFd, const void *buf, int len) wLen = write(socketFd, offset, remain); HiLog::Debug(LABEL, "socket fd %{public}d, wLen %zd", socketFd, wLen); if ((wLen <= 0) && (errno != EINTR)) { - HiLog::Error(LABEL, "Failed to write message to fd %{public}d, error %zd: %{public}d", socketFd, wLen, errno); + HiLog::Error(LABEL, "Failed to write message to fd %{public}d, error %zd: %{public}d", + socketFd, wLen, errno); return (-errno); } } diff --git a/src/socket/client_socket.cpp b/src/socket/client_socket.cpp index 5c44996e..f16908fe 100644 --- a/src/socket/client_socket.cpp +++ b/src/socket/client_socket.cpp @@ -80,7 +80,7 @@ int ClientSocket::ConnectSocket(int connectFd) return -1; } - HiLog::Debug(LABEL, "Client: Connected on socket fd %{public}d, name '%s'", connectFd, socketAddr_.sun_path); + HiLog::Debug(LABEL, "Client: Connected on socket fd %{public}d, name '%{public}s'", connectFd, socketAddr_.sun_path); return 0; } diff --git a/test/moduletest/appspawn_module_test.cpp b/test/moduletest/appspawn_module_test.cpp index 661c09af..33c4e81e 100644 --- a/test/moduletest/appspawn_module_test.cpp +++ b/test/moduletest/appspawn_module_test.cpp @@ -71,7 +71,7 @@ bool readFileInfo(char *buffer, const int32_t &pid, const char *fileName) { // Set file path char filePath[FILE_PATH_SIZE]; - if (sprintf_s(filePath, sizeof(filePath), "/proc/%{public}d/%s", pid, fileName) <= 0) { + if (sprintf_s(filePath, sizeof(filePath), "/proc/%d/%s", pid, fileName) <= 0) { HiLog::Error(LABEL, "filePath sprintf_s fail ."); return CHECK_ERROR; } @@ -206,7 +206,7 @@ bool checkProcName(const int32_t &pid, const AppSpawnStartMsg ¶ms) { FILE *fp = nullptr; char cmd[CMD_SIZE]; - if (sprintf_s(cmd, sizeof(cmd), "ps -o ARGS=CMD -p %{public}d |grep -v CMD", pid) <= 0) { + if (sprintf_s(cmd, sizeof(cmd), "ps -o ARGS=CMD -p %d |grep -v CMD", pid) <= 0) { HiLog::Error(LABEL, "cmd sprintf_s fail ."); return CHECK_ERROR; } @@ -245,7 +245,7 @@ bool checkProcName(const int32_t &pid, const AppSpawnStartMsg ¶ms) bool checkProcessIsDestroyed(const int32_t &pid) { char filePath[FILE_PATH_SIZE]; - if (sprintf_s(filePath, sizeof(filePath), "/proc/%{public}d", pid) <= 0) { + if (sprintf_s(filePath, sizeof(filePath), "/proc/%d", pid) <= 0) { HiLog::Error(LABEL, "filePath sprintf_s fail ."); return CHECK_ERROR; } -- Gitee From b2c3ff6c252f6b45881e2931ab9aa1d41ee3c34e Mon Sep 17 00:00:00 2001 From: xionglei6 Date: Tue, 22 Mar 2022 21:03:58 +0800 Subject: [PATCH 3/3] fix: log format print %{public}d Signed-off-by: xionglei6 --- src/socket/client_socket.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/socket/client_socket.cpp b/src/socket/client_socket.cpp index f16908fe..0d664bde 100644 --- a/src/socket/client_socket.cpp +++ b/src/socket/client_socket.cpp @@ -80,7 +80,8 @@ int ClientSocket::ConnectSocket(int connectFd) return -1; } - HiLog::Debug(LABEL, "Client: Connected on socket fd %{public}d, name '%{public}s'", connectFd, socketAddr_.sun_path); + HiLog::Debug(LABEL, "Client: Connected on socket fd %{public}d, name '%{public}s'", + connectFd, socketAddr_.sun_path); return 0; } -- Gitee