Skip to content

Commit 36b3d52

Browse files
committed
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 <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/CA%2BhUKG%2BL_3brvh%3D8e0BW_VfX9h7MtwgN%3DnFHP5o7X2oZucY9dg%40mail.gmail.com
1 parent 37a65d1 commit 36b3d52

File tree

16 files changed

+42
-89
lines changed

16 files changed

+42
-89
lines changed

configure

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13874,7 +13874,7 @@ $as_echo "#define HAVE_STDBOOL_H 1" >>confdefs.h
1387413874
fi
1387513875

1387613876

13877-
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
13877+
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
1387813878
do :
1387913879
as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
1388013880
ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
@@ -16734,12 +16734,6 @@ done
1673416734
;;
1673516735
esac
1673616736

16737-
case " $LIBOBJS " in
16738-
*" getrusage.$ac_objext "* ) ;;
16739-
*) LIBOBJS="$LIBOBJS getrusage.$ac_objext"
16740-
;;
16741-
esac
16742-
1674316737
case " $LIBOBJS " in
1674416738
*" kill.$ac_objext "* ) ;;
1674516739
*) LIBOBJS="$LIBOBJS kill.$ac_objext"
@@ -16782,6 +16776,12 @@ esac
1678216776
;;
1678316777
esac
1678416778

16779+
case " $LIBOBJS " in
16780+
*" win32getrusage.$ac_objext "* ) ;;
16781+
*) LIBOBJS="$LIBOBJS win32getrusage.$ac_objext"
16782+
;;
16783+
esac
16784+
1678516785
case " $LIBOBJS " in
1678616786
*" win32link.$ac_objext "* ) ;;
1678716787
*) LIBOBJS="$LIBOBJS win32link.$ac_objext"

configure.ac

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,7 +1459,6 @@ AC_CHECK_HEADERS(m4_normalize([
14591459
sys/personality.h
14601460
sys/prctl.h
14611461
sys/procctl.h
1462-
sys/resource.h
14631462
sys/signalfd.h
14641463
sys/sockio.h
14651464
sys/ucred.h
@@ -1897,14 +1896,14 @@ fi
18971896
if test "$PORTNAME" = "win32"; then
18981897
AC_CHECK_FUNCS(_configthreadlocale)
18991898
AC_LIBOBJ(dirmod)
1900-
AC_LIBOBJ(getrusage)
19011899
AC_LIBOBJ(kill)
19021900
AC_LIBOBJ(open)
19031901
AC_LIBOBJ(system)
19041902
AC_LIBOBJ(win32dlopen)
19051903
AC_LIBOBJ(win32env)
19061904
AC_LIBOBJ(win32error)
19071905
AC_LIBOBJ(win32fdatasync)
1906+
AC_LIBOBJ(win32getrusage)
19081907
AC_LIBOBJ(win32link)
19091908
AC_LIBOBJ(win32ntdll)
19101909
AC_LIBOBJ(win32pread)

src/backend/storage/file/fd.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
#include <dirent.h>
7676
#include <sys/file.h>
7777
#include <sys/param.h>
78+
#include <sys/resource.h> /* for getrlimit */
7879
#include <sys/stat.h>
7980
#include <sys/types.h>
8081
#ifndef WIN32
@@ -83,9 +84,6 @@
8384
#include <limits.h>
8485
#include <unistd.h>
8586
#include <fcntl.h>
86-
#ifdef HAVE_SYS_RESOURCE_H
87-
#include <sys/resource.h> /* for getrlimit */
88-
#endif
8987

9088
#include "access/xact.h"
9189
#include "access/xlog.h"

src/backend/tcop/postgres.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,10 @@
2323
#include <limits.h>
2424
#include <signal.h>
2525
#include <unistd.h>
26+
#include <sys/resource.h>
2627
#include <sys/select.h>
2728
#include <sys/socket.h>
28-
#ifdef HAVE_SYS_RESOURCE_H
2929
#include <sys/time.h>
30-
#include <sys/resource.h>
31-
#endif
32-
33-
#ifdef WIN32
34-
#include "rusagestub.h"
35-
#endif
3630

3731
#include "access/parallel.h"
3832
#include "access/printtup.h"
@@ -4860,7 +4854,7 @@ ShowUsage(const char *title)
48604854
* The following rusage fields are not defined by POSIX, but they're
48614855
* present on all current Unix-like systems so we use them without any
48624856
* special checks. Some of these could be provided in our Windows
4863-
* emulation in src/port/getrusage.c with more work.
4857+
* emulation in src/port/win32getrusage.c with more work.
48644858
*/
48654859
appendStringInfo(&str,
48664860
"!\t%ld kB max resident size\n",

src/bin/pg_ctl/pg_ctl.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@
1414
#include <fcntl.h>
1515
#include <signal.h>
1616
#include <time.h>
17+
#include <sys/resource.h>
1718
#include <sys/stat.h>
19+
#include <sys/time.h>
1820
#include <sys/wait.h>
1921
#include <unistd.h>
2022

21-
#ifdef HAVE_SYS_RESOURCE_H
22-
#include <sys/time.h>
23-
#include <sys/resource.h>
24-
#endif
2523

2624
#include "catalog/pg_control.h"
2725
#include "common/controldata_utils.h"

src/bin/pgbench/pgbench.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@
4040
#include <signal.h>
4141
#include <time.h>
4242
#include <sys/time.h>
43-
#ifdef HAVE_SYS_RESOURCE_H
4443
#include <sys/resource.h> /* for getrlimit */
45-
#endif
4644

4745
/* For testing, PGBENCH_USE_SELECT can be defined to force use of that code */
4846
#if defined(HAVE_PPOLL) && !defined(PGBENCH_USE_SELECT)

src/include/pg_config.h.in

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,9 +505,6 @@
505505
/* Define to 1 if you have the <sys/procctl.h> header file. */
506506
#undef HAVE_SYS_PROCCTL_H
507507

508-
/* Define to 1 if you have the <sys/resource.h> header file. */
509-
#undef HAVE_SYS_RESOURCE_H
510-
511508
/* Define to 1 if you have the <sys/signalfd.h> header file. */
512509
#undef HAVE_SYS_SIGNALFD_H
513510

src/include/port/win32/sys/resource.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Replacement for <sys/resource.h> for Windows.
3+
*/
4+
#ifndef WIN32_SYS_RESOURCE_H
5+
#define WIN32_SYS_RESOURCE_H
6+
7+
#include <sys/time.h> /* for struct timeval */
8+
9+
#define RUSAGE_SELF 0
10+
#define RUSAGE_CHILDREN (-1)
11+
12+
struct rusage
13+
{
14+
struct timeval ru_utime; /* user time used */
15+
struct timeval ru_stime; /* system time used */
16+
};
17+
18+
extern int getrusage(int who, struct rusage *rusage);
19+
20+
#endif /* WIN32_SYS_RESOURCE_H */

src/include/rusagestub.h

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/include/utils/pg_rusage.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,8 @@
1414
#ifndef PG_RUSAGE_H
1515
#define PG_RUSAGE_H
1616

17-
#include <sys/time.h>
18-
19-
#ifdef HAVE_SYS_RESOURCE_H
2017
#include <sys/resource.h>
21-
#else
22-
#include "rusagestub.h"
23-
#endif
18+
#include <sys/time.h>
2419

2520

2621
/* State structure for pg_rusage_init/pg_rusage_show */

src/port/getrusage.c renamed to src/port/win32getrusage.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
11
/*-------------------------------------------------------------------------
22
*
3-
* getrusage.c
3+
* win32getrusage.c
44
* get information about resource utilisation
55
*
66
* Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
*
1010
* IDENTIFICATION
11-
* src/port/getrusage.c
11+
* src/port/win32getrusage.c
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
1515

1616
#include "c.h"
1717

18-
#include "rusagestub.h"
19-
20-
/*
21-
* This code works on Windows, which is the only supported platform without a
22-
* native version of getrusage().
23-
*/
18+
#include <sys/resource.h>
2419

2520
int
2621
getrusage(int who, struct rusage *rusage)

src/test/regress/pg_regress.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,13 @@
1919
#include "postgres_fe.h"
2020

2121
#include <ctype.h>
22+
#include <sys/resource.h>
2223
#include <sys/stat.h>
24+
#include <sys/time.h>
2325
#include <sys/wait.h>
2426
#include <signal.h>
2527
#include <unistd.h>
2628

27-
#ifdef HAVE_SYS_RESOURCE_H
28-
#include <sys/time.h>
29-
#include <sys/resource.h>
30-
#endif
31-
3229
#include "common/logging.h"
3330
#include "common/restricted_token.h"
3431
#include "common/string.h"

src/tools/msvc/Mkvcbuild.pm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ sub mkvcbuild
100100

101101
our @pgportfiles = qw(
102102
chklocale.c explicit_bzero.c
103-
getpeereid.c getrusage.c inet_aton.c
103+
getpeereid.c inet_aton.c
104104
getaddrinfo.c inet_net_ntop.c kill.c open.c
105105
snprintf.c strlcat.c strlcpy.c dirmod.c noblock.c path.c
106106
dirent.c getopt.c getopt_long.c
@@ -111,6 +111,7 @@ sub mkvcbuild
111111
win32dlopen.c
112112
win32env.c win32error.c
113113
win32fdatasync.c
114+
win32getrusage.c
114115
win32gettimeofday.c
115116
win32link.c
116117
win32pread.c

src/tools/msvc/Solution.pm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,6 @@ sub GenerateFiles
364364
HAVE_SYS_PERSONALITY_H => undef,
365365
HAVE_SYS_PRCTL_H => undef,
366366
HAVE_SYS_PROCCTL_H => undef,
367-
HAVE_SYS_RESOURCE_H => undef,
368367
HAVE_SYS_SIGNALFD_H => undef,
369368
HAVE_SYS_SOCKIO_H => undef,
370369
HAVE_SYS_STAT_H => 1,

src/tools/pginclude/cpluspluscheck

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ do
7171

7272
# Additional Windows-specific headers.
7373
test "$f" = src/include/port/win32_port.h && continue
74+
test "$f" = src/include/port/win32/sys/resource.h && continue
7475
test "$f" = src/include/port/win32/sys/socket.h && continue
7576
test "$f" = src/include/port/win32_msvc/dirent.h && continue
7677
test "$f" = src/include/port/win32_msvc/utime.h && continue
@@ -90,10 +91,6 @@ do
9091
test "$f" = src/include/port/atomics/generic-msvc.h && continue
9192
test "$f" = src/include/port/atomics/generic-sunpro.h && continue
9293

93-
# rusagestub.h is also platform-specific, and will be included
94-
# by utils/pg_rusage.h if necessary.
95-
test "$f" = src/include/rusagestub.h && continue
96-
9794
# sepgsql.h depends on headers that aren't there on most platforms.
9895
test "$f" = contrib/sepgsql/sepgsql.h && continue
9996

src/tools/pginclude/headerscheck

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,6 @@ do
8686
test "$f" = src/include/port/atomics/generic-msvc.h && continue
8787
test "$f" = src/include/port/atomics/generic-sunpro.h && continue
8888

89-
# rusagestub.h is also platform-specific, and will be included
90-
# by utils/pg_rusage.h if necessary.
91-
test "$f" = src/include/rusagestub.h && continue
92-
9389
# sepgsql.h depends on headers that aren't there on most platforms.
9490
test "$f" = contrib/sepgsql/sepgsql.h && continue
9591

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy