Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc6d43ff

Browse files
committed
Replace use of sys_siglist[] with strsignal().
This commit back-patches the v12-era commitsa73d083,cc92cca,and7570df0 into supported pre-v12 branches. The net effect is toeliminate 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 ourcode can survive without sys_siglist[], it then fails to print anydescription of the signal that killed a child process, which is anon-negligible loss of friendliness. We can expect that people willbe wanting to build the back branches on platforms that include thischange, so we need to do something.Since strsignal(3) has existed for quite a long time, and we've nothad any trouble with these patches so far in v12, it seems safe toback-patch into older branches.Discussion:https://postgr.es/m/3179114.1594853308@sss.pgh.pa.us
1 parentc6d33d1 commitc6d43ff

File tree

12 files changed

+94
-84
lines changed

12 files changed

+94
-84
lines changed

‎configure

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15004,7 +15004,7 @@ fi
1500415004
LIBS_including_readline="$LIBS"
1500515005
LIBS=`echo "$LIBS" | sed -e 's/-ledit//g' -e 's/-lreadline//g'`
1500615006

15007-
for ac_func in cbrt clock_gettime dlopen fdatasync getifaddrs getpeerucred getrlimit mbstowcs_l memmove poll posix_fallocate pstat pthread_is_threaded_np readlink setproctitle setsid shm_open symlink sync_file_range uselocale utime utimes wcstombs_l
15007+
for ac_func in cbrt clock_gettime dlopen fdatasync getifaddrs getpeerucred getrlimit mbstowcs_l memmove poll posix_fallocate pstat pthread_is_threaded_np readlink setproctitle setsid shm_openstrsignalsymlink sync_file_range uselocale utime utimes wcstombs_l
1500815008
do :
1500915009
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
1501015010
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
@@ -15893,24 +15893,6 @@ esac
1589315893

1589415894
fi
1589515895

15896-
ac_fn_c_check_decl "$LINENO" "sys_siglist" "ac_cv_have_decl_sys_siglist" "#include <signal.h>
15897-
/* NetBSD declares sys_siglist in unistd.h. */
15898-
#ifdef HAVE_UNISTD_H
15899-
# include <unistd.h>
15900-
#endif
15901-
15902-
"
15903-
if test "x$ac_cv_have_decl_sys_siglist" = xyes; then :
15904-
ac_have_decl=1
15905-
else
15906-
ac_have_decl=0
15907-
fi
15908-
15909-
cat >>confdefs.h <<_ACEOF
15910-
#define HAVE_DECL_SYS_SIGLIST $ac_have_decl
15911-
_ACEOF
15912-
15913-
1591415896
ac_fn_c_check_func "$LINENO" "syslog" "ac_cv_func_syslog"
1591515897
if test "x$ac_cv_func_syslog" = xyes; then :
1591615898
ac_fn_c_check_header_mongrel "$LINENO" "syslog.h" "ac_cv_header_syslog_h" "$ac_includes_default"

‎configure.in

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,6 +1622,7 @@ AC_CHECK_FUNCS(m4_normalize([
16221622
setproctitle
16231623
setsid
16241624
shm_open
1625+
strsignal
16251626
symlink
16261627
sync_file_range
16271628
uselocale
@@ -1821,14 +1822,6 @@ if test "$PORTNAME" = "cygwin"; then
18211822
AC_LIBOBJ(dirmod)
18221823
fi
18231824

1824-
AC_CHECK_DECLS([sys_siglist], [], [],
1825-
[#include <signal.h>
1826-
/* NetBSD declares sys_siglist in unistd.h. */
1827-
#ifdef HAVE_UNISTD_H
1828-
# include <unistd.h>
1829-
#endif
1830-
])
1831-
18321825
AC_CHECK_FUNC(syslog,
18331826
[AC_CHECK_HEADER(syslog.h,
18341827
[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
@@ -596,17 +596,10 @@ pgarch_archiveXlog(char *xlog)
596596
errhint("See C include file \"ntstatus.h\" for a description of the hexadecimal value."),
597597
errdetail("The failed archive command was: %s",
598598
xlogarchcmd)));
599-
#elif defined(HAVE_DECL_SYS_SIGLIST)&&HAVE_DECL_SYS_SIGLIST
600-
ereport(lev,
601-
(errmsg("archive command was terminated by signal %d: %s",
602-
WTERMSIG(rc),
603-
WTERMSIG(rc)<NSIG ?sys_siglist[WTERMSIG(rc)] :"(unknown)"),
604-
errdetail("The failed archive command was: %s",
605-
xlogarchcmd)));
606599
#else
607600
ereport(lev,
608-
(errmsg("archive command was terminated by signal %d",
609-
WTERMSIG(rc)),
601+
(errmsg("archive command was terminated by signal %d: %s",
602+
WTERMSIG(rc),pg_strsignal(WTERMSIG(rc))),
610603
errdetail("The failed archive command was: %s",
611604
xlogarchcmd)));
612605
#endif

‎src/backend/postmaster/postmaster.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3563,6 +3563,7 @@ LogChildExit(int lev, const char *procname, int pid, int exitstatus)
35633563
procname,pid,WEXITSTATUS(exitstatus)),
35643564
activity ?errdetail("Failed process was running: %s",activity) :0));
35653565
elseif (WIFSIGNALED(exitstatus))
3566+
{
35663567
#if defined(WIN32)
35673568
ereport(lev,
35683569

@@ -3573,27 +3574,18 @@ LogChildExit(int lev, const char *procname, int pid, int exitstatus)
35733574
procname,pid,WTERMSIG(exitstatus)),
35743575
errhint("See C include file \"ntstatus.h\" for a description of the hexadecimal value."),
35753576
activity ?errdetail("Failed process was running: %s",activity) :0));
3576-
#elif defined(HAVE_DECL_SYS_SIGLIST)&&HAVE_DECL_SYS_SIGLIST
3577+
#else
35773578
ereport(lev,
35783579

35793580
/*------
35803581
translator: %s is a noun phrase describing a child process, such as
35813582
"server process" */
35823583
(errmsg("%s (PID %d) was terminated by signal %d: %s",
35833584
procname,pid,WTERMSIG(exitstatus),
3584-
WTERMSIG(exitstatus)<NSIG ?
3585-
sys_siglist[WTERMSIG(exitstatus)] :"(unknown)"),
3586-
activity ?errdetail("Failed process was running: %s",activity) :0));
3587-
#else
3588-
ereport(lev,
3589-
3590-
/*------
3591-
translator: %s is a noun phrase describing a child process, such as
3592-
"server process" */
3593-
(errmsg("%s (PID %d) was terminated by signal %d",
3594-
procname,pid,WTERMSIG(exitstatus)),
3585+
pg_strsignal(WTERMSIG(exitstatus))),
35953586
activity ?errdetail("Failed process was running: %s",activity) :0));
35963587
#endif
3588+
}
35973589
else
35983590
ereport(lev,
35993591

‎src/bin/pg_basebackup/pg_basebackup.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,7 +2014,7 @@ BaseBackup(void)
20142014
{
20152015
#ifndefWIN32
20162016
intstatus;
2017-
intr;
2017+
pid_tr;
20182018
#else
20192019
DWORDstatus;
20202020

@@ -2042,7 +2042,7 @@ BaseBackup(void)
20422042

20432043
/* Just wait for the background process to exit */
20442044
r=waitpid(bgchild,&status,0);
2045-
if (r==-1)
2045+
if (r==(pid_t)-1)
20462046
{
20472047
fprintf(stderr,_("%s: could not wait for child process: %s\n"),
20482048
progname,strerror(errno));
@@ -2051,19 +2051,13 @@ BaseBackup(void)
20512051
if (r!=bgchild)
20522052
{
20532053
fprintf(stderr,_("%s: child %d died, expected %d\n"),
2054-
progname,r, (int)bgchild);
2054+
progname,(int)r, (int)bgchild);
20552055
disconnect_and_exit(1);
20562056
}
2057-
if (!WIFEXITED(status))
2058-
{
2059-
fprintf(stderr,_("%s: child process did not exit normally\n"),
2060-
progname);
2061-
disconnect_and_exit(1);
2062-
}
2063-
if (WEXITSTATUS(status)!=0)
2057+
if (status!=0)
20642058
{
2065-
fprintf(stderr,_("%s:child process exited with error %d\n"),
2066-
progname,WEXITSTATUS(status));
2059+
fprintf(stderr,"%s:%s\n",
2060+
progname,wait_result_to_str(status));
20672061
disconnect_and_exit(1);
20682062
}
20692063
/* Exited normally, we're happy! */

‎src/common/wait_error.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,17 @@ wait_result_to_str(int exitstatus)
5656
}
5757
}
5858
elseif (WIFSIGNALED(exitstatus))
59+
{
5960
#if defined(WIN32)
6061
snprintf(str,sizeof(str),
6162
_("child process was terminated by exception 0x%X"),
6263
WTERMSIG(exitstatus));
63-
#elif defined(HAVE_DECL_SYS_SIGLIST)&&HAVE_DECL_SYS_SIGLIST
64-
{
65-
charstr2[256];
66-
67-
snprintf(str2,sizeof(str2),"%d: %s",WTERMSIG(exitstatus),
68-
WTERMSIG(exitstatus)<NSIG ?
69-
sys_siglist[WTERMSIG(exitstatus)] :"(unknown)");
70-
snprintf(str,sizeof(str),
71-
_("child process was terminated by signal %s"),str2);
72-
}
7364
#else
7465
snprintf(str,sizeof(str),
75-
_("child process was terminated by signal %d"),
76-
WTERMSIG(exitstatus));
66+
_("child process was terminated by signal %d: %s"),
67+
WTERMSIG(exitstatus),pg_strsignal(WTERMSIG(exitstatus)));
7768
#endif
69+
}
7870
else
7971
snprintf(str,sizeof(str),
8072
_("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
@@ -182,10 +182,6 @@
182182
don't. */
183183
#undef HAVE_DECL_STRTOULL
184184

185-
/* Define to 1 if you have the declaration of `sys_siglist', and to 0 if you
186-
don't. */
187-
#undef HAVE_DECL_SYS_SIGLIST
188-
189185
/* Define to 1 if you have the declaration of `vsnprintf', and to 0 if you
190186
don't. */
191187
#undef HAVE_DECL_VSNPRINTF
@@ -547,6 +543,9 @@
547543
/* Define to use have a strong random number source */
548544
#undef HAVE_STRONG_RANDOM
549545

546+
/* Define to 1 if you have the `strsignal' function. */
547+
#undef HAVE_STRSIGNAL
548+
550549
/* Define to 1 if you have the `strtoll' function. */
551550
#undef HAVE_STRTOLL
552551

‎src/include/pg_config.h.win32

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,9 @@
414414
/* Define to use have a strong random number source */
415415
#define HAVE_STRONG_RANDOM 1
416416

417+
/* Define to 1 if you have the `strsignal' function. */
418+
/* #undef HAVE_STRSIGNAL */
419+
417420
/* Define to 1 if you have the `strtoll' function. */
418421
#ifdef HAVE_LONG_LONG_INT_64
419422
#define HAVE_STRTOLL 1

‎src/include/port.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ extern intpg_printf(const char *fmt,...) pg_attribute_printf(1, 2);
189189
#endif
190190
#endif/* USE_REPL_SNPRINTF */
191191

192+
/* Wrap strsignal(), or provide our own version if necessary */
193+
externconstchar*pg_strsignal(intsignum);
194+
192195
/* Portable prompt handling */
193196
externvoidsimple_prompt(constchar*prompt,char*destination,size_tdestlen,
194197
boolecho);

‎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.opgstrsignal.opqsignal.o\
3636
qsort.o qsort_arg.o quotes.o sprompt.o tar.o thread.o
3737

3838
ifeq ($(enable_strong_random), yes)

‎src/port/pgstrsignal.c

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* pgstrsignal.c
4+
* Identify a Unix signal number
5+
*
6+
* On platforms compliant with modern POSIX, this just wraps strsignal(3).
7+
* Elsewhere, we do the best we can.
8+
*
9+
* This file is not currently built in MSVC builds, since it's useless
10+
* on non-Unix platforms.
11+
*
12+
* Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
13+
* Portions Copyright (c) 1994, Regents of the University of California
14+
*
15+
* IDENTIFICATION
16+
* src/port/pgstrsignal.c
17+
*
18+
*-------------------------------------------------------------------------
19+
*/
20+
21+
#include"c.h"
22+
23+
24+
/*
25+
* pg_strsignal
26+
*
27+
* Return a string identifying the given Unix signal number.
28+
*
29+
* The result is declared "const char *" because callers should not
30+
* modify the string. Note, however, that POSIX does not promise that
31+
* the string will remain valid across later calls to strsignal().
32+
*
33+
* This version guarantees to return a non-NULL pointer, although
34+
* 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.
40+
*/
41+
constchar*
42+
pg_strsignal(intsignum)
43+
{
44+
constchar*result;
45+
46+
/*
47+
* If we have strsignal(3), use that --- but check its result for NULL.
48+
*/
49+
#ifdefHAVE_STRSIGNAL
50+
result=strsignal(signum);
51+
if (result==NULL)
52+
result="unrecognized signal";
53+
#else
54+
55+
/*
56+
* We used to have code here to try to use sys_siglist[] if available.
57+
* However, it seems that all platforms with sys_siglist[] have also had
58+
* strsignal() for many years now, so that was just a waste of code.
59+
*/
60+
result="(signal names not available on this platform)";
61+
#endif
62+
63+
returnresult;
64+
}

‎src/test/regress/pg_regress.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,14 +1560,9 @@ log_child_failure(int exitstatus)
15601560
#if defined(WIN32)
15611561
status(_(" (test process was terminated by exception 0x%X)"),
15621562
WTERMSIG(exitstatus));
1563-
#elif defined(HAVE_DECL_SYS_SIGLIST)&&HAVE_DECL_SYS_SIGLIST
1564-
status(_(" (test process was terminated by signal %d: %s)"),
1565-
WTERMSIG(exitstatus),
1566-
WTERMSIG(exitstatus)<NSIG ?
1567-
sys_siglist[WTERMSIG(exitstatus)] :"(unknown))");
15681563
#else
1569-
status(_(" (test process was terminated by signal %d)"),
1570-
WTERMSIG(exitstatus));
1564+
status(_(" (test process was terminated by signal %d: %s)"),
1565+
WTERMSIG(exitstatus),pg_strsignal(WTERMSIG(exitstatus)));
15711566
#endif
15721567
}
15731568
else

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp