pg_auto_failover icon indicating copy to clipboard operation
pg_auto_failover copied to clipboard

health_check_worker.c: WaitForEvent(List *healthCheckList) uses non-crosscompatible machinery

Open pashagolub opened this issue 4 years ago • 2 comments

WaitForEvent function heavily dependant on poll.h include, but in all other places, PostgreSQL uses such include tecnhique:

#ifdef HAVE_POLL_H
#include <poll.h>
#endif

If we do define include in such a manner we got:

pasha@PG480 MINGW64 /src/pg_auto_failover
$ make
make -C src/monitor/ all
make[1]: Entering directory '/src/pg_auto_failover/src/monitor'
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -Wno-stringop-truncation -O2  -std=c99 -Wall -Werror -Wno-unused-parameter -Iinclude -IC:/Users/pasha/Code/POSTGR~1/msys64/usr/local/POSTGR~1/include -I. -I./ -IC:/Users/pasha/Code/POSTGR~1/msys64/usr/local/POSTGR~1/include/server -IC:/Users/pasha/Code/POSTGR~1/msys64/usr/local/POSTGR~1/include/internal  -I./src/include/port/win32 -DEXEC_BACKEND  -IC:/Users/pasha/Code/POSTGR~1/msys64/usr/local/POSTGR~1/include/server/port/win32 -DWIN32_STACK_RLIMIT=4194304  -c -o health_check_worker.o health_check_worker.c
health_check_worker.c: In function 'HealthCheckWorkerLauncherMain':
health_check_worker.c:292:44: error: passing argument 2 of 'WaitForBackgroundWorkerStartup' from incompatible pointer type [-Werror=incompatible-pointer-types]
  292 |     WaitForBackgroundWorkerStartup(handle, &pid);
      |                                            ^~~~
      |                                            |
      |                                            int *
In file included from health_check_worker.c:28:
C:/Users/pasha/Code/POSTGR~1/msys64/usr/local/POSTGR~1/include/server/postmaster/bgworker.h:123:94: note: expected 'pid_t *' {aka 'long long int *'} but argument is of type 'int *'
  123 | extern BgwHandleStatus WaitForBackgroundWorkerStartup(BackgroundWorkerHandle *handle, pid_t *pid);
      |                                                                                       ~~~~~~~^~~
health_check_worker.c: In function 'WaitForEvent':
health_check_worker.c:637:64: error: invalid application of 'sizeof' to incomplete type 'struct pollfd'
  637 |  pollFDs = (struct pollfd *) palloc0(healthCheckCount * sizeof(struct pollfd));
      |                                                                ^~~~~~
health_check_worker.c:644:47: error: invalid use of undefined type 'struct pollfd'
  644 |   struct pollfd *pollFileDescriptor = &pollFDs[healthCheckIndex];
      |                                               ^
health_check_worker.c:644:47: error: dereferencing pointer to incomplete type 'struct pollfd'
health_check_worker.c:670:21: error: 'POLLERR' undeclared (first use in this function)
  670 |     pollEventMask = POLLERR | POLLIN;
      |                     ^~~~~~~
health_check_worker.c:670:21: note: each undeclared identifier is reported only once for each function it appears in
health_check_worker.c:670:31: error: 'POLLIN' undeclared (first use in this function); did you mean 'LPOLELINK'?
  670 |     pollEventMask = POLLERR | POLLIN;
      |                               ^~~~~~
      |                               LPOLELINK
health_check_worker.c:674:31: error: 'POLLOUT' undeclared (first use in this function)
  674 |     pollEventMask = POLLERR | POLLOUT;
      |                               ^~~~~~~
health_check_worker.c:694:15: error: implicit declaration of function 'poll' [-Werror=implicit-function-declaration]
  694 |  pollResult = poll(pollFDs, healthCheckCount, pollTimeout);
      |               ^~~~
health_check_worker.c:706:47: error: invalid use of undefined type 'struct pollfd'
  706 |   struct pollfd *pollFileDescriptor = &pollFDs[healthCheckIndex];
      |                                               ^
cc1.exe: all warnings being treated as errors
make[1]: *** [<builtin>: health_check_worker.o] Error 1
make[1]: Leaving directory '/src/pg_auto_failover/src/monitor'
make: *** [Makefile:16: monitor] Error 2

I think we need to rewrite that particular piece of code to be crosscompatible

pashagolub avatar Sep 25 '19 13:09 pashagolub

Hi @pashagolub ; thanks for this work!

Windows compatibility is not a priority for the project at the moment, though it's still a very nice property to have. I'm leaving this issue open. We don't have someone we can assign to it for the time being, so feel free to contribute patches yourself if you want to / have the time to !

DimCitus avatar Sep 26 '19 09:09 DimCitus

Yeap, I know about that. Just wanted let you know about places I've found during quick look around

pashagolub avatar Sep 27 '19 10:09 pashagolub

Did you close the issue because it's no longer a problem, or because it's a “wont fix” situation?

DimCitus avatar Sep 21 '22 10:09 DimCitus

more like "won't fix". Trying to tidy my opened issues :)

pashagolub avatar Sep 21 '22 10:09 pashagolub