On Tue, Jul 13, 2021 at 12:30 PM Tom Lane <t...@sss.pgh.pa.us> wrote: > > Thomas Munro <tmu...@postgresql.org> writes: > > To make \watch react quickly when the user quits the pager or presses > > ^C, and also to increase the accuracy of its timing and decrease the > > rate of useless context switches, change the main loop of the \watch > > command to use sigwait() rather than a sleeping/polling loop, on Unix. > > I think this is going to fall over on gaur, which doesn't have POSIX-style > sigwait. We've escaped dealing with that so far because our only existing > use of sigwait is hidden under > > #if defined(ENABLE_THREAD_SAFETY) && !defined(WIN32) > > Perhaps the easiest answer is to make the #if conditional for this > code look like that too.
Oh, thanks for the advance warning. Wouldn't HAVE_SIGWAIT be better? Like so.
From d7eb7dd85df95ee7f1babfe9621bc5e9bfc1879d Mon Sep 17 00:00:00 2001 From: Thomas Munro <thomas.mu...@gmail.com> Date: Tue, 13 Jul 2021 12:47:03 +1200 Subject: [PATCH] Add configure check for sigwait(3). Build farm animal gaur doesn't have POSIX sigwait so would likely fail on recent commit 7c09d279. Add a configure check to avoid that. Reported-by: Tom Lane <t...@sss.pgh.pa.us> Discussion: https://postgr.es/m/3187588.1626136248%40sss.pgh.pa.us --- configure | 2 +- configure.ac | 1 + src/bin/psql/command.c | 10 +++++----- src/bin/psql/startup.c | 4 ++-- src/include/pg_config.h.in | 3 +++ src/tools/msvc/Solution.pm | 1 + 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/configure b/configure index 1ea28a0d67..0d3bea0e3b 100755 --- a/configure +++ b/configure @@ -15546,7 +15546,7 @@ fi LIBS_including_readline="$LIBS" LIBS=`echo "$LIBS" | sed -e 's/-ledit//g' -e 's/-lreadline//g'` -for ac_func in backtrace_symbols clock_gettime copyfile fdatasync getifaddrs getpeerucred getrlimit kqueue mbstowcs_l memset_s poll posix_fallocate ppoll pstat pthread_is_threaded_np readlink readv setproctitle setproctitle_fast setsid shm_open strchrnul strsignal symlink syncfs sync_file_range uselocale wcstombs_l writev +for ac_func in backtrace_symbols clock_gettime copyfile fdatasync getifaddrs getpeerucred getrlimit kqueue mbstowcs_l memset_s poll posix_fallocate ppoll pstat pthread_is_threaded_np readlink readv setproctitle setproctitle_fast setsid shm_open sigwait strchrnul strsignal symlink syncfs sync_file_range uselocale wcstombs_l writev do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" diff --git a/configure.ac b/configure.ac index 57336e1fb6..f8e7dc5992 100644 --- a/configure.ac +++ b/configure.ac @@ -1718,6 +1718,7 @@ AC_CHECK_FUNCS(m4_normalize([ setproctitle_fast setsid shm_open + sigwait strchrnul strsignal symlink diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index d704c4220c..138567bec9 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -4899,7 +4899,7 @@ do_watch(PQExpBuffer query_buf, double sleep) FILE *pagerpipe = NULL; int title_len; int res = 0; -#ifndef WIN32 +#ifdef HAVE_SIGWAIT sigset_t sigalrm_sigchld_sigint; sigset_t sigalrm_sigchld; sigset_t sigint; @@ -4913,7 +4913,7 @@ do_watch(PQExpBuffer query_buf, double sleep) return false; } -#ifndef WIN32 +#ifdef HAVE_SIGWAIT sigemptyset(&sigalrm_sigchld_sigint); sigaddset(&sigalrm_sigchld_sigint, SIGCHLD); sigaddset(&sigalrm_sigchld_sigint, SIGALRM); @@ -4952,7 +4952,7 @@ do_watch(PQExpBuffer query_buf, double sleep) * PAGER environment variables, because traditional pagers probably won't * be very useful for showing a stream of results. */ -#ifndef WIN32 +#ifdef HAVE_SIGWAIT pagerprog = getenv("PSQL_WATCH_PAGER"); #endif if (pagerprog && myopt.topt.pager) @@ -5023,7 +5023,7 @@ do_watch(PQExpBuffer query_buf, double sleep) if (pagerpipe && ferror(pagerpipe)) break; -#ifdef WIN32 +#ifndef HAVE_SIGWAIT /* * Set up cancellation of 'watch' via SIGINT. We redo this each time @@ -5091,7 +5091,7 @@ do_watch(PQExpBuffer query_buf, double sleep) restore_sigpipe_trap(); } -#ifndef WIN32 +#ifdef HAVE_SIGWAIT /* Disable the interval timer. */ memset(&interval, 0, sizeof(interval)); setitimer(ITIMER_REAL, &interval, NULL); diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c index 5f36f0d1c6..24b493180f 100644 --- a/src/bin/psql/startup.c +++ b/src/bin/psql/startup.c @@ -110,7 +110,7 @@ log_locus_callback(const char **filename, uint64 *lineno) } } -#ifndef WIN32 +#ifdef HAVE_SIGWAIT static void empty_signal_handler(SIGNAL_ARGS) { @@ -309,7 +309,7 @@ main(int argc, char *argv[]) psql_setup_cancel_handler(); -#ifndef WIN32 +#ifdef HAVE_SIGWAIT /* * do_watch() needs signal handlers installed (otherwise sigwait() will diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in index d69d461ff2..a3c4e43e1f 100644 --- a/src/include/pg_config.h.in +++ b/src/include/pg_config.h.in @@ -511,6 +511,9 @@ /* Define to 1 if you have the `shm_open' function. */ #undef HAVE_SHM_OPEN +/* Define to 1 if you have the `sigwait' function. */ +#undef HAVE_SIGWAIT + /* Define to 1 if you have spinlocks. */ #undef HAVE_SPINLOCKS diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm index 294b968dcd..a2626bb279 100644 --- a/src/tools/msvc/Solution.pm +++ b/src/tools/msvc/Solution.pm @@ -363,6 +363,7 @@ sub GenerateFiles HAVE_SETPROCTITLE_FAST => undef, HAVE_SETSID => undef, HAVE_SHM_OPEN => undef, + HAVE_SIGWAIT => undef, HAVE_SPINLOCKS => 1, HAVE_SRANDOM => undef, HAVE_STDBOOL_H => 1, -- 2.30.2