Skip to content

Commit d61dccc

Browse files
committed
Replace use of sys_siglist[] with strsignal().
This commit back-patches the v12-era commits a73d083, cc92cca, and 7570df0 into supported pre-v12 branches. The net effect is to eliminate our former dependency on the never-standard sys_siglist[] array, instead using POSIX-standard strsignal(3). What motivates doing this now is that glibc just removed sys_siglist[] from the set of symbols available to newly-built programs. While our code can survive without sys_siglist[], it then fails to print any description of the signal that killed a child process, which is a non-negligible loss of friendliness. We can expect that people will be wanting to build the back branches on platforms that include this change, so we need to do something. Since strsignal(3) has existed for quite a long time, and we've not had any trouble with these patches so far in v12, it seems safe to back-patch into older branches. Discussion: https://postgr.es/m/3179114.1594853308@sss.pgh.pa.us
1 parent 18ec254 commit d61dccc

File tree

12 files changed

+94
-79
lines changed

12 files changed

+94
-79
lines changed

configure

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12584,7 +12584,7 @@ fi
1258412584
LIBS_including_readline="$LIBS"
1258512585
LIBS=`echo "$LIBS" | sed -e 's/-ledit//g' -e 's/-lreadline//g'`
1258612586

12587-
for ac_func in cbrt dlopen fdatasync getifaddrs getpeerucred getrlimit mbstowcs_l memmove poll posix_fallocate pstat pthread_is_threaded_np readlink setproctitle setsid shm_open sigprocmask symlink sync_file_range towlower uselocale utime utimes wcstombs wcstombs_l
12587+
for ac_func in cbrt dlopen fdatasync getifaddrs getpeerucred getrlimit mbstowcs_l memmove poll posix_fallocate pstat pthread_is_threaded_np readlink setproctitle setsid shm_open sigprocmask strsignal symlink sync_file_range towlower uselocale utime utimes wcstombs wcstombs_l
1258812588
do :
1258912589
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
1259012590
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
@@ -13476,25 +13476,6 @@ $as_echo "#define HAVE_SIGSETJMP 1" >>confdefs.h
1347613476

1347713477
fi
1347813478

13479-
ac_fn_c_check_decl "$LINENO" "sys_siglist" "ac_cv_have_decl_sys_siglist" "#include <signal.h>
13480-
/* NetBSD declares sys_siglist in unistd.h. */
13481-
#ifdef HAVE_UNISTD_H
13482-
# include <unistd.h>
13483-
#endif
13484-
13485-
"
13486-
if test "x$ac_cv_have_decl_sys_siglist" = xyes; then :
13487-
ac_have_decl=1
13488-
else
13489-
ac_have_decl=0
13490-
fi
13491-
13492-
cat >>confdefs.h <<_ACEOF
13493-
#define HAVE_DECL_SYS_SIGLIST $ac_have_decl
13494-
_ACEOF
13495-
13496-
13497-
1349813479
ac_fn_c_check_func "$LINENO" "syslog" "ac_cv_func_syslog"
1349913480
if test "x$ac_cv_func_syslog" = xyes; then :
1350013481
ac_fn_c_check_header_mongrel "$LINENO" "syslog.h" "ac_cv_header_syslog_h" "$ac_includes_default"

configure.in

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,6 +1483,7 @@ AC_CHECK_FUNCS(m4_normalize([
14831483
setsid
14841484
shm_open
14851485
sigprocmask
1486+
strsignal
14861487
symlink
14871488
sync_file_range
14881489
towlower
@@ -1695,8 +1696,6 @@ if test x"$pgac_cv_func_sigsetjmp" = x"yes"; then
16951696
AC_DEFINE(HAVE_SIGSETJMP, 1, [Define to 1 if you have sigsetjmp().])
16961697
fi
16971698

1698-
AC_DECL_SYS_SIGLIST
1699-
17001699
AC_CHECK_FUNC(syslog,
17011700
[AC_CHECK_HEADER(syslog.h,
17021701
[AC_DEFINE(HAVE_SYSLOG, 1, [Define to 1 if you have the syslog interface.])])])

src/backend/postmaster/pgarch.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -598,17 +598,10 @@ pgarch_archiveXlog(char *xlog)
598598
errhint("See C include file \"ntstatus.h\" for a description of the hexadecimal value."),
599599
errdetail("The failed archive command was: %s",
600600
xlogarchcmd)));
601-
#elif defined(HAVE_DECL_SYS_SIGLIST) && HAVE_DECL_SYS_SIGLIST
602-
ereport(lev,
603-
(errmsg("archive command was terminated by signal %d: %s",
604-
WTERMSIG(rc),
605-
WTERMSIG(rc) < NSIG ? sys_siglist[WTERMSIG(rc)] : "(unknown)"),
606-
errdetail("The failed archive command was: %s",
607-
xlogarchcmd)));
608601
#else
609602
ereport(lev,
610-
(errmsg("archive command was terminated by signal %d",
611-
WTERMSIG(rc)),
603+
(errmsg("archive command was terminated by signal %d: %s",
604+
WTERMSIG(rc), pg_strsignal(WTERMSIG(rc))),
612605
errdetail("The failed archive command was: %s",
613606
xlogarchcmd)));
614607
#endif

src/backend/postmaster/postmaster.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3528,6 +3528,7 @@ LogChildExit(int lev, const char *procname, int pid, int exitstatus)
35283528
procname, pid, WEXITSTATUS(exitstatus)),
35293529
activity ? errdetail("Failed process was running: %s", activity) : 0));
35303530
else if (WIFSIGNALED(exitstatus))
3531+
{
35313532
#if defined(WIN32)
35323533
ereport(lev,
35333534

@@ -3538,27 +3539,18 @@ LogChildExit(int lev, const char *procname, int pid, int exitstatus)
35383539
procname, pid, WTERMSIG(exitstatus)),
35393540
errhint("See C include file \"ntstatus.h\" for a description of the hexadecimal value."),
35403541
activity ? errdetail("Failed process was running: %s", activity) : 0));
3541-
#elif defined(HAVE_DECL_SYS_SIGLIST) && HAVE_DECL_SYS_SIGLIST
3542+
#else
35423543
ereport(lev,
35433544

35443545
/*------
35453546
translator: %s is a noun phrase describing a child process, such as
35463547
"server process" */
35473548
(errmsg("%s (PID %d) was terminated by signal %d: %s",
35483549
procname, pid, WTERMSIG(exitstatus),
3549-
WTERMSIG(exitstatus) < NSIG ?
3550-
sys_siglist[WTERMSIG(exitstatus)] : "(unknown)"),
3551-
activity ? errdetail("Failed process was running: %s", activity) : 0));
3552-
#else
3553-
ereport(lev,
3554-
3555-
/*------
3556-
translator: %s is a noun phrase describing a child process, such as
3557-
"server process" */
3558-
(errmsg("%s (PID %d) was terminated by signal %d",
3559-
procname, pid, WTERMSIG(exitstatus)),
3550+
pg_strsignal(WTERMSIG(exitstatus))),
35603551
activity ? errdetail("Failed process was running: %s", activity) : 0));
35613552
#endif
3553+
}
35623554
else
35633555
ereport(lev,
35643556

src/bin/pg_basebackup/pg_basebackup.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,7 +1848,7 @@ BaseBackup(void)
18481848
{
18491849
#ifndef WIN32
18501850
int status;
1851-
int r;
1851+
pid_t r;
18521852
#else
18531853
DWORD status;
18541854
/*
@@ -1875,7 +1875,7 @@ BaseBackup(void)
18751875

18761876
/* Just wait for the background process to exit */
18771877
r = waitpid(bgchild, &status, 0);
1878-
if (r == -1)
1878+
if (r == (pid_t) -1)
18791879
{
18801880
fprintf(stderr, _("%s: could not wait for child process: %s\n"),
18811881
progname, strerror(errno));
@@ -1884,19 +1884,13 @@ BaseBackup(void)
18841884
if (r != bgchild)
18851885
{
18861886
fprintf(stderr, _("%s: child %d died, expected %d\n"),
1887-
progname, r, (int) bgchild);
1887+
progname, (int) r, (int) bgchild);
18881888
disconnect_and_exit(1);
18891889
}
1890-
if (!WIFEXITED(status))
1891-
{
1892-
fprintf(stderr, _("%s: child process did not exit normally\n"),
1893-
progname);
1894-
disconnect_and_exit(1);
1895-
}
1896-
if (WEXITSTATUS(status) != 0)
1890+
if (status != 0)
18971891
{
1898-
fprintf(stderr, _("%s: child process exited with error %d\n"),
1899-
progname, WEXITSTATUS(status));
1892+
fprintf(stderr, "%s: %s\n",
1893+
progname, wait_result_to_str(status));
19001894
disconnect_and_exit(1);
19011895
}
19021896
/* Exited normally, we're happy! */

src/common/wait_error.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,17 @@ wait_result_to_str(int exitstatus)
5858
}
5959
}
6060
else if (WIFSIGNALED(exitstatus))
61+
{
6162
#if defined(WIN32)
6263
snprintf(str, sizeof(str),
6364
_("child process was terminated by exception 0x%X"),
6465
WTERMSIG(exitstatus));
65-
#elif defined(HAVE_DECL_SYS_SIGLIST) && HAVE_DECL_SYS_SIGLIST
66-
{
67-
char str2[256];
68-
69-
snprintf(str2, sizeof(str2), "%d: %s", WTERMSIG(exitstatus),
70-
WTERMSIG(exitstatus) < NSIG ?
71-
sys_siglist[WTERMSIG(exitstatus)] : "(unknown)");
72-
snprintf(str, sizeof(str),
73-
_("child process was terminated by signal %s"), str2);
74-
}
7566
#else
7667
snprintf(str, sizeof(str),
77-
_("child process was terminated by signal %d"),
78-
WTERMSIG(exitstatus));
68+
_("child process was terminated by signal %d: %s"),
69+
WTERMSIG(exitstatus), pg_strsignal(WTERMSIG(exitstatus)));
7970
#endif
71+
}
8072
else
8173
snprintf(str, sizeof(str),
8274
_("child process exited with unrecognized status %d"),

src/include/pg_config.h.in

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,6 @@
152152
don't. */
153153
#undef HAVE_DECL_STRTOULL
154154

155-
/* Define to 1 if you have the declaration of `sys_siglist', and to 0 if you
156-
don't. */
157-
#undef HAVE_DECL_SYS_SIGLIST
158-
159155
/* Define to 1 if you have the declaration of `vsnprintf', and to 0 if you
160156
don't. */
161157
#undef HAVE_DECL_VSNPRINTF
@@ -520,6 +516,9 @@
520516
/* Define to 1 if you have the `strlcpy' function. */
521517
#undef HAVE_STRLCPY
522518

519+
/* Define to 1 if you have the `strsignal' function. */
520+
#undef HAVE_STRSIGNAL
521+
523522
/* Define to 1 if you have the `strtoll' function. */
524523
#undef HAVE_STRTOLL
525524

src/include/pg_config.h.win32

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,9 @@
373373
/* Define to 1 if you have the <string.h> header file. */
374374
#define HAVE_STRING_H 1
375375

376+
/* Define to 1 if you have the `strsignal' function. */
377+
/* #undef HAVE_STRSIGNAL */
378+
376379
/* Define to 1 if you have the `strtoll' function. */
377380
#ifdef HAVE_LONG_LONG_INT_64
378381
#define HAVE_STRTOLL 1

src/include/port.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ extern char *pgwin32_setlocale(int category, const char *locale);
201201
#define setlocale(a,b) pgwin32_setlocale(a,b)
202202
#endif /* WIN32 */
203203

204+
/* Wrap strsignal(), or provide our own version if necessary */
205+
extern const char *pg_strsignal(int signum);
206+
204207
/* Portable prompt handling */
205208
extern char *simple_prompt(const char *prompt, int maxlen, bool echo);
206209

src/port/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ LIBS += $(PTHREAD_LIBS)
3232

3333
OBJS = $(LIBOBJS) $(PG_CRC32C_OBJS) chklocale.o erand48.o inet_net_ntop.o \
3434
noblock.o path.o pgcheckdir.o pgmkdirp.o pgsleep.o \
35-
pgstrcasecmp.o pqsignal.o \
35+
pgstrcasecmp.o pgstrsignal.o pqsignal.o \
3636
qsort.o qsort_arg.o quotes.o sprompt.o tar.o thread.o
3737

3838
# foo_srv.o and foo.o are both built from foo.c, but only foo.o has -DFRONTEND

0 commit comments

Comments
 (0)