Skip to content

Commit c9bd7f4

Browse files
committed
Improve what pg_strsignal prints if we haven't got strsignal(3).
Turns out that returning "unrecognized signal" is confusing. Make it explicit that the platform lacks any support for signal names. (At least of the machines in the buildfarm, only HPUX lacks it.) Back-patch to v12 where we invented this function. Discussion: https://postgr.es/m/3067.1566870481@sss.pgh.pa.us
1 parent b8b3a27 commit c9bd7f4

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/port/pgstrsignal.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232
*
3333
* This version guarantees to return a non-NULL pointer, although
3434
* some platforms' versions of strsignal() reputedly do not.
35+
*
36+
* Note that the fallback cases just return constant strings such as
37+
* "unrecognized signal". Project style is for callers to print the
38+
* numeric signal value along with the result of this function, so
39+
* there's no need to work harder than that.
3540
*/
3641
const char *
3742
pg_strsignal(int signum)
@@ -43,22 +48,17 @@ pg_strsignal(int signum)
4348
*/
4449
#ifdef HAVE_STRSIGNAL
4550
result = strsignal(signum);
46-
if (result)
47-
return result;
51+
if (result == NULL)
52+
result = "unrecognized signal";
4853
#else
4954

5055
/*
5156
* We used to have code here to try to use sys_siglist[] if available.
5257
* However, it seems that all platforms with sys_siglist[] have also had
5358
* strsignal() for many years now, so that was just a waste of code.
5459
*/
60+
result = "(signal names not available on this platform)";
5561
#endif
5662

57-
/*
58-
* Fallback case: just return "unrecognized signal". Project style is for
59-
* callers to print the numeric signal value along with the result of this
60-
* function, so there's no need to work harder than this.
61-
*/
62-
result = "unrecognized signal";
6363
return result;
6464
}

0 commit comments

Comments
 (0)