From dfe27f51852225077af056a37acab8345f9977ed Mon Sep 17 00:00:00 2001 From: Muhammad Usama Date: Tue, 24 Nov 2020 21:39:26 +0500 Subject: [PATCH] Removing strerror() call from ereports. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Call to ereport() resets the errno value and using the "strerror(errno)" emmits the wrong error message. The right way is to use %m format specifier instead.   --- src/auth/pool_passwd.c | 2 +- src/main/health_check.c | 6 +-- src/main/main.c | 51 ++++++++++++--------- src/main/pgpool_logger.c | 2 +- src/main/pgpool_main.c | 71 ++++++++++++++++------------- src/pcp_con/pcp_child.c | 14 +++--- src/pcp_con/pcp_worker.c | 10 ++-- src/protocol/child.c | 12 ++--- src/protocol/pool_connection_pool.c | 24 ++++++---- src/protocol/pool_process_query.c | 2 +- src/query_cache/pool_memqcache.c | 39 ++++++++++------ src/utils/pool_sema.c | 16 ++++--- src/utils/pool_shmem.c | 10 ++-- src/utils/pool_stream.c | 28 ++++++------ src/utils/socket_stream.c | 20 ++++---- src/watchdog/watchdog.c | 33 +++++++------- src/watchdog/wd_heartbeat.c | 28 ++++++------ src/watchdog/wd_if.c | 15 +++--- src/watchdog/wd_ipc_conn.c | 12 ++--- src/watchdog/wd_lifecheck.c | 8 ++-- src/watchdog/wd_ping.c | 11 +++-- 21 files changed, 230 insertions(+), 184 deletions(-) diff --git a/src/auth/pool_passwd.c b/src/auth/pool_passwd.c index 15b9282b2..d704f2c4b 100644 --- a/src/auth/pool_passwd.c +++ b/src/auth/pool_passwd.c @@ -83,7 +83,7 @@ pool_init_pool_passwd(char *pool_passwd_filename, POOL_PASSWD_MODE mode) } ereport(ERROR, (errmsg("initializing pool password, failed to open file:\"%s\"", pool_passwd_filename), - errdetail("file open failed with error:\"%s\"", strerror(errno)))); + errdetail("file open failed with error:\"%m\""))); } } diff --git a/src/main/health_check.c b/src/main/health_check.c index 70a32b5a1..d7ed427df 100644 --- a/src/main/health_check.c +++ b/src/main/health_check.c @@ -611,7 +611,7 @@ check_backend_down_request(int node, bool done_requests) ereport(WARNING, (errmsg("check_backend_down_request: failed to open file %s", backend_down_request_file), - errdetail("\"%s\"", strerror(errno)))); + errdetail("%m"))); return false; } @@ -675,7 +675,7 @@ check_backend_down_request(int node, bool done_requests) ereport(WARNING, (errmsg("check_backend_down_request: failed to open file for writing %s", backend_down_request_file), - errdetail("\"%s\"", strerror(errno)))); + errdetail("%m"))); return false; } @@ -684,7 +684,7 @@ check_backend_down_request(int node, bool done_requests) ereport(WARNING, (errmsg("check_backend_down_request: failed to write %s", backend_down_request_file), - errdetail("\"%s\"", strerror(errno)))); + errdetail("%m"))); fclose(fd); return false; } diff --git a/src/main/main.c b/src/main/main.c index 1c83cef70..e687ac0f9 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -258,7 +258,8 @@ main(int argc, char **argv) { ereport(FATAL, (return_code(1), - errmsg("could not reload configuration file pid: %d. reason: %s", pid, strerror(errno)))); + errmsg("could not reload configuration file pid: %d", pid), + errdetail("%m"))); } exit(0); } @@ -463,7 +464,7 @@ daemonize(void) { ereport(FATAL, (errmsg("could not daemonize the pgpool-II"), - errdetail("fork() system call failed with reason: \"%s\"", strerror(errno)))); + errdetail("fork() system call failed with reason: \"%m\""))); } else if (pid > 0) { /* parent */ @@ -475,7 +476,7 @@ daemonize(void) { ereport(FATAL, (errmsg("could not daemonize the pgpool-II"), - errdetail("setsid() system call failed with reason: \"%s\"", strerror(errno)))); + errdetail("setsid() system call failed with reason: \"%m\""))); } #endif @@ -485,14 +486,15 @@ daemonize(void) if (chdir("/")) ereport(WARNING, (errmsg("change directory failed"), - errdetail("chdir() system call failed with reason: \"%s\"", strerror(errno)))); + errdetail("chdir() system call failed with reason: \"%m\""))); /* redirect stdin, stdout and stderr to /dev/null */ i = open("/dev/null", O_RDWR); if (i < 0) { ereport(WARNING, - (errmsg("failed to open \"/dev/null\", open() failed with error \"%s\"", strerror(errno)))); + (errmsg("failed to open \"/dev/null\""), + errdetail("%m"))); } else { @@ -533,7 +535,7 @@ stop_me(void) { ereport(FATAL, (errmsg("could not stop process with pid: %d", pid), - errdetail("\"%s\"", strerror(errno)))); + errdetail("%m"))); } ereport(LOG, (errmsg("stop request sent to pgpool. waiting for termination..."))); @@ -571,8 +573,9 @@ get_pid_file_path(void) if (conf_dir == NULL) { ereport(LOG, - (errmsg("failed to get the dirname of pid file:\"%s\". reason: %s", - pool_config->pid_file_name, strerror(errno)))); + (errmsg("failed to get the dirname of pid file:\"%s\"", + pool_config->pid_file_name), + errdetail("%m"))); return NULL; } path_size = strlen(conf_dir) + strlen(pool_config->pid_file_name) + 1 + 1; @@ -622,16 +625,18 @@ read_pid_file(void) close(fd); pfree(pid_file); ereport(FATAL, - (errmsg("could not read pid file as \"%s\". reason: %s", - pool_config->pid_file_name, strerror(errno)))); + (errmsg("could not read pid file \"%s\"", + pool_config->pid_file_name), + errdetail("%m"))); } else if (readlen == 0) { close(fd); pfree(pid_file); ereport(FATAL, - (errmsg("EOF detected while reading pid file \"%s\". reason: %s", - pool_config->pid_file_name, strerror(errno)))); + (errmsg("EOF detected while reading pid file \"%s\"", + pool_config->pid_file_name), + errdetail("%m"))); } pfree(pid_file); close(fd); @@ -660,8 +665,9 @@ write_pid_file(void) if (fd == -1) { ereport(FATAL, - (errmsg("could not open pid file as %s. reason: %s", - pool_config->pid_file_name, strerror(errno)))); + (errmsg("could not open pid file \"%s\"", + pool_config->pid_file_name), + errdetail("%m"))); } snprintf(pidbuf, sizeof(pidbuf), "%d", (int) getpid()); if (write(fd, pidbuf, strlen(pidbuf) + 1) == -1) @@ -669,23 +675,26 @@ write_pid_file(void) close(fd); pfree(pid_file); ereport(FATAL, - (errmsg("could not write pid file as %s. reason: %s", - pool_config->pid_file_name, strerror(errno)))); + (errmsg("could not write pid file \"%s\"", + pool_config->pid_file_name), + errdetail("%m"))); } if (fsync(fd) == -1) { close(fd); pfree(pid_file); ereport(FATAL, - (errmsg("could not fsync pid file as %s. reason: %s", - pool_config->pid_file_name, strerror(errno)))); + (errmsg("could not fsync pid file \"%s\"", + pool_config->pid_file_name), + errdetail("%m"))); } if (close(fd) == -1) { pfree(pid_file); ereport(FATAL, - (errmsg("could not close pid file as %s. reason: %s", - pool_config->pid_file_name, strerror(errno)))); + (errmsg("could not close pid file \"%s\"", + pool_config->pid_file_name), + errdetail("%m"))); } /* register the call back to delete the pid file at system exit */ on_proc_exit(FileUnlink, (Datum) pid_file); @@ -726,5 +735,5 @@ FileUnlink(int code, Datum path) */ ereport(LOG, (errmsg("unlink failed for file at path \"%s\"", filePath), - errdetail("\"%s\"", strerror(errno)))); + errdetail("%m"))); } diff --git a/src/main/pgpool_logger.c b/src/main/pgpool_logger.c index 40d238e59..2f84cec52 100644 --- a/src/main/pgpool_logger.c +++ b/src/main/pgpool_logger.c @@ -277,7 +277,7 @@ SysLoggerMain(int argc, char *argv[]) if (mkdir(pool_config->log_directory, S_IREAD | S_IWRITE | S_IEXEC) == -1) { ereport(LOG, - (errmsg("pgpool logger, failed to create directory:\"%s\". error:\"%s\"", pool_config->log_directory, strerror(errno)))); + (errmsg("pgpool logger, failed to create directory:\"%s\". error:\"%m\"", pool_config->log_directory))); } } if (strcmp(pool_config->log_filename, currentLogFilename) != 0) diff --git a/src/main/pgpool_main.c b/src/main/pgpool_main.c index 21f1ad574..604fa9c89 100644 --- a/src/main/pgpool_main.c +++ b/src/main/pgpool_main.c @@ -627,7 +627,7 @@ pcp_fork_a_child(int unix_fd, int inet_fd, char *pcp_conf_file) else if (pid == -1) { ereport(FATAL, - (errmsg("fork() failed. reason: %s", strerror(errno)))); + (errmsg("fork() failed. reason: %m"))); } return pid; @@ -674,7 +674,7 @@ fork_a_child(int *fds, int id) { ereport(FATAL, (errmsg("failed to fork a child"), - errdetail("system call fork() failed with reason: %s", strerror(errno)))); + errdetail("system call fork() failed with reason: %m"))); } return pid; @@ -720,7 +720,7 @@ worker_fork_a_child(ProcessType type, void (*func) (), void *params) { ereport(FATAL, (errmsg("failed to fork a child"), - errdetail("system call fork() failed with reason: %s", strerror(errno)))); + errdetail("system call fork() failed with reason: %m"))); } return pid; @@ -754,7 +754,7 @@ create_inet_domain_sockets(const char *hostname, const int port) { ereport(FATAL, (errmsg("failed to create INET domain socket"), - errdetail("asprintf() failed: %s", strerror(errno)))); + errdetail("asprintf() failed: %m"))); } if ((ret = getaddrinfo((!hostname || strcmp(hostname, "*") == 0) ? NULL : hostname, portstr, &hints, &res)) != 0) @@ -803,7 +803,7 @@ create_inet_domain_sockets(const char *hostname, const int port) */ ereport(LOG, (errmsg("perhaps failed to create INET domain socket"), - errdetail("socket(%s) failed: \"%s\"", buf, strerror(errno)))); + errdetail("socket(%s) failed: \"%m\"", buf))); continue; } @@ -812,7 +812,7 @@ create_inet_domain_sockets(const char *hostname, const int port) { ereport(FATAL, (errmsg("failed to create INET domain socket"), - errdetail("socket error \"%s\"", strerror(errno)))); + errdetail("socket error \"%m\""))); } if (walk->ai_family == AF_INET6) @@ -828,7 +828,7 @@ create_inet_domain_sockets(const char *hostname, const int port) { ereport(LOG, (errmsg("perhaps failed to create INET domain socket"), - errdetail("setsockopt(%s, IPV6_V6ONLY) failed: \"%s\"", buf, strerror(errno)))); + errdetail("setsockopt(%s, IPV6_V6ONLY) failed: \"%m\"", buf))); } } @@ -836,7 +836,7 @@ create_inet_domain_sockets(const char *hostname, const int port) { ereport(FATAL, (errmsg("failed to create INET domain socket"), - errdetail("bind on socket failed with error \"%s\"", strerror(errno)))); + errdetail("bind on socket failed with error \"%m\""))); } backlog = pool_config->num_init_children * pool_config->listen_backlog_multiplier; @@ -848,7 +848,7 @@ create_inet_domain_sockets(const char *hostname, const int port) if (status < 0) ereport(FATAL, (errmsg("failed to create INET domain socket"), - errdetail("listen on socket failed with error \"%s\"", strerror(errno)))); + errdetail("listen on socket failed with error \"%m\""))); sockfds[n++] = fd; } @@ -883,14 +883,14 @@ create_inet_domain_socket(const char *hostname, const int port) { ereport(FATAL, (errmsg("failed to create INET domain socket"), - errdetail("socket error \"%s\"", strerror(errno)))); + errdetail("%m"))); } if ((setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &one, sizeof(one))) == -1) { ereport(FATAL, (errmsg("failed to create INET domain socket"), - errdetail("socket error \"%s\"", strerror(errno)))); + errdetail("%m"))); } memset((char *) &addr, 0, sizeof(addr)); @@ -948,7 +948,7 @@ create_inet_domain_socket(const char *hostname, const int port) if (status < 0) ereport(FATAL, (errmsg("failed to create INET domain socket"), - errdetail("listen on socket failed with error \"%s\"", strerror(errno)))); + errdetail("listen on socket failed with error \"%m\""))); return fd; } @@ -972,7 +972,7 @@ create_unix_domain_socket(struct sockaddr_un un_addr_tmp) { ereport(FATAL, (errmsg("failed to create a socket"), - errdetail("Failed to create UNIX domain socket. error: \"%s\"", strerror(errno)))); + errdetail("Failed to create UNIX domain socket. error: \"%m\""))); } memset((char *) &addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; @@ -983,14 +983,14 @@ create_unix_domain_socket(struct sockaddr_un un_addr_tmp) { ereport(FATAL, (errmsg("failed to bind a socket: \"%s\"", un_addr_tmp.sun_path), - errdetail("bind socket failed with error: \"%s\"", strerror(errno)))); + errdetail("bind socket failed with error: \"%m\""))); } if (chmod(un_addr_tmp.sun_path, 0777) == -1) { ereport(FATAL, (errmsg("failed to bind a socket: \"%s\"", un_addr_tmp.sun_path), - errdetail("system call chmod failed with error: \"%s\"", strerror(errno)))); + errdetail("system call chmod failed with error: \"%m\""))); } status = listen(fd, PGPOOLMAXLITSENQUEUELENGTH); @@ -998,7 +998,7 @@ create_unix_domain_socket(struct sockaddr_un un_addr_tmp) { ereport(FATAL, (errmsg("failed to bind a socket: \"%s\"", un_addr_tmp.sun_path), - errdetail("system call listen() failed with error: \"%s\"", strerror(errno)))); + errdetail("system call listen() failed with error: \"%m\""))); } return fd; } @@ -1098,7 +1098,8 @@ terminate_all_childrens(int sig) if (wpid == -1 && errno != ECHILD) ereport(LOG, - (errmsg("wait() failed. reason:%s", strerror(errno)))); + (errmsg("wait() failed"), + errdetail("%m"))); } @@ -1201,7 +1202,8 @@ static RETSIGTYPE sigusr1_handler(int sig) #ifdef NOT_USED if (write(pipe_fds[1], "\0", 1) < 0) ereport(WARNING, - (errmsg("SIGUSR1 handler: write to pipe failed with error \"%s\"", strerror(errno)))); + (errmsg("SIGUSR1 handler: write to pipe failed"), + errdetail("%m"))); #endif POOL_SETMASK(&UnBlockSig); @@ -2033,7 +2035,8 @@ failover(void) else { ereport(WARNING, - (errmsg("failover: waitpid failed. reason: %s", strerror(errno)))); + (errmsg("failover: waitpid failed"), + errdetail("%m"))); continue; } } @@ -2167,7 +2170,8 @@ static RETSIGTYPE reap_handler(int sig) #ifdef NOT_USED if (pipe_fds[1] && write(pipe_fds[1], "\0", 1) < 0) ereport(WARNING, - (errmsg("reap_handler: write to pipe failed with error \"%s\"", strerror(errno)))); + (errmsg("reap_handler: write to pipe failed"), + errdetail("%m"))); #endif POOL_SETMASK(&UnBlockSig); @@ -2513,7 +2517,8 @@ static RETSIGTYPE wakeup_handler(int sig) #ifdef NOT_USED if (write(pipe_fds[1], "\0", 1) < 0) ereport(WARNING, - (errmsg("wakeup_handler: write to pipe failed with error \"%s\"", strerror(errno)))); + (errmsg("wakeup_handler: write to pipe failed"), + errdetail("%m"))); #endif POOL_SETMASK(&UnBlockSig); } @@ -2534,7 +2539,8 @@ static RETSIGTYPE reload_config_handler(int sig) #ifdef NOT_USED if (write(pipe_fds[1], "\0", 1) < 0) ereport(WARNING, - (errmsg("reload_config_handler: write to pipe failed with error \"%s\"", strerror(errno)))); + (errmsg("reload_config_handler: write to pipe failed"), + errdetail("%m"))); #endif POOL_SETMASK(&UnBlockSig); @@ -2598,7 +2604,8 @@ pool_pause(struct timeval *timeout) { if (read(pipe_fds[0], &dummy, 1) < 0) ereport(WARNING, - (errmsg("pool_pause: read on pipe failed with error \"%s\"", strerror(errno)))); + (errmsg("pool_pause: read on pipe failed"), + errdetail("%m"))); } return n; } @@ -3257,7 +3264,8 @@ fork_follow_child(int old_main_node, int new_primary, int old_primary) else if (pid == -1) { ereport(WARNING, - (errmsg("follow fork() failed with reason: \"%s\"", strerror(errno)))); + (errmsg("follow fork() failed"), + errdetail("%m"))); exit(1); } return pid; @@ -3444,7 +3452,8 @@ read_status_file(bool discard_status) (errmsg("Backend status file %s discarded", fnamebuf))); else ereport(WARNING, - (errmsg("failed to discard backend status file: \"%s\" with reason: \"%s\"", fnamebuf, strerror(errno)))); + (errmsg("failed to discard backend status file: \"%s\"", fnamebuf), + errdetail("%m"))); return 0; } @@ -3611,7 +3620,7 @@ write_status_file(void) { ereport(WARNING, (errmsg("failed to open status file at: \"%s\"", fnamebuf), - errdetail("\"%s\"", strerror(errno)))); + errdetail("%m"))); return -1; } @@ -3632,7 +3641,7 @@ write_status_file(void) { ereport(WARNING, (errmsg("failed to write status file at: \"%s\"", fnamebuf), - errdetail("\"%s\"", strerror(errno)))); + errdetail("%m"))); fclose(fd); return -1; } @@ -3642,7 +3651,7 @@ write_status_file(void) { ereport(WARNING, (errmsg("failed to write status file at: \"%s\"", fnamebuf), - errdetail("\"%s\"", strerror(errno)))); + errdetail("%m"))); fclose(fd); return -1; } @@ -3651,7 +3660,7 @@ write_status_file(void) { ereport(WARNING, (errmsg("failed to get file number. fsync() will not be performed: \"%s\"", fnamebuf), - errdetail("\"%s\"", strerror(errno)))); + errdetail("%m"))); fclose(fd); return -1; } @@ -3659,7 +3668,7 @@ write_status_file(void) { ereport(WARNING, (errmsg("failed to fsync(): \"%s\"", fnamebuf), - errdetail("\"%s\"", strerror(errno)))); + errdetail("%m"))); fclose(fd); return -1; } @@ -3705,7 +3714,7 @@ FileUnlink(int code, Datum path) */ ereport(LOG, (errmsg("unlink failed for file at path \"%s\"", filePath), - errdetail("%s", strerror(errno)))); + errdetail("%m"))); } static void diff --git a/src/pcp_con/pcp_child.c b/src/pcp_con/pcp_child.c index 49042d399..59a304097 100644 --- a/src/pcp_con/pcp_child.c +++ b/src/pcp_con/pcp_child.c @@ -195,7 +195,7 @@ pcp_do_accept(int unix_fd, int inet_fd) return -1; ereport(ERROR, (errmsg("unable to accept new pcp connection"), - errdetail("select system call failed with error : \"%s\"", strerror(errno)))); + errdetail("select system call failed with error : \"%m\""))); } if (FD_ISSET(unix_fd, &readmask)) { @@ -219,7 +219,7 @@ pcp_do_accept(int unix_fd, int inet_fd) if (errno != EAGAIN && errno != EWOULDBLOCK) ereport(ERROR, (errmsg("unable to accept new pcp connection"), - errdetail("socket accept system call failed with error : \"%s\"", strerror(errno)))); + errdetail("socket accept system call failed with error : \"%m\""))); } if (pcp_got_sighup) { @@ -242,7 +242,7 @@ pcp_do_accept(int unix_fd, int inet_fd) close(afd); ereport(ERROR, (errmsg("unable to accept new pcp connection"), - errdetail("setsockopt system call failed with error : \"%s\"", strerror(errno)))); + errdetail("setsockopt system call failed with error : \"%m\""))); } if (setsockopt(afd, SOL_SOCKET, SO_KEEPALIVE, (char *) &on, @@ -251,7 +251,7 @@ pcp_do_accept(int unix_fd, int inet_fd) close(afd); ereport(ERROR, (errmsg("unable to accept new pcp connection"), - errdetail("setsockopt system call failed with error : \"%s\"", strerror(errno)))); + errdetail("setsockopt system call failed with error : \"%m\""))); } } return afd; @@ -283,7 +283,8 @@ start_pcp_command_processor_process(int port) else if (pid == -1) { ereport(FATAL, - (errmsg("fork() failed. reason: %s", strerror(errno)))); + (errmsg("fork() failed"), + errdetail("%m"))); } else /* parent */ { @@ -442,7 +443,8 @@ pcp_child_will_die(int code, Datum arg) if (wpid == -1 && errno != ECHILD) ereport(WARNING, - (errmsg("wait() on pcp worker children failed. reason:%s", strerror(errno)))); + (errmsg("wait() on pcp worker children failed"), + errdetail("%m"))); POOL_SETMASK(&UnBlockSig); } diff --git a/src/pcp_con/pcp_worker.c b/src/pcp_con/pcp_worker.c index b315afa61..cf123e7ee 100644 --- a/src/pcp_con/pcp_worker.c +++ b/src/pcp_con/pcp_worker.c @@ -401,14 +401,14 @@ unset_nonblock(int fd) { ereport(FATAL, (errmsg("unable to connect"), - errdetail("fcntl system call failed with error : \"%s\"", strerror(errno)))); + errdetail("fcntl system call failed with error : \"%m\""))); } if (fcntl(fd, F_SETFL, var & ~O_NONBLOCK) == -1) { ereport(FATAL, (errmsg("unable to connect"), - errdetail("fcntl system call failed with error : \"%s\"", strerror(errno)))); + errdetail("fcntl system call failed with error : \"%m\""))); } } @@ -446,7 +446,7 @@ user_authenticate(char *buf, char *passwd_file, char *salt, int salt_len) { ereport(FATAL, (errmsg("failed to authenticate PCP user"), - errdetail("could not open %s. reason: %s", passwd_file, strerror(errno)))); + errdetail("could not open %s. reason: %m", passwd_file))); return 0; } @@ -1418,7 +1418,7 @@ do_pcp_flush(PCP_CONNECTION * frontend) if (pcp_flush(frontend) < 0) ereport(FATAL, (errmsg("failed to flush data to client"), - errdetail("pcp_flush failed with error : \"%s\"", strerror(errno)))); + errdetail("pcp_flush failed with error : \"%m\""))); } /* @@ -1430,7 +1430,7 @@ do_pcp_read(PCP_CONNECTION * pc, void *buf, int len) if (pcp_read(pc, buf, len)) ereport(FATAL, (errmsg("unable to read from client"), - errdetail("pcp_read failed with error : \"%s\"", strerror(errno)))); + errdetail("pcp_read failed with error : \"%m\""))); } int diff --git a/src/protocol/child.c b/src/protocol/child.c index 02bc52e58..bfcbea048 100644 --- a/src/protocol/child.c +++ b/src/protocol/child.c @@ -1605,7 +1605,7 @@ wait_for_new_connections(int *fds, struct timeval *timeout, SockAddr *saddr) return RETRY; ereport(ERROR, (errmsg("failed to accept user connection"), - errdetail("select on socket failed with error : \"%s\"", strerror(errno)))); + errdetail("select on socket failed with error : \"%m\""))); } /* timeout */ @@ -1664,7 +1664,7 @@ retry_accept: if (errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR) ereport(ERROR, (errmsg("failed to accept user connection"), - errdetail("accept on socket failed with error : \"%s\"", strerror(errno)))); + errdetail("accept on socket failed with error : \"%m\""))); return RETRY; } @@ -1681,7 +1681,7 @@ retry_accept: sizeof(on)) < 0) { ereport(WARNING, - (errmsg("wait_for_new_connections: setsockopt failed with error \"%s\"", strerror(errno)))); + (errmsg("wait_for_new_connections: setsockopt failed with error \"%m\""))); close(afd); return -1; } @@ -1850,12 +1850,12 @@ get_connection(int front_end_fd, SockAddr *saddr) sizeof(on)) < 0) ereport(ERROR, (errmsg("failed to accept user connection"), - errdetail("setsockopt on socket failed with error : \"%s\"", strerror(errno)))); + errdetail("setsockopt on socket failed with error : \"%m\""))); if (setsockopt(front_end_fd, SOL_SOCKET, SO_KEEPALIVE, (char *) &on, sizeof(on)) < 0) ereport(FATAL, (errmsg("failed to accept user connection"), - errdetail("setsockopt on socket failed with error : \"%s\"", strerror(errno)))); + errdetail("setsockopt on socket failed with error : \"%m\""))); } @@ -1864,7 +1864,7 @@ get_connection(int front_end_fd, SockAddr *saddr) close(front_end_fd); ereport(ERROR, (errmsg("failed to accept user connection"), - errdetail("unable to open connection with remote end : \"%s\"", strerror(errno)))); + errdetail("unable to open connection with remote end : \"%m\""))); } /* save ip address for hba */ diff --git a/src/protocol/pool_connection_pool.c b/src/protocol/pool_connection_pool.c index f00b5638c..465a17f06 100644 --- a/src/protocol/pool_connection_pool.c +++ b/src/protocol/pool_connection_pool.c @@ -521,7 +521,7 @@ connect_unix_domain_socket_by_port(int port, char *socket_dir, bool retry) { ereport(LOG, (errmsg("failed to connect to PostgreSQL server by unix domain socket"), - errdetail("create socket failed with error \"%s\"", strerror(errno)))); + errdetail("create socket failed with error \"%m\""))); return -1; } @@ -548,7 +548,7 @@ connect_unix_domain_socket_by_port(int port, char *socket_dir, bool retry) close(fd); ereport(LOG, (errmsg("failed to connect to PostgreSQL server by unix domain socket"), - errdetail("connect to \"%s\" failed with error \"%s\"", addr.sun_path, strerror(errno)))); + errdetail("connect to \"%s\" failed with error \"%m\"", addr.sun_path))); return -1; } @@ -618,7 +618,8 @@ connect_with_timeout(int fd, struct addrinfo *walk, char *host, int port, bool r if (errno != EINPROGRESS && errno != EALREADY) { ereport(LOG, - (errmsg("failed to connect to PostgreSQL server on \"%s:%d\" with error \"%s\"", host, port, strerror(errno)))); + (errmsg("failed to connect to PostgreSQL server on \"%s:%d\"", host, port), + errdetail("%m"))); return false; } @@ -678,7 +679,8 @@ connect_with_timeout(int fd, struct addrinfo *walk, char *host, int port, bool r { /* Solaris returns error in this case */ ereport(LOG, - (errmsg("failed to connect to PostgreSQL server on \"%s:%d\", getsockopt() failed with error \"%s\"", host, port, strerror(errno)))); + (errmsg("failed to connect to PostgreSQL server on \"%s:%d\", getsockopt() failed", host, port), + errdetail("%m"))); return false; } @@ -687,7 +689,8 @@ connect_with_timeout(int fd, struct addrinfo *walk, char *host, int port, bool r if (error != 0) { ereport(LOG, - (errmsg("failed to connect to PostgreSQL server on \"%s:%d\", getsockopt() detected error \"%s\"", host, port, strerror(error)))); + (errmsg("failed to connect to PostgreSQL server on \"%s:%d\", getsockopt() failed", host, port), + errdetail("%m"))); return false; } } @@ -734,7 +737,7 @@ connect_with_timeout(int fd, struct addrinfo *walk, char *host, int port, bool r { ereport(LOG, (errmsg("failed to connect to PostgreSQL server on \"%s:%d\" using INET socket", host, port), - errdetail("select() system call failed with an error \"%s\"", strerror(errno)))); + errdetail("select() system call failed with error \"%m\""))); } close(fd); return false; @@ -769,7 +772,8 @@ connect_inet_domain_socket_by_port(char *host, int port, bool retry) if (asprintf(&portstr, "%d", port) == -1) { ereport(WARNING, - (errmsg("failed to connect to PostgreSQL server, asprintf() failed with error \"%s\"", strerror(errno)))); + (errmsg("failed to connect to PostgreSQL server, asprintf() failed"), + errdetail("%m"))); return -1; } @@ -795,7 +799,8 @@ connect_inet_domain_socket_by_port(char *host, int port, bool retry) if (fd < 0) { ereport(WARNING, - (errmsg("failed to connect to PostgreSQL server, socket() failed with error \"%s\"", strerror(errno)))); + (errmsg("failed to connect to PostgreSQL server, socket() failed"), + errdetail("%m"))); continue; } @@ -805,7 +810,8 @@ connect_inet_domain_socket_by_port(char *host, int port, bool retry) sizeof(on)) < 0) { ereport(WARNING, - (errmsg("failed to connect to PostgreSQL server, setsockopt() failed with error \"%s\"", strerror(errno)))); + (errmsg("failed to connect to PostgreSQL server, setsockopt() failed"), + errdetail("%m"))); close(fd); freeaddrinfo(res); diff --git a/src/protocol/pool_process_query.c b/src/protocol/pool_process_query.c index 8afdce741..dbe32e1b0 100644 --- a/src/protocol/pool_process_query.c +++ b/src/protocol/pool_process_query.c @@ -4760,7 +4760,7 @@ SELECT_RETRY: ereport(FATAL, (errmsg("unable to read data"), - errdetail("select() system call failed with reason \"%s\"", strerror(errno)))); + errdetail("select() system call failed with reason \"%m\""))); } /* select timeout */ diff --git a/src/query_cache/pool_memqcache.c b/src/query_cache/pool_memqcache.c index 61726c29b..9c83eaaba 100644 --- a/src/query_cache/pool_memqcache.c +++ b/src/query_cache/pool_memqcache.c @@ -1587,7 +1587,8 @@ pool_add_table_oid_map(POOL_CACHEKEY * cachekey, int num_table_oids, int *table_ if (errno != EEXIST) { ereport(WARNING, - (errmsg("memcache: adding table oid maps, failed to create directory:\"%s\". error:\"%s\"", dir, strerror(errno)))); + (errmsg("memcache: adding table oid maps, failed to create directory:\"%s\"", dir), + errdetail("%m"))); return; } } @@ -1613,7 +1614,8 @@ pool_add_table_oid_map(POOL_CACHEKEY * cachekey, int num_table_oids, int *table_ if (errno != EEXIST) { ereport(WARNING, - (errmsg("memcache: adding table oid maps, failed to create directory:\"%s\". error:\"%s\"", path, strerror(errno)))); + (errmsg("memcache: adding table oid maps, failed to create directory:\"%s\"", path), + errdetail("%m"))); return; } } @@ -1641,7 +1643,8 @@ pool_add_table_oid_map(POOL_CACHEKEY * cachekey, int num_table_oids, int *table_ if ((fd = open(path, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR)) == -1) { ereport(WARNING, - (errmsg("memcache: adding table oid maps, failed to open file:\"%s\". error:\"%s\"", path, strerror(errno)))); + (errmsg("memcache: adding table oid maps, failed to open file:\"%s\"", path), + errdetail("%m"))); return; } @@ -1654,7 +1657,8 @@ pool_add_table_oid_map(POOL_CACHEKEY * cachekey, int num_table_oids, int *table_ if (sts == -1) { ereport(WARNING, - (errmsg("memcache: adding table oid maps, failed to lock file:\"%s\". error:\"%s\"", path, strerror(errno)))); + (errmsg("memcache: adding table oid maps, failed to lock file:\"%s\"", path), + errdetail("%m"))); close(fd); return; @@ -1673,7 +1677,8 @@ pool_add_table_oid_map(POOL_CACHEKEY * cachekey, int num_table_oids, int *table_ if (sts == -1) { ereport(WARNING, - (errmsg("memcache: adding table oid maps, failed to read file:\"%s\". error:\"%s\"", path, strerror(errno)))); + (errmsg("memcache: adding table oid maps, failed to read file:\"%s\"", path), + errdetail("%m"))); close(fd); return; } @@ -1705,7 +1710,8 @@ pool_add_table_oid_map(POOL_CACHEKEY * cachekey, int num_table_oids, int *table_ if (lseek(fd, 0, SEEK_END) == -1) { ereport(WARNING, - (errmsg("memcache: adding table oid maps, failed seek on file:\"%s\". error:\"%s\"", path, strerror(errno)))); + (errmsg("memcache: adding table oid maps, failed seek on file:\"%s\"", path), + errdetail("%m"))); close(fd); return; } @@ -1717,7 +1723,8 @@ pool_add_table_oid_map(POOL_CACHEKEY * cachekey, int num_table_oids, int *table_ if (sts == -1 || sts != len) { ereport(WARNING, - (errmsg("memcache: adding table oid maps, failed to write file:\"%s\". error:\"%s\"", path, strerror(errno)))); + (errmsg("memcache: adding table oid maps, failed to write file:\"%s\"", path), + errdetail("%m"))); close(fd); return; } @@ -1739,7 +1746,7 @@ pool_discard_oid_maps(void) if (system(command) == -1) ereport(WARNING, (errmsg("unable to execute command \"%s\"", command), - errdetail("system() command failed with error \"%s\"", strerror(errno)))); + errdetail("system() command failed with error \"%m\""))); } @@ -1761,7 +1768,7 @@ pool_discard_oid_maps_by_db(int dboid) if (system(command) == -1) ereport(WARNING, (errmsg("unable to execute command \"%s\"", command), - errdetail("system() command failed with error \"%s\"", strerror(errno)))); + errdetail("system() command failed with error \"%m\""))); } } @@ -1789,7 +1796,8 @@ pool_invalidate_query_cache(int num_table_oids, int *table_oid, bool unlinkp, in if (errno != EEXIST) { ereport(WARNING, - (errmsg("memcache: invalidating query cache, failed to create directory:\"%s\". error:\"%s\"", dir, strerror(errno)))); + (errmsg("memcache: invalidating query cache, failed to create directory:\"%s\"", dir), + errdetail("%m"))); return; } } @@ -1818,7 +1826,8 @@ pool_invalidate_query_cache(int num_table_oids, int *table_oid, bool unlinkp, in if (errno != EEXIST) { ereport(WARNING, - (errmsg("memcache: invalidating query cache, failed to create directory:\"%s\". error:\"%s\"", path, strerror(errno)))); + (errmsg("memcache: invalidating query cache, failed to create directory:\"%s\"", path), + errdetail("%m"))); return; } } @@ -1852,7 +1861,7 @@ pool_invalidate_query_cache(int num_table_oids, int *table_oid, bool unlinkp, in */ ereport(DEBUG1, (errmsg("memcache invalidating query cache"), - errdetail("failed to open \"%s\". reason:\"%s\"", path, strerror(errno)))); + errdetail("failed to open \"%s\". reason:\"%m\"", path))); continue; } @@ -1865,7 +1874,8 @@ pool_invalidate_query_cache(int num_table_oids, int *table_oid, bool unlinkp, in if (sts == -1) { ereport(WARNING, - (errmsg("memcache: invalidating query cache, failed to lock file:\"%s\". error:\"%s\"", path, strerror(errno)))); + (errmsg("memcache: invalidating query cache, failed to lock file:\"%s\"", path), + errdetail("%m"))); close(fd); return; } @@ -1875,7 +1885,8 @@ pool_invalidate_query_cache(int num_table_oids, int *table_oid, bool unlinkp, in if (sts == -1) { ereport(WARNING, - (errmsg("memcache: invalidating query cache, failed to read file:\"%s\". error:\"%s\"", path, strerror(errno)))); + (errmsg("memcache: invalidating query cache, failed to read file:\"%s\"", path), + errdetail("%m"))); close(fd); return; diff --git a/src/utils/pool_sema.c b/src/utils/pool_sema.c index 9558c7fd7..0f3a3319c 100644 --- a/src/utils/pool_sema.c +++ b/src/utils/pool_sema.c @@ -68,7 +68,7 @@ IpcSemaphoreKill(int status, Datum semId) if (semctl(semId, 0, IPC_RMID) < 0) ereport(LOG, (errmsg("removing semaphore set"), - errdetail("semctl(%lu, 0, IPC_RMID, ...) failed: %s", semId, strerror(errno)))); + errdetail("semctl(%lu, 0, IPC_RMID, ...) failed with error \"%m\"", semId))); } /* @@ -84,7 +84,8 @@ pool_semaphore_create(int numSems) if (semId < 0) ereport(FATAL, - (errmsg("Unable to create semaphores:%d error:\"%s\"", numSems, strerror(errno)))); + (errmsg("Unable to create semaphores:%d", numSems), + errdetail("%m"))); on_shmem_exit(IpcSemaphoreKill, semId); @@ -96,7 +97,7 @@ pool_semaphore_create(int numSems) semun.val = 1; if (semctl(semId, i, SETVAL, semun) < 0) ereport(FATAL, - (errmsg("Unable to create semaphores:%d error:\"%s\"", numSems, strerror(errno)), + (errmsg("Unable to create semaphores:%d error:\"%m\"", numSems), errdetail("semctl(%d, %d, SETVAL, %d) failed", semId, i, semun.val))); } } @@ -126,7 +127,8 @@ pool_semaphore_lock(int semNum) if (errStatus < 0) ereport(WARNING, - (errmsg("failed to lock semaphore error:\"%s\"", strerror(errno)))); + (errmsg("failed to lock semaphore"), + errdetail("%m"))); } /* @@ -164,7 +166,8 @@ pool_semaphore_lock_allow_interrupt(int semNum) else { ereport(WARNING, - (errmsg("failed to lock semaphore error:\"%s\"", strerror(errno)))); + (errmsg("failed to lock semaphore"), + errdetail("%m"))); return -1; } } @@ -197,5 +200,6 @@ pool_semaphore_unlock(int semNum) if (errStatus < 0) ereport(WARNING, - (errmsg("failed to unlock semaphore error:\"%s\"", strerror(errno)))); + (errmsg("failed to unlock semaphore"), + errdetail("%m"))); } diff --git a/src/utils/pool_shmem.c b/src/utils/pool_shmem.c index a9f51fd1b..787db3f15 100644 --- a/src/utils/pool_shmem.c +++ b/src/utils/pool_shmem.c @@ -55,7 +55,7 @@ pool_shared_memory_create(size_t size) if (shmid < 0) ereport(FATAL, (errmsg("could not create shared memory for request size: %ld", size), - errdetail("shared memory creation failed with error \"%s\"", strerror(errno)))); + errdetail("shared memory creation failed with error \"%m\""))); /* Register on-exit routine to delete the new segment */ on_shmem_exit(IpcMemoryDelete, shmid); @@ -66,7 +66,7 @@ pool_shared_memory_create(size_t size) if (memAddress == (void *) -1) ereport(FATAL, (errmsg("could not create shared memory for request size: %ld", size), - errdetail("attach to shared memory [id:%d] failed with reason: \"%s\"", shmid, strerror(errno)))); + errdetail("attach to shared memory [id:%d] failed with reason: \"%m\"", shmid))); /* Register on-exit routine to detach new segment before deleting */ @@ -85,7 +85,7 @@ IpcMemoryDetach(int status, Datum shmaddr) if (shmdt((void *) shmaddr) < 0) ereport(LOG, (errmsg("removing shared memory segments"), - errdetail("shmdt(%p) failed: %s", (void *) shmaddr, strerror(errno)))); + errdetail("shmdt(%p) failed: %m", (void *) shmaddr))); } @@ -112,8 +112,8 @@ IpcMemoryDelete(int status, Datum shmId) if (shmctl(shmId, IPC_RMID, NULL) < 0) ereport(LOG, (errmsg("deleting shared memory segments"), - errdetail("shmctl(%lu, %d, 0) failed: %s", - shmId, IPC_RMID, strerror(errno)))); + errdetail("shmctl(%lu, %d, 0) failed with error \"%m\"", + shmId, IPC_RMID))); } void diff --git a/src/utils/pool_stream.c b/src/utils/pool_stream.c index 9f6fcb7dd..dcb64188e 100644 --- a/src/utils/pool_stream.c +++ b/src/utils/pool_stream.c @@ -183,7 +183,7 @@ pool_read(POOL_CONNECTION * cp, void *buf, int len) { ereport(ERROR, (errmsg("unable to read data from DB node %d", cp->db_node_id), - errdetail("pool_check_fd call failed with an error \"%s\"", strerror(errno)))); + errdetail("pool_check_fd call failed with error \"%m\""))); } } @@ -217,7 +217,7 @@ pool_read(POOL_CONNECTION * cp, void *buf, int len) if (errno == EINTR || errno == EAGAIN) { ereport(DEBUG5, - (errmsg("read on socket failed with error :\"%s\"", strerror(errno)), + (errmsg("read on socket failed with error :\"%m\""), errdetail("retrying..."))); continue; } @@ -245,20 +245,20 @@ pool_read(POOL_CONNECTION * cp, void *buf, int len) child_exit(POOL_EXIT_AND_RESTART); ereport(ERROR, (errmsg("unable to read data from DB node %d", cp->db_node_id), - errdetail("socket read failed with an error \"%s\"", strerror(errno)))); + errdetail("socket read failed with error \"%m\""))); } else { ereport(ERROR, (errmsg("unable to read data from DB node %d", cp->db_node_id), - errdetail("socket read failed with an error \"%s\"", strerror(errno)))); + errdetail("socket read failed with error \"%m\""))); } } else { ereport(FRONTEND_ERROR, (errmsg("unable to read data from frontend"), - errdetail("socket read failed with an error \"%s\"", strerror(errno)))); + errdetail("socket read failed with error \"%m\""))); } } else if (readlen == 0) @@ -351,7 +351,7 @@ pool_read2(POOL_CONNECTION * cp, int len) { ereport(ERROR, (errmsg("unable to read data from DB node %d", cp->db_node_id), - errdetail("pool_check_fd call failed with an error \"%s\"", strerror(errno)))); + errdetail("pool_check_fd call failed with error \"%m\""))); } } @@ -373,7 +373,7 @@ pool_read2(POOL_CONNECTION * cp, int len) if (errno == EINTR || errno == EAGAIN) { ereport(DEBUG5, - (errmsg("read on socket failed with error :\"%s\"", strerror(errno)), + (errmsg("read on socket failed with error :\"%m\""), errdetail("retrying..."))); continue; } @@ -400,7 +400,7 @@ pool_read2(POOL_CONNECTION * cp, int len) /* we are in main process */ ereport(ERROR, (errmsg("unable to read data from DB node %d", cp->db_node_id), - errdetail("socket read failed with an error \"%s\"", strerror(errno)))); + errdetail("socket read failed with error \"%m\""))); } else { @@ -621,11 +621,11 @@ pool_write_flush(POOL_CONNECTION * cp, void *buf, int len) */ if (cp->isbackend) ereport(WARNING, - (errmsg("write on backend %d failed with error :\"%s\"", cp->db_node_id, strerror(errno)), + (errmsg("write on backend %d failed with error :\"%m\"", cp->db_node_id), errdetail("while trying to write data from offset: %d wlen: %d", offset, wlen))); else ereport(DEBUG5, - (errmsg("write on frontend failed with error :\"%s\"", strerror(errno)), + (errmsg("write on frontend failed with error :\"%m\""), errdetail("while trying to write data from offset: %d wlen: %d", offset, wlen))); return -1; } @@ -712,11 +712,11 @@ pool_flush_it(POOL_CONNECTION * cp) */ if (cp->isbackend) ereport(WARNING, - (errmsg("write on backend %d failed with error :\"%s\"", cp->db_node_id, strerror(errno)), + (errmsg("write on backend %d failed with error :\"%m\"", cp->db_node_id), errdetail("while trying to write data from offset: %d wlen: %d", offset, wlen))); else ereport(DEBUG5, - (errmsg("write on frontend failed with error :\"%s\"", strerror(errno)), + (errmsg("write on frontend failed with error :\"%m\""), errdetail("while trying to write data from offset: %d wlen: %d", offset, wlen))); cp->wbufpo = 0; return -1; @@ -955,7 +955,7 @@ pool_read_string(POOL_CONNECTION * cp, int *len, int line) { ereport(ERROR, (errmsg("unable to read data from DB node %d", cp->db_node_id), - errdetail("pool_check_fd call failed with an error \"%s\"", strerror(errno)))); + errdetail("pool_check_fd call failed with error \"%m\""))); } } @@ -1382,7 +1382,7 @@ pool_check_fd(POOL_CONNECTION * cp) continue; ereport(WARNING, - (errmsg("waiting for reading data. select failed with error: \"%s\"", strerror(errno)))); + (errmsg("waiting for reading data. select failed with error: \"%m\""))); break; } else if (fds == 0) /* timeout */ diff --git a/src/utils/socket_stream.c b/src/utils/socket_stream.c index 199e84a74..17459951b 100644 --- a/src/utils/socket_stream.c +++ b/src/utils/socket_stream.c @@ -59,14 +59,14 @@ socket_set_nonblock(int fd) { ereport(FATAL, (errmsg("unable to set options on socket"), - errdetail("fcntl system call failed with error \"%s\"", strerror(errno)))); + errdetail("fcntl system call failed with error \"%m\""))); } if (fcntl(fd, F_SETFL, var | O_NONBLOCK) == -1) { ereport(FATAL, (errmsg("unable to set options on socket"), - errdetail("fcntl system call failed with error \"%s\"", strerror(errno)))); + errdetail("fcntl system call failed with error \"%m\""))); } } @@ -84,13 +84,13 @@ socket_unset_nonblock(int fd) { ereport(FATAL, (errmsg("unable to set options on socket"), - errdetail("fcntl system call failed with error \"%s\"", strerror(errno)))); + errdetail("fcntl system call failed with error \"%m\""))); } if (fcntl(fd, F_SETFL, var & ~O_NONBLOCK) == -1) { ereport(FATAL, (errmsg("unable to set options on socket"), - errdetail("fcntl system call failed with error \"%s\"", strerror(errno)))); + errdetail("fcntl system call failed with error \"%m\""))); } } @@ -123,12 +123,13 @@ socket_write(int fd, void *buf, size_t len) if (errno == EINTR || errno == EAGAIN) { ereport(DEBUG5, - (errmsg("write on socket failed with error :\"%s\"", strerror(errno)), + (errmsg("write on socket failed with error :\"%m\""), errdetail("retrying..."))); continue; } ereport(LOG, - (errmsg("write on socket failed with error :\"%s\"", strerror(errno)))); + (errmsg("write on socket failed"), + errdetail("%m"))); return -1; } bytes_send += ret; @@ -162,7 +163,8 @@ socket_read(int fd, void *buf, size_t len, int timeout) continue; ereport(WARNING, - (errmsg("select failed with error: \"%s\"", strerror(errno)))); + (errmsg("system call select() failed"), + errdetail("%m"))); return -1; } else if (fds == 0) @@ -175,12 +177,12 @@ socket_read(int fd, void *buf, size_t len, int timeout) if (errno == EINTR || errno == EAGAIN) { ereport(DEBUG5, - (errmsg("read from socket failed with error :\"%s\"", strerror(errno)), + (errmsg("read from socket failed with error :\"%m\""), errdetail("retrying..."))); continue; } ereport(LOG, - (errmsg("read from socket failed with error :\"%s\"", strerror(errno)))); + (errmsg("read from socket failed with error :\"%m\""))); return -1; } if (ret == 0) diff --git a/src/watchdog/watchdog.c b/src/watchdog/watchdog.c index fd9c0eda4..47ece977c 100644 --- a/src/watchdog/watchdog.c +++ b/src/watchdog/watchdog.c @@ -844,7 +844,7 @@ wd_create_recv_socket(int port) /* socket create failed */ ereport(ERROR, (errmsg("failed to create watchdog receive socket"), - errdetail("create socket failed with reason: \"%s\"", strerror(errno)))); + errdetail("create socket failed with reason: \"%m\""))); } socket_set_nonblock(sock); @@ -926,7 +926,7 @@ wd_create_client_socket(char *hostname, int port, bool *connected) { /* socket create failed */ ereport(LOG, - (errmsg("create socket failed with reason: \"%s\"", strerror(errno)))); + (errmsg("create socket failed with reason: \"%m\""))); return -1; } @@ -936,14 +936,14 @@ wd_create_client_socket(char *hostname, int port, bool *connected) close(sock); ereport(LOG, (errmsg("failed to set socket options"), - errdetail("setsockopt(TCP_NODELAY) failed with error: \"%s\"", strerror(errno)))); + errdetail("setsockopt(TCP_NODELAY) failed with error: \"%m\""))); return -1; } if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (char *) &one, sizeof(one)) == -1) { ereport(LOG, (errmsg("failed to set socket options"), - errdetail("setsockopt(SO_KEEPALIVE) failed with error: \"%s\"", strerror(errno)))); + errdetail("setsockopt(SO_KEEPALIVE) failed with error: \"%m\""))); close(sock); return -1; } @@ -984,7 +984,7 @@ wd_create_client_socket(char *hostname, int port, bool *connected) } ereport(LOG, (errmsg("connect on socket failed"), - errdetail("connect failed with error: \"%s\"", strerror(errno)))); + errdetail("connect failed with error: \"%m\""))); close(sock); return -1; } @@ -1119,7 +1119,8 @@ fork_watchdog_child(void) { ereport(FATAL, (return_code(POOL_EXIT_FATAL), - errmsg("fork() failed. reason: %s", strerror(errno)))); + errmsg("fork() failed"), + errdetail("%m"))); } return pid; @@ -1291,7 +1292,7 @@ wd_create_command_server_socket(void) ereport(FATAL, (return_code(POOL_EXIT_FATAL), errmsg("failed to create watchdog command server socket"), - errdetail("create socket failed with reason: \"%s\"", strerror(errno)))); + errdetail("create socket failed with reason: \"%m\""))); } memset((char *) &addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; @@ -1892,7 +1893,7 @@ read_ipc_socket_and_process(int sock, bool *remove_socket) { ereport(WARNING, (errmsg("error reading from IPC socket"), - errdetail("read from socket failed with error \"%s\"", strerror(errno)))); + errdetail("read from socket failed with error \"%m\""))); return false; } @@ -1902,7 +1903,7 @@ read_ipc_socket_and_process(int sock, bool *remove_socket) { ereport(WARNING, (errmsg("error reading from IPC socket"), - errdetail("read from socket failed with error \"%s\"", strerror(errno)))); + errdetail("read from socket failed with error \"%m\""))); return false; } @@ -1922,7 +1923,7 @@ read_ipc_socket_and_process(int sock, bool *remove_socket) { ereport(LOG, (errmsg("error reading IPC from socket"), - errdetail("read from socket failed with error \"%s\"", strerror(errno)))); + errdetail("read from socket failed with error \"%m\""))); return false; } } @@ -3447,7 +3448,7 @@ update_successful_outgoing_cons(fd_set *wmask, int pending_fds_count) { ereport(DEBUG1, (errmsg("error in outbound connection to %s:%d ", wdNode->hostname, wdNode->wd_port), - errdetail("getsockopt failed with error \"%s\"", strerror(errno)))); + errdetail("getsockopt failed with error \"%m\""))); close_socket_connection(&wdNode->client_socket); wdNode->client_socket.sock_state = WD_SOCK_ERROR; @@ -3479,7 +3480,7 @@ write_packet_to_socket(int sock, WDPacketData * pkt, bool ipcPacket) { ereport(LOG, (errmsg("failed to write watchdog packet to socket"), - errdetail("%s", strerror(errno)))); + errdetail("%m"))); return false; } if (ipcPacket == false) @@ -3490,7 +3491,7 @@ write_packet_to_socket(int sock, WDPacketData * pkt, bool ipcPacket) { ereport(LOG, (errmsg("failed to write watchdog packet to socket"), - errdetail("%s", strerror(errno)))); + errdetail("%m"))); return false; } } @@ -3500,7 +3501,7 @@ write_packet_to_socket(int sock, WDPacketData * pkt, bool ipcPacket) { ereport(LOG, (errmsg("failed to write watchdog packet to socket"), - errdetail("%s", strerror(errno)))); + errdetail("%m"))); return false; } /* DATA */ @@ -3515,7 +3516,7 @@ write_packet_to_socket(int sock, WDPacketData * pkt, bool ipcPacket) { ereport(LOG, (errmsg("failed to write watchdog packet to socket"), - errdetail("%s", strerror(errno)))); + errdetail("%m"))); return false; } bytes_send += ret; @@ -8025,7 +8026,7 @@ load_watchdog_debug_test_option(void) ereport(DEBUG3, (errmsg("load_watchdog_debug_test_option: failed to open file %s", wd_debug_request_file), - errdetail("\"%s\"", strerror(errno)))); + errdetail("%m"))); return; } diff --git a/src/watchdog/wd_heartbeat.c b/src/watchdog/wd_heartbeat.c index b2e8f4da0..d9bd98aca 100644 --- a/src/watchdog/wd_heartbeat.c +++ b/src/watchdog/wd_heartbeat.c @@ -95,7 +95,7 @@ wd_create_hb_send_socket(WdHbIf * hb_if) /* socket create failed */ ereport(ERROR, (errmsg("failed to create watchdog heartbeat sender socket"), - errdetail("create socket failed with reason: \"%s\"", strerror(errno)))); + errdetail("create socket failed with reason: \"%m\""))); } /* set socket option */ @@ -105,7 +105,7 @@ wd_create_hb_send_socket(WdHbIf * hb_if) close(sock); ereport(ERROR, (errmsg("failed to create watchdog heartbeat sender socket"), - errdetail("setsockopt(IP_TOS) failed with reason: \"%s\"", strerror(errno)))); + errdetail("setsockopt(IP_TOS) failed with reason: \"%m\""))); } if (hb_if->if_name[0] != '\0') @@ -123,7 +123,7 @@ wd_create_hb_send_socket(WdHbIf * hb_if) close(sock); ereport(ERROR, (errmsg("failed to create watchdog heartbeat sender socket"), - errdetail("setsockopt(SO_BINDTODEVICE) failed with reason: \"%s\"", strerror(errno)))); + errdetail("setsockopt(SO_BINDTODEVICE) failed with reason: \"%m\""))); } ereport(LOG, @@ -152,7 +152,7 @@ wd_create_hb_send_socket(WdHbIf * hb_if) close(sock); ereport(ERROR, (errmsg("failed to create watchdog heartbeat sender socket"), - errdetail("setting close-on-exec flag failed with reason: \"%s\"", strerror(errno)))); + errdetail("setting close-on-exec flag failed with reason: \"%m\""))); } return sock; @@ -179,7 +179,7 @@ wd_create_hb_recv_socket(WdHbIf * hb_if) /* socket create failed */ ereport(ERROR, (errmsg("failed to create watchdog heartbeat receive socket"), - errdetail("create socket failed with reason: \"%s\"", strerror(errno)))); + errdetail("create socket failed with reason: \"%m\""))); } if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &one, sizeof(one)) == -1) @@ -187,7 +187,7 @@ wd_create_hb_recv_socket(WdHbIf * hb_if) close(sock); ereport(ERROR, (errmsg("failed to create watchdog heartbeat receive socket"), - errdetail("setsockopt(SO_REUSEADDR) failed with reason: \"%s\"", strerror(errno)))); + errdetail("setsockopt(SO_REUSEADDR) failed with reason: \"%m\""))); } if (hb_if->if_name[0] != '\0') @@ -205,7 +205,7 @@ wd_create_hb_recv_socket(WdHbIf * hb_if) close(sock); ereport(ERROR, (errmsg("failed to create watchdog heartbeat receive socket"), - errdetail("setsockopt(SO_BINDTODEVICE) failed with reason: \"%s\"", strerror(errno)))); + errdetail("setsockopt(SO_BINDTODEVICE) failed with reason: \"%m\""))); } ereport(LOG, (errmsg("createing watchdog heartbeat receive socket."), @@ -237,8 +237,7 @@ wd_create_hb_recv_socket(WdHbIf * hb_if) { ereport(LOG, (errmsg("failed to create watchdog heartbeat receive socket. retrying..."), - errdetail("bind failed with reason: \"%s\"", - strerror(errno)))); + errdetail("bind failed with reason: \"%m\""))); sleep(1); } @@ -254,7 +253,7 @@ wd_create_hb_recv_socket(WdHbIf * hb_if) close(sock); ereport(ERROR, (errmsg("failed to create watchdog heartbeat receive socket"), - errdetail("bind socket failed with reason: \"%s\"", strerror(errno)))); + errdetail("bind socket failed with reason: \"%m\""))); } if (fcntl(sock, F_SETFD, FD_CLOEXEC) < 0) @@ -262,7 +261,7 @@ wd_create_hb_recv_socket(WdHbIf * hb_if) close(sock); ereport(ERROR, (errmsg("failed to create watchdog heartbeat receive socket"), - errdetail("setting close-on-exec flag failed with reason: \"%s\"", strerror(errno)))); + errdetail("setting close-on-exec flag failed with reason: \"%m\""))); } return sock; @@ -299,7 +298,7 @@ wd_hb_send(int sock, WdHbPacket * pkt, int len, const char *host, const int port { ereport(ERROR, (errmsg("failed to send watchdog heartbeat, sendto failed"), - errdetail("sending packet to \"%s\" failed with reason: \"%s\"", host, strerror(errno)))); + errdetail("sending packet to \"%s\" failed with reason: \"%m\"", host))); } ereport(DEBUG2, @@ -677,15 +676,14 @@ wd_set_reuseport(int sock) { ereport(LOG, (errmsg("error seting SO_REUSEPORT option to the socket"), - errdetail("setsockopt(SO_REUSEPORT) is not supported by the kernel. detail: %s", - strerror(errno)))); + errdetail("setsockopt(SO_REUSEPORT) is not supported by the kernel. detail: %m"))); } else { close(sock); ereport(ERROR, (errmsg("failed to create watchdog heartbeat socket"), - errdetail("setsockopt(SO_REUSEPORT) failed with reason: \"%s\"", strerror(errno)))); + errdetail("setsockopt(SO_REUSEPORT) failed with reason: \"%m\""))); } } else diff --git a/src/watchdog/wd_if.c b/src/watchdog/wd_if.c index 19ef6f4cd..575925483 100644 --- a/src/watchdog/wd_if.c +++ b/src/watchdog/wd_if.c @@ -267,7 +267,8 @@ exec_if_cmd(char *path, char *command) if (pipe(pfd) == -1) { ereport(WARNING, - (errmsg("while executing interface up/down command, pipe open failed with error \"%s\"", strerror(errno)))); + (errmsg("while executing interface up/down command, pipe open failed"), + errdetail("%m"))); return WD_NG; } @@ -306,7 +307,7 @@ exec_if_cmd(char *path, char *command) { ereport(FATAL, (errmsg("failed to execute interface up/down command"), - errdetail("fork() failed with reason: \"%s\"", strerror(errno)))); + errdetail("fork() failed with reason: \"%m\""))); } if (pid == 0) { @@ -334,7 +335,7 @@ exec_if_cmd(char *path, char *command) ereport(DEBUG1, (errmsg("watchdog exec waitpid()failed"), - errdetail("waitpid() system call failed with reason \"%s\"", strerror(errno)))); + errdetail("waitpid() system call failed with reason \"%m\""))); return WD_NG; } @@ -372,7 +373,7 @@ create_monitoring_socket(void) if (sock < 0) ereport(ERROR, (errmsg("watchdog: VIP monitoring failed to create socket"), - errdetail("socket() failed with error \"%s\"", strerror(errno)))); + errdetail("socket() failed with error \"%m\""))); #ifdef __linux__ struct sockaddr_nl addr; @@ -386,7 +387,7 @@ create_monitoring_socket(void) close(sock); ereport(ERROR, (errmsg("watchdog: VIP monitoring failed to bind socket"), - errdetail("bind() failed with error \"%s\"", strerror(errno)))); + errdetail("bind() failed with error \"%m\""))); } #endif @@ -419,7 +420,7 @@ read_interface_change_event(int sock, bool *link_event, bool *deleted) { ereport(DEBUG1, (errmsg("VIP monitoring failed to receive from socket"), - errdetail("recvmsg() failed with error \"%s\"", strerror(errno)))); + errdetail("recvmsg() failed with error \"%m\""))); return false; } @@ -483,7 +484,7 @@ read_interface_change_event(int sock, bool *link_event, bool *deleted) { ereport(DEBUG1, (errmsg("VIP monitoring failed to receive from socket"), - errdetail("recv() failed with error \"%s\"", strerror(errno)))); + errdetail("recv() failed with error \"%m\""))); return false; } diff --git a/src/watchdog/wd_ipc_conn.c b/src/watchdog/wd_ipc_conn.c index 207a5801f..1f88f5b0f 100644 --- a/src/watchdog/wd_ipc_conn.c +++ b/src/watchdog/wd_ipc_conn.c @@ -176,7 +176,7 @@ issue_command_to_watchdog(char type, int timeout_sec, char *data, int data_len, continue; ereport(WARNING, (errmsg("error reading from IPC command socket for ipc command %c", type), - errdetail("select system call failed with error \"%s\"", strerror(errno)))); + errdetail("select system call failed with error \"%m\""))); close(sock); return NULL; } @@ -187,7 +187,7 @@ issue_command_to_watchdog(char type, int timeout_sec, char *data, int data_len, { ereport(WARNING, (errmsg("error reading from IPC command socket for ipc command %c", type), - errdetail("read from socket failed with error \"%s\"", strerror(errno)))); + errdetail("read from socket failed with error \"%m\""))); close(sock); return result; } @@ -196,7 +196,7 @@ issue_command_to_watchdog(char type, int timeout_sec, char *data, int data_len, { ereport(WARNING, (errmsg("error reading from IPC command socket for ipc command %c", type), - errdetail("read from socket failed with error \"%s\"", strerror(errno)))); + errdetail("read from socket failed with error \"%m\""))); close(sock); return result; } @@ -215,7 +215,7 @@ issue_command_to_watchdog(char type, int timeout_sec, char *data, int data_len, pfree(result); ereport(DEBUG1, (errmsg("error reading from IPC command socket for ipc command %c", type), - errdetail("read from socket failed with error \"%s\"", strerror(errno)))); + errdetail("read from socket failed with error \"%m\""))); close(sock); return NULL; } @@ -250,7 +250,7 @@ open_wd_command_sock(bool throw_error) /* socket create failed */ ereport(throw_error ? ERROR : LOG, (errmsg("failed to connect to watchdog command server socket"), - errdetail("connect on \"%s\" failed with reason: \"%s\"", addr.sun_path, strerror(errno)))); + errdetail("connect on \"%s\" failed with reason: \"%m\"", addr.sun_path))); return -1; } @@ -264,7 +264,7 @@ open_wd_command_sock(bool throw_error) close(sock); ereport(throw_error ? ERROR : LOG, (errmsg("failed to connect to watchdog command server socket"), - errdetail("connect on \"%s\" failed with reason: \"%s\"", addr.sun_path, strerror(errno)))); + errdetail("connect on \"%s\" failed with reason: \"%m\"", addr.sun_path))); return -1; } return sock; diff --git a/src/watchdog/wd_lifecheck.c b/src/watchdog/wd_lifecheck.c index 7dfda75f3..a08fb1bbf 100644 --- a/src/watchdog/wd_lifecheck.c +++ b/src/watchdog/wd_lifecheck.c @@ -317,7 +317,8 @@ lifecheck_exit_handler(int sig) if (wpid == -1 && errno != ECHILD) ereport(WARNING, - (errmsg("wait() on lifecheck children failed. reason:%s", strerror(errno)))); + (errmsg("wait() on lifecheck children failed"), + errdetail("%m"))); if (g_hb_receiver_pid) pfree(g_hb_receiver_pid); @@ -365,7 +366,8 @@ fork_lifecheck_child(void) else if (pid == -1) { ereport(FATAL, - (errmsg("fork() failed. reason: %s", strerror(errno)))); + (errmsg("fork() failed"), + errdetail("%m"))); } return pid; @@ -1142,7 +1144,7 @@ wd_ping_all_server(void) continue; ereport(WARNING, (errmsg("failed to check the ping status of trusted servers"), - errdetail("waitpid failed with reason: %s", strerror(errno)))); + errdetail("waitpid failed with reason: %m"))); break; } } diff --git a/src/watchdog/wd_ping.c b/src/watchdog/wd_ping.c index 1eed46130..7d4c72d88 100644 --- a/src/watchdog/wd_ping.c +++ b/src/watchdog/wd_ping.c @@ -81,7 +81,7 @@ wd_is_ip_exists(char *ip) close(outputfd); ereport(WARNING, (errmsg("watchdog failed to ping host\"%s\"", ip), - errdetail("waitpid() failed with reason \"%s\"", strerror(errno)))); + errdetail("waitpid() failed with reason \"%m\""))); return false; } @@ -112,7 +112,7 @@ wd_issue_ping_command(char *hostname, int *outfd) { ereport(WARNING, (errmsg("watchdog failed to ping host\"%s\"", hostname), - errdetail("pipe open failed. reason: %s", strerror(errno)))); + errdetail("pipe open failed. reason: %m"))); return -1; } @@ -127,7 +127,7 @@ wd_issue_ping_command(char *hostname, int *outfd) { ereport(WARNING, (errmsg("watchdog failed to ping host\"%s\"", hostname), - errdetail("fork() failed. reason: %s", strerror(errno)))); + errdetail("fork() failed. reason: %m"))); return -1; } if (pid == 0) @@ -145,7 +145,7 @@ wd_issue_ping_command(char *hostname, int *outfd) { ereport(FATAL, (errmsg("watchdog failed to ping host\"%s\"", hostname), - errdetail("execv(%s) failed. reason: %s", ping_path, strerror(errno)))); + errdetail("execv(%s) failed. reason: %m", ping_path))); } exit(0); } @@ -257,7 +257,8 @@ get_result(char *ping_data) if (errno != 0) { ereport(WARNING, - (errmsg("get_result: strtod() failed with reason \"%s\"", strerror(errno)))); + (errmsg("get_result: strtod() failed"), + errdetail("%m"))); return -1; } -- 2.39.5