Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gYamw-0005Hl-OP for pgsql-hackers@arkaria.postgresql.org; Sun, 16 Dec 2018 18:05:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gYamu-0002WG-Vi for pgsql-hackers@arkaria.postgresql.org; Sun, 16 Dec 2018 18:05:12 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gYamu-0002W8-LC for pgsql-hackers@lists.postgresql.org; Sun, 16 Dec 2018 18:05:12 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gYamo-0004C2-1I for pgsql-hackers@lists.postgresql.org; Sun, 16 Dec 2018 18:05:11 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id wBGI53RS025759 for ; Sun, 16 Dec 2018 13:05:03 -0500 From: Tom Lane To: pgsql-hackers@lists.postgresql.org Subject: Why aren't we using strsignal(3) ? MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <25757.1544983503.1@sss.pgh.pa.us> Date: Sun, 16 Dec 2018 13:05:03 -0500 Message-ID: <25758.1544983503@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk While poking at the signal-reporting bug just pointed out by Erik Rijkers, I couldn't help noticing how many places we have that are doing some equivalent of this ugly dance: #if defined(HAVE_DECL_SYS_SIGLIST) && HAVE_DECL_SYS_SIGLIST { char str2[256]; snprintf(str2, sizeof(str2), "%d: %s", WTERMSIG(exitstatus), WTERMSIG(exitstatus) < NSIG ? sys_siglist[WTERMSIG(exitstatus)] : "(unknown)"); snprintf(str, sizeof(str), _("child process was terminated by signal %s"), str2); } #else snprintf(str, sizeof(str), _("child process was terminated by signal %d"), WTERMSIG(exitstatus)); #endif (Plus, there's at least one place that *should* be doing this and is not.) Not only is this repetitive and unreadable, but it's also obsolete: at least as far back as POSIX:2008, there's a function strsignal() that you're supposed to use instead. I propose to replace all these places with code like snprintf(str, sizeof(str), _("child process was terminated by signal %d: %s"), WTERMSIG(exitstatus), pg_strsignal(WTERMSIG(exitstatus))); where pg_strsignal is a trivial wrapper around strsignal() if that exists, else it uses sys_siglist[] if that exists, else it just returns "unrecognized signal". regards, tom lane