diff --git a/src/aws/proxy/client_session_pool_test.cc b/src/aws/proxy/client_session_pool_test.cc index 7f2e510a2..5d7e36826 100644 --- a/src/aws/proxy/client_session_pool_test.cc +++ b/src/aws/proxy/client_session_pool_test.cc @@ -18,6 +18,7 @@ #include +#include #include #include #include @@ -80,47 +81,48 @@ TEST(ClientSessionPoolTest, TestBind) { socket_vendor::BindResponse bind_resp; asio::read(client_sock0, mutable_buffer(&bind_resp, sizeof(bind_resp)), ec); if (ec.failed()) { - exit(1); + std::exit(1); } socket_vendor::ListenResponse listen_resp; asio::read(client_sock0, mutable_buffer(&listen_resp, sizeof(listen_resp)), ec); if (ec.failed()) { - exit(1); + std::exit(1); } // Try to receive a FD uint8_t client_buff[128]; - struct msghdr msg = {}; struct iovec iov = {client_buff, sizeof(client_buff)}; - msg.msg_iov = &iov; - msg.msg_iovlen = 1; - union { struct cmsghdr align; char buf[CMSG_SPACE(sizeof(int))]; } cmsgu; - msg.msg_control = cmsgu.buf; - msg.msg_controllen = sizeof(cmsgu.buf); + struct msghdr msg = { + .msg_iov = &iov, + .msg_iovlen = 1, + .msg_control = cmsgu.buf, + .msg_controllen = sizeof(cmsgu.buf), + }; // client_sock0.wait(Socket::wait_read); - ssize_t bytes_recv = recvmsg(client_sock0.native_handle(), &msg, 0); - if (bytes_recv <= 0) { - exit(2); + if (ssize_t bytes_recv = recvmsg(client_sock0.native_handle(), &msg, 0); + bytes_recv <= 0) { + std::exit(2); + } else { + LOG(INFO) << "Client received " << bytes_recv << " bytes"; } - LOG(INFO) << "Client received " << bytes_recv << " bytes"; struct cmsghdr* cmsg = CMSG_FIRSTHDR(&msg); if (cmsg == nullptr) { - exit(3); + std::exit(3); } if (cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) { - exit(4); + std::exit(4); } int fd = -1; memcpy(&fd, CMSG_DATA(cmsg), sizeof(fd)); if (fd <= 0) { - exit(5); + std::exit(5); } - exit(0); + std::exit(0); } asio::local::stream_protocol::socket proxy_client_sock(io_context); diff --git a/src/core/blob_storage_provider/gcp/gcp_cloud_storage_stress_run.cc b/src/core/blob_storage_provider/gcp/gcp_cloud_storage_stress_run.cc index 78447a9a7..f92d0b0b8 100644 --- a/src/core/blob_storage_provider/gcp/gcp_cloud_storage_stress_run.cc +++ b/src/core/blob_storage_provider/gcp/gcp_cloud_storage_stress_run.cc @@ -56,8 +56,8 @@ int ClearBucketIfPresent(Client& client) { << std::endl; return EXIT_FAILURE; } - auto status = client.DeleteObject(kBucketName, obj_metadata->name()); - if (!status.ok()) { + if (auto status = client.DeleteObject(kBucketName, obj_metadata->name()); + !status.ok()) { std::cout << status.message() << std::endl; return EXIT_FAILURE; } @@ -97,14 +97,14 @@ void WriteObjectOfByteCount(GcpCloudStorageClient& client, int64_t byte_count) { put_blob_context.request->buffer->capacity; put_blob_context.request->buffer->bytes->assign(byte_count, kBlobByte); - assert(client.PutBlob(put_blob_context).Successful()); + ::assert(client.PutBlob(put_blob_context).Successful()); while (!finished) { } if (!result.Successful()) { std::cerr << errors::GetErrorMessage(result.status_code) << std::endl; - exit(EXIT_FAILURE); + std::exit(EXIT_FAILURE); } } @@ -119,9 +119,9 @@ int WriteAndGetBlob(int64_t byte_count) { CreateBucketIfNotExists(*client); auto async_executor = - std::make_shared(kThreadCount, kQueueSize), - io_async_executor = - std::make_shared(kThreadCount, kQueueSize); + std::make_shared(kThreadCount, kQueueSize); + auto io_async_executor = + std::make_shared(kThreadCount, kQueueSize); async_executor->Init(); async_executor->Run(); @@ -134,9 +134,10 @@ int WriteAndGetBlob(int64_t byte_count) { WriteObjectOfByteCount(my_client, byte_count); AsyncContext get_blob_context; - get_blob_context.request = std::make_shared( - GetBlobRequest{std::make_shared(kBucketName), - std::make_shared(kDefaultBlobName)}); + get_blob_context.request = std::make_shared(GetBlobRequest{ + std::make_shared(kBucketName), + std::make_shared(kDefaultBlobName), + }); int return_status; std::atomic_bool finished(false); @@ -194,16 +195,17 @@ int WriteAndGetBlob(int64_t byte_count) { } // namespace } // namespace google::scp::core::test -constexpr int64_t kBytesCount = 100, kKiloBytesCount = 1000, - kMegaBytesCount = 1000 * kKiloBytesCount, - kGigaBytesCount = 1000 * kMegaBytesCount, - k10GigaBytesCount = 10 * kGigaBytesCount, - kTeraBytesCount = 1000 * kGigaBytesCount; +constexpr int64_t kBytesCount = 100; +constexpr int64_t kKiloBytesCount = 1000; +constexpr int64_t kMegaBytesCount = 1000 * kKiloBytesCount; +constexpr int64_t kGigaBytesCount = 1000 * kMegaBytesCount; +constexpr int64_t k10GigaBytesCount = 10 * kGigaBytesCount; +constexpr int64_t kTeraBytesCount = 1000 * kGigaBytesCount; int main(int argc, char* argv[]) { for (auto count : - {kBytesCount, kKiloBytesCount, kMegaBytesCount, - kGigaBytesCount /*, k10GigaBytesCount, kTeraBytesCount*/}) { + {kBytesCount, kKiloBytesCount, kMegaBytesCount, kGigaBytesCount, + /*, k10GigaBytesCount, kTeraBytesCount*/}) { if (google::scp::core::test::WriteAndGetBlob(count) != EXIT_SUCCESS) { return EXIT_FAILURE; } diff --git a/src/core/test/utils/http1_helper/test_http1_server.cc b/src/core/test/utils/http1_helper/test_http1_server.cc index 1494d750f..d71e1083a 100644 --- a/src/core/test/utils/http1_helper/test_http1_server.cc +++ b/src/core/test/utils/http1_helper/test_http1_server.cc @@ -15,6 +15,7 @@ */ #include "test_http1_server.h" +#include #include #include @@ -31,33 +32,35 @@ void HandleErrorIfPresent(const boost::system::error_code& ec, std::string stage) { if (ec) { std::cerr << stage << " failed: " << ec << std::endl; - exit(EXIT_FAILURE); + std::exit(EXIT_FAILURE); } } } // namespace // Uses the C socket library to bind to an unused port, close that socket then // return that port number. -ExecutionResultOr GetUnusedPortNumber() { - int sockfd = socket(AF_INET, SOCK_STREAM, 0); +ExecutionResultOr<::in_port_t> GetUnusedPortNumber() { + int sockfd = ::socket(AF_INET, SOCK_STREAM, 0); if (sockfd < 0) { return FailureExecutionResult( errors::SC_TEST_HTTP1_SERVER_ERROR_GETTING_SOCKET); } - sockaddr_in server_addr; - socklen_t server_len = sizeof(server_addr); - server_addr.sin_family = AF_INET; - server_addr.sin_port = 0; + ::sockaddr_in server_addr = { + .sin_family = AF_INET, + .sin_port = 0, + }; server_addr.sin_addr.s_addr = INADDR_ANY; - if (bind(sockfd, reinterpret_cast(&server_addr), server_len) < 0) { + ::socklen_t server_len = sizeof(server_addr); + if (::bind(sockfd, reinterpret_cast<::sockaddr*>(&server_addr), server_len) < + 0) { return FailureExecutionResult(errors::SC_TEST_HTTP1_SERVER_ERROR_BINDING); } - if (getsockname(sockfd, reinterpret_cast(&server_addr), - &server_len) < 0) { + if (::getsockname(sockfd, reinterpret_cast<::sockaddr*>(&server_addr), + &server_len) < 0) { return FailureExecutionResult( errors::SC_TEST_HTTP1_SERVER_ERROR_GETTING_SOCKET_NAME); } - close(sockfd); + ::close(sockfd); return server_addr.sin_port; } @@ -79,7 +82,7 @@ TestHttp1Server::TestHttp1Server() { ReadFromSocketAndWriteResponse(socket); } else { std::cerr << "accept failed: " << ec << std::endl; - exit(EXIT_FAILURE); + std::exit(EXIT_FAILURE); } }); { @@ -128,7 +131,7 @@ void TestHttp1Server::ReadFromSocketAndWriteResponse(tcp::socket& socket) { HandleErrorIfPresent(ec, "close"); } -in_port_t TestHttp1Server::PortNumber() const { return port_number_; } +::in_port_t TestHttp1Server::PortNumber() const { return port_number_; } std::string TestHttp1Server::GetPath() const { return "http://localhost:" + std::to_string(port_number_); diff --git a/src/core/test/utils/http1_helper/test_http1_server.h b/src/core/test/utils/http1_helper/test_http1_server.h index 0acddf688..3f84ad432 100644 --- a/src/core/test/utils/http1_helper/test_http1_server.h +++ b/src/core/test/utils/http1_helper/test_http1_server.h @@ -35,7 +35,7 @@ namespace google::scp::core::test { // Returns an unused TCP port number. -ExecutionResultOr GetUnusedPortNumber(); +ExecutionResultOr<::in_port_t> GetUnusedPortNumber(); // Lightweight Boost HTTP/1.1 server. // After the constructor returns, the server is ready to accept incoming @@ -46,7 +46,7 @@ class TestHttp1Server { TestHttp1Server(); // Gets the port number the server is running on. - in_port_t PortNumber() const; + ::in_port_t PortNumber() const; // Gets the full path to this server i.e. 'http://localhost:8080' std::string GetPath() const; @@ -92,7 +92,7 @@ class TestHttp1Server { absl::Mutex has_run_mu_; bool has_run_ ABSL_GUARDED_BY(has_run_mu_) = false; - in_port_t port_number_ = 0; + ::in_port_t port_number_ = 0; // Indicates when thread should exit (false). std::atomic_bool run_{true}; diff --git a/src/cpio/client_providers/kms_client_provider/aws/tee_aws_kms_client_provider_utils.cc b/src/cpio/client_providers/kms_client_provider/aws/tee_aws_kms_client_provider_utils.cc index af73e4a0c..246321681 100644 --- a/src/cpio/client_providers/kms_client_provider/aws/tee_aws_kms_client_provider_utils.cc +++ b/src/cpio/client_providers/kms_client_provider/aws/tee_aws_kms_client_provider_utils.cc @@ -18,6 +18,8 @@ #include +#include +#include #include #include @@ -29,25 +31,25 @@ namespace google::scp::cpio::client_providers::utils { absl::StatusOr Exec(absl::Span args) noexcept { int fd[2]; - if (pipe(fd) == -1) { + if (::pipe(fd) == -1) { return absl::ErrnoToStatus(errno, "Exec failed to create a pipe."); } - const pid_t pid = fork(); + const ::pid_t pid = fork(); if (pid == 0) { - close(fd[0]); + ::close(fd[0]); // Redirect child standard output to pipe and execute. - if (dup2(fd[1], STDOUT_FILENO) == -1 || - execv(args[0], const_cast(&args[0])) == -1) { - exit(errno); + if (::dup2(fd[1], STDOUT_FILENO) == -1 || + ::execv(args[0], const_cast(&args[0])) == -1) { + std::exit(errno); } } else if (pid == -1) { return absl::ErrnoToStatus(errno, "Exec failed to fork a child."); } // Only parent gets here (pid > 0). - close(fd[1]); - if (int status; waitpid(pid, &status, /*options=*/0) == -1) { + ::close(fd[1]); + if (int status; ::waitpid(pid, &status, /*options=*/0) == -1) { return absl::ErrnoToStatus(errno, "Exec failed to wait for child."); } else if (!WIFEXITED(status)) { return absl::InternalError(absl::StrCat( @@ -62,9 +64,9 @@ absl::StatusOr Exec(absl::Span args) noexcept { absl::StrJoin(args, " "), "'")); } std::string result; - if (FILE* const stream = fdopen(fd[0], "r"); stream != nullptr) { + if (FILE* const stream = ::fdopen(fd[0], "r"); stream != nullptr) { std::array buffer; - while (fgets(buffer.data(), buffer.size(), stream) != nullptr) { + while (std::fgets(buffer.data(), buffer.size(), stream) != nullptr) { result += buffer.data(); } } else { diff --git a/src/public/cpio/examples/blob_storage_client_test.cc b/src/public/cpio/examples/blob_storage_client_test.cc index 22d9aa6f1..3936c1ce2 100644 --- a/src/public/cpio/examples/blob_storage_client_test.cc +++ b/src/public/cpio/examples/blob_storage_client_test.cc @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include #include #include @@ -94,13 +95,13 @@ int main(int argc, char* argv[]) { if (absl::Status error = blob_storage_client->PutBlob(put_blob_context); !error.ok()) { std::cerr << "Putting blob failed: " << error << std::endl; - exit(EXIT_FAILURE); + std::exit(EXIT_FAILURE); } finished.WaitForNotification(); if (!result.Successful()) { std::cerr << "Putting blob failed asynchronously: " << GetErrorMessage(result.status_code) << std::endl; - exit(EXIT_FAILURE); + std::exit(EXIT_FAILURE); } } { @@ -121,13 +122,13 @@ int main(int argc, char* argv[]) { if (absl::Status error = blob_storage_client->GetBlob(get_blob_context); !error.ok()) { std::cerr << "Getting blob failed: " << error << std::endl; - exit(EXIT_FAILURE); + std::exit(EXIT_FAILURE); } finished.WaitForNotification(); if (!result.Successful()) { std::cerr << "Getting blob failed asynchronously: " << GetErrorMessage(result.status_code) << std::endl; - exit(EXIT_FAILURE); + std::exit(EXIT_FAILURE); } } { @@ -153,13 +154,13 @@ int main(int argc, char* argv[]) { blob_storage_client->ListBlobsMetadata(list_blobs_metadata_context); !error.ok()) { std::cerr << "Listing blobs failed: " << error << std::endl; - exit(EXIT_FAILURE); + std::exit(EXIT_FAILURE); } finished.WaitForNotification(); if (!result.Successful()) { std::cerr << "Listing blobs failed asynchronously: " << GetErrorMessage(result.status_code) << std::endl; - exit(EXIT_FAILURE); + std::exit(EXIT_FAILURE); } } { @@ -179,13 +180,13 @@ int main(int argc, char* argv[]) { blob_storage_client->DeleteBlob(delete_blob_context); !error.ok()) { std::cerr << "Deleting blob failed: " << error << std::endl; - exit(EXIT_FAILURE); + std::exit(EXIT_FAILURE); } finished.WaitForNotification(); if (!result.Successful()) { std::cerr << "Deleting blob failed asynchronously: " << GetErrorMessage(result.status_code) << std::endl; - exit(EXIT_FAILURE); + std::exit(EXIT_FAILURE); } } @@ -217,7 +218,7 @@ int main(int argc, char* argv[]) { blob_storage_client->PutBlobStream(put_blob_stream_context); !error.ok()) { std::cerr << "Putting blob failed: " << error << std::endl; - exit(EXIT_FAILURE); + std::exit(EXIT_FAILURE); } // After this point, the client is waiting for elements to be pushed // onto the queue. @@ -233,14 +234,14 @@ int main(int argc, char* argv[]) { if (auto result = put_blob_stream_context.TryPushRequest(request); !result.Successful()) { std::cerr << "Failed enqueueing a new element" << std::endl; - exit(EXIT_FAILURE); + std::exit(EXIT_FAILURE); } request.mutable_blob_portion()->set_data(" data"); if (auto result = put_blob_stream_context.TryPushRequest(request); !result.Successful()) { std::cerr << "Failed enqueueing a new element" << std::endl; - exit(EXIT_FAILURE); + std::exit(EXIT_FAILURE); } // Marking the context done here tells the client to finalize the upload @@ -251,7 +252,7 @@ int main(int argc, char* argv[]) { if (!result.Successful()) { std::cerr << "Putting blob failed asynchronously: " << GetErrorMessage(result.status_code) << std::endl; - exit(EXIT_FAILURE); + std::exit(EXIT_FAILURE); } } { @@ -291,7 +292,7 @@ int main(int argc, char* argv[]) { if (!result.Successful()) { std::cerr << "Getting blob stream failed asynchronously: " << GetErrorMessage(result.status_code) << std::endl; - exit(EXIT_FAILURE); + std::exit(EXIT_FAILURE); } } { @@ -318,7 +319,7 @@ int main(int argc, char* argv[]) { blob_storage_client->GetBlobStream(get_blob_stream_context); !error.ok()) { std::cerr << "Getting blob stream failed: " << error << std::endl; - exit(EXIT_FAILURE); + std::exit(EXIT_FAILURE); } std::unique_ptr resp = nullptr; @@ -343,7 +344,7 @@ int main(int argc, char* argv[]) { if (!result.Successful()) { std::cerr << "Getting blob stream failed asynchronously: " << GetErrorMessage(result.status_code) << std::endl; - exit(EXIT_FAILURE); + std::exit(EXIT_FAILURE); } } #endif diff --git a/src/roma/tools/v8_cli/v8_shell.cc b/src/roma/tools/v8_cli/v8_shell.cc index d6bde02ad..db6b6b1e5 100644 --- a/src/roma/tools/v8_cli/v8_shell.cc +++ b/src/roma/tools/v8_cli/v8_shell.cc @@ -31,6 +31,8 @@ #include #include +#include + #include "include/libplatform/libplatform.h" #include "include/v8.h" @@ -147,7 +149,7 @@ void Quit(const v8::FunctionCallbackInfo& info) { info[0]->Int32Value(info.GetIsolate()->GetCurrentContext()).FromMaybe(0); fflush(stdout); fflush(stderr); - exit(exit_code); + std::exit(exit_code); } // The callback that is invoked by v8 whenever the JavaScript 'version'