Skip to content

Commit

Permalink
Fixes error due to having the sys/resource.h file and not having the …
Browse files Browse the repository at this point in the history
…`getrlimit` function.
  • Loading branch information
kdschlosser committed Oct 30, 2024
1 parent ef3b574 commit 8f496ca
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ if(NOT HAVE_STDINT_H)
message(FATAL_ERROR "Could NOT find required header stdint.h")
endif()

check_function_exists(getrlimit LIBVNCSERVER_HAVE_GETRLIMIT)
check_function_exists(gettimeofday LIBVNCSERVER_HAVE_GETTIMEOFDAY)
check_function_exists(vfork LIBVNCSERVER_HAVE_VFORK)
check_function_exists(vprintf LIBVNCSERVER_HAVE_VPRINTF)
Expand Down
3 changes: 3 additions & 0 deletions include/rfb/rfbconfig.h.cmakein
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@
/* Define to 1 if you have <sys/resource.h> */
#cmakedefine LIBVNCSERVER_HAVE_SYS_RESOURCE_H 1

/* Define to 1 if you have the `getrlimit' function. */
#cmakedefine LIBVNCSERVER_HAVE_GETRLIMIT 1

/* Define to 1 if you have the <unistd.h> header file. */
#cmakedefine LIBVNCSERVER_HAVE_UNISTD_H 1

Expand Down
4 changes: 2 additions & 2 deletions src/libvncserver/sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ rfbProcessNewConnection(rfbScreenInfoPtr rfbScreen)
rfbSocket sock = RFB_INVALID_SOCKET;
fd_set listen_fds;
rfbSocket chosen_listen_sock = RFB_INVALID_SOCKET;
#if defined LIBVNCSERVER_HAVE_SYS_RESOURCE_H && defined LIBVNCSERVER_HAVE_FCNTL_H
#if defined LIBVNCSERVER_HAVE_GETRLIMIT && defined LIBVNCSERVER_HAVE_FCNTL_H
struct rlimit rlim;
size_t maxfds, curfds, i;
#endif
Expand Down Expand Up @@ -629,7 +629,7 @@ rfbProcessNewConnection(rfbScreenInfoPtr rfbScreen)
Our approach is to deny new clients when we have reached a certain fraction of the per-process limit of file descriptors.
TODO: add Windows support.
*/
#if defined LIBVNCSERVER_HAVE_SYS_RESOURCE_H && defined LIBVNCSERVER_HAVE_FCNTL_H
#if defined LIBVNCSERVER_HAVE_GETRLIMIT && defined LIBVNCSERVER_HAVE_FCNTL_H
if(getrlimit(RLIMIT_NOFILE, &rlim) < 0)
maxfds = 100; /* use a sane default if getting the limit fails */
else
Expand Down

0 comments on commit 8f496ca

Please sign in to comment.