diff --git a/src/appspawn_msg_peer.cpp b/src/appspawn_msg_peer.cpp index e658e75520c62916fa2668ae2062dd447a4f8835..dec21fb6f99f8f2a66de93d08329c24f5905cc1e 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 9ee81fc9fbef2ec764472d298c1328b1e7f87e1c..c263b983ee09dd72d0a16b04c0fdcd12cfeb648e 100644 --- a/src/appspawn_server.cpp +++ b/src/appspawn_server.cpp @@ -119,14 +119,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 @@ -144,7 +144,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; } diff --git a/src/socket/appspawn_socket.cpp b/src/socket/appspawn_socket.cpp index 4c0caf6a3461c85ae32ab4714386d11273d73ea4..096fed0024f4f4f34f225686960567a98152c5f6 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; } @@ -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,10 @@ 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 699bbaf942e21e35e7a967df8e5bc96eb995be08..3c240bde54bc08c9b1c1c1e0ea4f6131c3c06a82 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; } @@ -68,16 +68,17 @@ 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); 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); 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 '%{public}s'", + connectFd, socketAddr_.sun_path); return 0; } diff --git a/src/socket/server_socket.cpp b/src/socket/server_socket.cpp index 7a0b14440a81d7cf1aa309f696abb45b3b9a7057..0917613c74addc130715757ed0b2b4d02408bb2a 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; }