Skip to content

Commit

Permalink
core: Allow building on very old systems with kernels < 3.15
Browse files Browse the repository at this point in the history
Open file descriptor locks were introduced in Linux 3.15, so we
cannot use that type of locking on systems with older kernels
(e.g. CentOS 7, which of course is no longer supported).

Since this problem only occurs on kernels no longer supported
by keepalived this commit simply removes the file locking, rather
than implementing a more comprehensive solution.

It is expected that at some point, in order to simplify the code,
support for kernels no longer supported by any of the main
distros will be removed from keepalived.

Signed-off-by: Quentin Armitage <[email protected]>
  • Loading branch information
pqarmitage committed Nov 6, 2024
1 parent 706be31 commit 7d2b85d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
15 changes: 14 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1695,7 +1695,7 @@ AC_CHECK_LIB(magic, magic_open,
AM_CONDITIONAL([MAGIC], [test $MAGIC -eq 1])
unset LIBS
dnl -- Check for the following variables introduced at various times into Linux
dnl -- Check for the following definitions introduced at various times into Linux
dnl --RTAX_QUICKACK dnl -- Linux 3.11
dnl --FRA_SUPPRESS_PREFIXLEN dnl -- Linux 3.12
dnl --FRA_SUPPRESS_IFGROUP dnl -- Linux 3.12
Expand Down Expand Up @@ -1736,6 +1736,19 @@ for flag in IFA_FLAGS; do
fi
done
dnl -- Linux 3.15
AC_CHECK_DECLS([F_OFD_SETLK], [], [],
[[
#include <unistd.h>
#include <fcntl.h>
]])
for flag in F_OFD_SETLK; do
AS_VAR_COPY([decl_var], [ac_cv_have_decl_$flag])
if test ${decl_var} = yes; then
add_system_opt[${flag}]
fi
done
dnl - Introduced in Linux 5.18
AC_CHECK_DECLS([IFA_PROTO], [], [], [[#include <linux/if_addr.h>]])
for flag in IFA_PROTO; do
Expand Down
4 changes: 4 additions & 0 deletions keepalived/core/pidfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ create_pidfile(pidfile_t *pidf)
struct stat st, fd_st;
int error;
int ret;
#if HAVE_DECL_F_OFD_SETLK == 1
struct flock fl = { .l_type = F_WRLCK, .l_whence = SEEK_SET, .l_start = 0, .l_len = 0 };
#endif

for (;;) {
/* We want to create the file with permissions rw-r--r-- */
Expand All @@ -177,6 +179,7 @@ create_pidfile(pidfile_t *pidf)
return true;
}

#if HAVE_DECL_F_OFD_SETLK == 1
fl.l_pid = 0;
while ((ret = fcntl(pidf->fd, F_OFD_SETLK, &fl)) && errno == EINTR);
if (ret) {
Expand All @@ -187,6 +190,7 @@ create_pidfile(pidfile_t *pidf)

break;
}
#endif

/* Make sure the file has not been removed/moved */
if (stat(pidf->path, &st)) {
Expand Down

0 comments on commit 7d2b85d

Please sign in to comment.