Use include <cstring> and std::memcpy etc
This commit is contained in:
17
src/main.cpp
17
src/main.cpp
@@ -6,6 +6,7 @@
|
||||
#include "server.hpp"
|
||||
#include <atomic>
|
||||
#include <csignal>
|
||||
#include <cstring>
|
||||
#include <fcntl.h>
|
||||
#include <iostream>
|
||||
#include <netdb.h>
|
||||
@@ -44,7 +45,7 @@ std::vector<int> create_listen_sockets(const weaseldb::Config &config) {
|
||||
unlink(config.server.unix_socket_path.c_str());
|
||||
|
||||
struct sockaddr_un addr;
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
std::memset(&addr, 0, sizeof(addr));
|
||||
addr.sun_family = AF_UNIX;
|
||||
|
||||
if (config.server.unix_socket_path.length() >= sizeof(addr.sun_path)) {
|
||||
@@ -52,8 +53,8 @@ std::vector<int> create_listen_sockets(const weaseldb::Config &config) {
|
||||
std::abort();
|
||||
}
|
||||
|
||||
strncpy(addr.sun_path, config.server.unix_socket_path.c_str(),
|
||||
sizeof(addr.sun_path) - 1);
|
||||
std::strncpy(addr.sun_path, config.server.unix_socket_path.c_str(),
|
||||
sizeof(addr.sun_path) - 1);
|
||||
|
||||
if (bind(sfd, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
|
||||
perror("bind");
|
||||
@@ -74,7 +75,7 @@ std::vector<int> create_listen_sockets(const weaseldb::Config &config) {
|
||||
struct addrinfo *result, *rp;
|
||||
int s;
|
||||
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
std::memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */
|
||||
hints.ai_socktype = SOCK_STREAM; /* stream socket */
|
||||
hints.ai_flags = AI_PASSIVE; /* For wildcard IP address */
|
||||
@@ -86,7 +87,7 @@ std::vector<int> create_listen_sockets(const weaseldb::Config &config) {
|
||||
s = getaddrinfo(config.server.bind_address.c_str(),
|
||||
std::to_string(config.server.port).c_str(), &hints, &result);
|
||||
if (s != 0) {
|
||||
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(s));
|
||||
std::fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(s));
|
||||
std::abort();
|
||||
}
|
||||
|
||||
@@ -254,9 +255,9 @@ int main(int argc, char *argv[]) {
|
||||
g_server = server.get();
|
||||
|
||||
// Setup signal handling
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
signal(SIGTERM, signal_handler);
|
||||
signal(SIGINT, signal_handler);
|
||||
std::signal(SIGPIPE, SIG_IGN);
|
||||
std::signal(SIGTERM, signal_handler);
|
||||
std::signal(SIGINT, signal_handler);
|
||||
|
||||
std::cout << "Starting WeaselDB HTTP server..." << std::endl;
|
||||
server->run();
|
||||
|
||||
Reference in New Issue
Block a user