Remove configure probe for sys/resource.h and refactor.
authorThomas Munro <[email protected]>
Sat, 13 Aug 2022 11:35:24 +0000 (23:35 +1200)
committerThomas Munro <[email protected]>
Sat, 13 Aug 2022 12:09:47 +0000 (00:09 +1200)
<sys/resource.h> is in SUSv2 and is on all targeted Unix systems.  We
have a replacement for getrusage() on Windows, so let's just move its
declarations into src/include/port/win32/sys/resource.h so that we can
use a standard-looking #include.  Also remove an obsolete reference to
CLK_TCK.  Also rename src/port/getrusage.c to win32getrusage.c,
following the convention for Windows-only fallback code.

Reviewed-by: Tom Lane <[email protected]>
Discussion: https://postgr.es/m/CA%2BhUKG%2BL_3brvh%3D8e0BW_VfX9h7MtwgN%3DnFHP5o7X2oZucY9dg%40mail.gmail.com

16 files changed:
configure
configure.ac
src/backend/storage/file/fd.c
src/backend/tcop/postgres.c
src/bin/pg_ctl/pg_ctl.c
src/bin/pgbench/pgbench.c
src/include/pg_config.h.in
src/include/port/win32/sys/resource.h [new file with mode: 0644]
src/include/rusagestub.h [deleted file]
src/include/utils/pg_rusage.h
src/port/win32getrusage.c [moved from src/port/getrusage.c with 88% similarity]
src/test/regress/pg_regress.c
src/tools/msvc/Mkvcbuild.pm
src/tools/msvc/Solution.pm
src/tools/pginclude/cpluspluscheck
src/tools/pginclude/headerscheck

index 9ea343c9a19b87ed2de919ee7bf3ad6da0724a6d..3306741cfc35c0a450cdeae368e3d18388254780 100755 (executable)
--- a/configure
+++ b/configure
@@ -13874,7 +13874,7 @@ $as_echo "#define HAVE_STDBOOL_H 1" >>confdefs.h
 fi
 
 
-for ac_header in atomic.h copyfile.h execinfo.h getopt.h ifaddrs.h langinfo.h mbarrier.h net/if.h netinet/tcp.h sys/epoll.h sys/event.h sys/personality.h sys/prctl.h sys/procctl.h sys/resource.h sys/signalfd.h sys/sockio.h sys/ucred.h termios.h ucred.h
+for ac_header in atomic.h copyfile.h execinfo.h getopt.h ifaddrs.h langinfo.h mbarrier.h net/if.h netinet/tcp.h sys/epoll.h sys/event.h sys/personality.h sys/prctl.h sys/procctl.h sys/signalfd.h sys/sockio.h sys/ucred.h termios.h ucred.h
 do :
   as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
 ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
@@ -16734,12 +16734,6 @@ done
  ;;
 esac
 
-  case " $LIBOBJS " in
-  *" getrusage.$ac_objext "* ) ;;
-  *) LIBOBJS="$LIBOBJS getrusage.$ac_objext"
- ;;
-esac
-
   case " $LIBOBJS " in
   *" kill.$ac_objext "* ) ;;
   *) LIBOBJS="$LIBOBJS kill.$ac_objext"
@@ -16782,6 +16776,12 @@ esac
  ;;
 esac
 
+  case " $LIBOBJS " in
+  *" win32getrusage.$ac_objext "* ) ;;
+  *) LIBOBJS="$LIBOBJS win32getrusage.$ac_objext"
+ ;;
+esac
+
   case " $LIBOBJS " in
   *" win32link.$ac_objext "* ) ;;
   *) LIBOBJS="$LIBOBJS win32link.$ac_objext"
index 8da9fc614db7ec677ea07836dd2ea4c0617bd141..19fe78339c541419fc2d15d7bdc9e55c8b7e7f5a 100644 (file)
@@ -1459,7 +1459,6 @@ AC_CHECK_HEADERS(m4_normalize([
        sys/personality.h
        sys/prctl.h
        sys/procctl.h
-       sys/resource.h
        sys/signalfd.h
        sys/sockio.h
        sys/ucred.h
@@ -1897,7 +1896,6 @@ fi
 if test "$PORTNAME" = "win32"; then
   AC_CHECK_FUNCS(_configthreadlocale)
   AC_LIBOBJ(dirmod)
-  AC_LIBOBJ(getrusage)
   AC_LIBOBJ(kill)
   AC_LIBOBJ(open)
   AC_LIBOBJ(system)
@@ -1905,6 +1903,7 @@ if test "$PORTNAME" = "win32"; then
   AC_LIBOBJ(win32env)
   AC_LIBOBJ(win32error)
   AC_LIBOBJ(win32fdatasync)
+  AC_LIBOBJ(win32getrusage)
   AC_LIBOBJ(win32link)
   AC_LIBOBJ(win32ntdll)
   AC_LIBOBJ(win32pread)
index efb34d4dcbcfa6be91e85288734f35ac5abc30d5..e3b19ca1ed4a7e77ee7f99b9ac622e82ac376e68 100644 (file)
@@ -75,6 +75,7 @@
 #include <dirent.h>
 #include <sys/file.h>
 #include <sys/param.h>
+#include <sys/resource.h>              /* for getrlimit */
 #include <sys/stat.h>
 #include <sys/types.h>
 #ifndef WIN32
@@ -83,9 +84,6 @@
 #include <limits.h>
 #include <unistd.h>
 #include <fcntl.h>
-#ifdef HAVE_SYS_RESOURCE_H
-#include <sys/resource.h>              /* for getrlimit */
-#endif
 
 #include "access/xact.h"
 #include "access/xlog.h"
index 671edcb3c7a878da4a74b982ee10b7304c98712c..7bec4e4ff58f373e86954cafe47aeb9be8590466 100644 (file)
 #include <limits.h>
 #include <signal.h>
 #include <unistd.h>
+#include <sys/resource.h>
 #include <sys/select.h>
 #include <sys/socket.h>
-#ifdef HAVE_SYS_RESOURCE_H
 #include <sys/time.h>
-#include <sys/resource.h>
-#endif
-
-#ifdef WIN32
-#include "rusagestub.h"
-#endif
 
 #include "access/parallel.h"
 #include "access/printtup.h"
@@ -4860,7 +4854,7 @@ ShowUsage(const char *title)
         * The following rusage fields are not defined by POSIX, but they're
         * present on all current Unix-like systems so we use them without any
         * special checks.  Some of these could be provided in our Windows
-        * emulation in src/port/getrusage.c with more work.
+        * emulation in src/port/win32getrusage.c with more work.
         */
        appendStringInfo(&str,
                                         "!\t%ld kB max resident size\n",
index 2762e8590d0a77a2379ee7ada5ec25e3c9692203..73e20081d1dafc38d348b5b1165235e033f20925 100644 (file)
 #include <fcntl.h>
 #include <signal.h>
 #include <time.h>
+#include <sys/resource.h>
 #include <sys/stat.h>
+#include <sys/time.h>
 #include <sys/wait.h>
 #include <unistd.h>
 
-#ifdef HAVE_SYS_RESOURCE_H
-#include <sys/time.h>
-#include <sys/resource.h>
-#endif
 
 #include "catalog/pg_control.h"
 #include "common/controldata_utils.h"
index 45606e944da464557d1ca73207c1e9e4b16571ee..c0e907d437379ba7c3bf8c62234a5e339b2704bc 100644 (file)
@@ -40,9 +40,7 @@
 #include <signal.h>
 #include <time.h>
 #include <sys/time.h>
-#ifdef HAVE_SYS_RESOURCE_H
 #include <sys/resource.h>              /* for getrlimit */
-#endif
 
 /* For testing, PGBENCH_USE_SELECT can be defined to force use of that code */
 #if defined(HAVE_PPOLL) && !defined(PGBENCH_USE_SELECT)
index 5f96f71896d174318c525a02807d7d1e28e9012e..45faf051219a88f6bda7bc63fd5526dcdc53c931 100644 (file)
 /* Define to 1 if you have the <sys/procctl.h> header file. */
 #undef HAVE_SYS_PROCCTL_H
 
-/* Define to 1 if you have the <sys/resource.h> header file. */
-#undef HAVE_SYS_RESOURCE_H
-
 /* Define to 1 if you have the <sys/signalfd.h> header file. */
 #undef HAVE_SYS_SIGNALFD_H
 
diff --git a/src/include/port/win32/sys/resource.h b/src/include/port/win32/sys/resource.h
new file mode 100644 (file)
index 0000000..a14feeb
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * Replacement for <sys/resource.h> for Windows.
+ */
+#ifndef WIN32_SYS_RESOURCE_H
+#define WIN32_SYS_RESOURCE_H
+
+#include <sys/time.h>                  /* for struct timeval */
+
+#define RUSAGE_SELF            0
+#define RUSAGE_CHILDREN (-1)
+
+struct rusage
+{
+       struct timeval ru_utime;        /* user time used */
+       struct timeval ru_stime;        /* system time used */
+};
+
+extern int     getrusage(int who, struct rusage *rusage);
+
+#endif                                                 /* WIN32_SYS_RESOURCE_H */
diff --git a/src/include/rusagestub.h b/src/include/rusagestub.h
deleted file mode 100644 (file)
index be26f84..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * rusagestub.h
- *       Stubs for getrusage(3).
- *
- *
- * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- * src/include/rusagestub.h
- *
- *-------------------------------------------------------------------------
- */
-#ifndef RUSAGESTUB_H
-#define RUSAGESTUB_H
-
-#include <sys/time.h>                  /* for struct timeval */
-#include <limits.h>                            /* for CLK_TCK */
-
-#define RUSAGE_SELF            0
-#define RUSAGE_CHILDREN (-1)
-
-struct rusage
-{
-       struct timeval ru_utime;        /* user time used */
-       struct timeval ru_stime;        /* system time used */
-};
-
-extern int     getrusage(int who, struct rusage *rusage);
-
-#endif                                                 /* RUSAGESTUB_H */
index a6344abd1071121ed9e52f997c4fdae3ff9f44cc..b2c4d36ced8782b9f96c654c22996752e19cbc2c 100644 (file)
 #ifndef PG_RUSAGE_H
 #define PG_RUSAGE_H
 
-#include <sys/time.h>
-
-#ifdef HAVE_SYS_RESOURCE_H
 #include <sys/resource.h>
-#else
-#include "rusagestub.h"
-#endif
+#include <sys/time.h>
 
 
 /* State structure for pg_rusage_init/pg_rusage_show */
similarity index 88%
rename from src/port/getrusage.c
rename to src/port/win32getrusage.c
index 2ba59ade2c3cf981f152dc600c2dbb0f9546a02d..8f3556f63b19b0062e53158894677dfe1506b79b 100644 (file)
@@ -1,6 +1,6 @@
 /*-------------------------------------------------------------------------
  *
- * getrusage.c
+ * win32getrusage.c
  *       get information about resource utilisation
  *
  * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
@@ -8,19 +8,14 @@
  *
  *
  * IDENTIFICATION
- *       src/port/getrusage.c
+ *       src/port/win32getrusage.c
  *
  *-------------------------------------------------------------------------
  */
 
 #include "c.h"
 
-#include "rusagestub.h"
-
-/*
- * This code works on Windows, which is the only supported platform without a
- * native version of getrusage().
- */
+#include <sys/resource.h>
 
 int
 getrusage(int who, struct rusage *rusage)
index 04ab513b7cb36aa813dc8c2900b441152ab9ac95..e015a11c21721bf2a137e2c5754a5e25a438610e 100644 (file)
 #include "postgres_fe.h"
 
 #include <ctype.h>
+#include <sys/resource.h>
 #include <sys/stat.h>
+#include <sys/time.h>
 #include <sys/wait.h>
 #include <signal.h>
 #include <unistd.h>
 
-#ifdef HAVE_SYS_RESOURCE_H
-#include <sys/time.h>
-#include <sys/resource.h>
-#endif
-
 #include "common/logging.h"
 #include "common/restricted_token.h"
 #include "common/string.h"
index bacc9207581faea124d8b3f89fd3092dee0dcad0..0a4f0d2eaa74c390cca9a09dd6e5b9988f7326fd 100644 (file)
@@ -100,7 +100,7 @@ sub mkvcbuild
 
        our @pgportfiles = qw(
          chklocale.c explicit_bzero.c
-         getpeereid.c getrusage.c inet_aton.c
+         getpeereid.c inet_aton.c
          getaddrinfo.c inet_net_ntop.c kill.c open.c
          snprintf.c strlcat.c strlcpy.c dirmod.c noblock.c path.c
          dirent.c getopt.c getopt_long.c
@@ -111,6 +111,7 @@ sub mkvcbuild
          win32dlopen.c
          win32env.c win32error.c
          win32fdatasync.c
+         win32getrusage.c
          win32gettimeofday.c
          win32link.c
          win32pread.c
index 3f69618c4aea213a880050a17369e089208e5942..df594b2fe7a1968e2af0efe3a0c3924a6d8c5bce 100644 (file)
@@ -364,7 +364,6 @@ sub GenerateFiles
                HAVE_SYS_PERSONALITY_H                   => undef,
                HAVE_SYS_PRCTL_H                         => undef,
                HAVE_SYS_PROCCTL_H                       => undef,
-               HAVE_SYS_RESOURCE_H                      => undef,
                HAVE_SYS_SIGNALFD_H                      => undef,
                HAVE_SYS_SOCKIO_H                        => undef,
                HAVE_SYS_STAT_H                          => 1,
index 6f336deae8a50b2790ed2b9d9172176ff7c291b4..a2120594806f81541a2337890ceabbdb4e59214b 100755 (executable)
@@ -71,6 +71,7 @@ do
 
        # Additional Windows-specific headers.
        test "$f" = src/include/port/win32_port.h && continue
+       test "$f" = src/include/port/win32/sys/resource.h && continue
        test "$f" = src/include/port/win32/sys/socket.h && continue
        test "$f" = src/include/port/win32_msvc/dirent.h && continue
        test "$f" = src/include/port/win32_msvc/utime.h && continue
@@ -90,10 +91,6 @@ do
        test "$f" = src/include/port/atomics/generic-msvc.h && continue
        test "$f" = src/include/port/atomics/generic-sunpro.h && continue
 
-       # rusagestub.h is also platform-specific, and will be included
-       # by utils/pg_rusage.h if necessary.
-       test "$f" = src/include/rusagestub.h && continue
-
        # sepgsql.h depends on headers that aren't there on most platforms.
        test "$f" = contrib/sepgsql/sepgsql.h && continue
 
index ae60ef09e688bf5ac145c557e364099be0979b27..bbe89dd1a0803bf7c239dd351c1e8df0d85bda83 100755 (executable)
@@ -86,10 +86,6 @@ do
        test "$f" = src/include/port/atomics/generic-msvc.h && continue
        test "$f" = src/include/port/atomics/generic-sunpro.h && continue
 
-       # rusagestub.h is also platform-specific, and will be included
-       # by utils/pg_rusage.h if necessary.
-       test "$f" = src/include/rusagestub.h && continue
-
        # sepgsql.h depends on headers that aren't there on most platforms.
        test "$f" = contrib/sepgsql/sepgsql.h && continue