summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Munro2022-08-13 11:35:24 +0000
committerThomas Munro2022-08-13 12:09:47 +0000
commit36b3d52459aecd4f8bc39a4604e42186c48aa9d2 (patch)
tree15a7b1211cac9a9fcb193e3eb4984cbe73cb1b8a /src
parent37a65d1db14658bc75faa3aea7bd5a064118d135 (diff)
Remove configure probe for sys/resource.h and refactor.
<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
Diffstat (limited to 'src')
-rw-r--r--src/backend/storage/file/fd.c4
-rw-r--r--src/backend/tcop/postgres.c10
-rw-r--r--src/bin/pg_ctl/pg_ctl.c6
-rw-r--r--src/bin/pgbench/pgbench.c2
-rw-r--r--src/include/pg_config.h.in3
-rw-r--r--src/include/port/win32/sys/resource.h20
-rw-r--r--src/include/rusagestub.h31
-rw-r--r--src/include/utils/pg_rusage.h7
-rw-r--r--src/port/win32getrusage.c (renamed from src/port/getrusage.c)11
-rw-r--r--src/test/regress/pg_regress.c7
-rw-r--r--src/tools/msvc/Mkvcbuild.pm3
-rw-r--r--src/tools/msvc/Solution.pm1
-rwxr-xr-xsrc/tools/pginclude/cpluspluscheck5
-rwxr-xr-xsrc/tools/pginclude/headerscheck4
14 files changed, 34 insertions, 80 deletions
diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c
index efb34d4dcbc..e3b19ca1ed4 100644
--- a/src/backend/storage/file/fd.c
+++ b/src/backend/storage/file/fd.c
@@ -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"
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index 671edcb3c7a..7bec4e4ff58 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -23,16 +23,10 @@
#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",
diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c
index 2762e8590d0..73e20081d1d 100644
--- a/src/bin/pg_ctl/pg_ctl.c
+++ b/src/bin/pg_ctl/pg_ctl.c
@@ -14,14 +14,12 @@
#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"
diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index 45606e944da..c0e907d4373 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -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)
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index 5f96f71896d..45faf051219 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -505,9 +505,6 @@
/* 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
index 00000000000..a14feeb5844
--- /dev/null
+++ b/src/include/port/win32/sys/resource.h
@@ -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
index be26f849a59..00000000000
--- a/src/include/rusagestub.h
+++ /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 */
diff --git a/src/include/utils/pg_rusage.h b/src/include/utils/pg_rusage.h
index a6344abd107..b2c4d36ced8 100644
--- a/src/include/utils/pg_rusage.h
+++ b/src/include/utils/pg_rusage.h
@@ -14,13 +14,8 @@
#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 */
diff --git a/src/port/getrusage.c b/src/port/win32getrusage.c
index 2ba59ade2c3..8f3556f63b1 100644
--- a/src/port/getrusage.c
+++ b/src/port/win32getrusage.c
@@ -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)
diff --git a/src/test/regress/pg_regress.c b/src/test/regress/pg_regress.c
index 04ab513b7cb..e015a11c217 100644
--- a/src/test/regress/pg_regress.c
+++ b/src/test/regress/pg_regress.c
@@ -19,16 +19,13 @@
#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"
diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm
index bacc9207581..0a4f0d2eaa7 100644
--- a/src/tools/msvc/Mkvcbuild.pm
+++ b/src/tools/msvc/Mkvcbuild.pm
@@ -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
diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index 3f69618c4ae..df594b2fe7a 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -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,
diff --git a/src/tools/pginclude/cpluspluscheck b/src/tools/pginclude/cpluspluscheck
index 6f336deae8a..a2120594806 100755
--- a/src/tools/pginclude/cpluspluscheck
+++ b/src/tools/pginclude/cpluspluscheck
@@ -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
diff --git a/src/tools/pginclude/headerscheck b/src/tools/pginclude/headerscheck
index ae60ef09e68..bbe89dd1a08 100755
--- a/src/tools/pginclude/headerscheck
+++ b/src/tools/pginclude/headerscheck
@@ -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