From 6250e6c5ed2bbb4c65f7998df8d0064aec3cf8d3 Mon Sep 17 00:00:00 2001
From: "Dmitry V. Levin" <ldv@altlinux.org>
Date: Fri, 9 Oct 2015 01:38:07 +0000
Subject: [PATCH] fcntl.c: use <linux/fcntl.h> instead of <fcntl.h>

Include <linux/fcntl.h> for proper definitions of F_* constants
and flock structures.

* configure.ac (AC_CHECK_TYPES): Check for struct flock, struct flock64,
struct __kernel_flock, and struct __kernel_flock64 in <linux/fcntl.h>.
* flock.h: New file.
* Makefile.am (strace_SOURCES): Add it.
* fcntl.c: Include it instead of <fcntl.h>.
(struct flock64): Remove.
(printflock): Use struct_kernel_flock instead of struct flock.
(printflock64): Use struct_kernel_flock64 instead of struct flock64.
---
 Makefile.am  |  1 +
 configure.ac |  5 ++++-
 fcntl.c      | 14 +++-----------
 flock.h      | 17 +++++++++++++++++
 4 files changed, 25 insertions(+), 12 deletions(-)
 create mode 100644 flock.h

diff --git a/Makefile.am b/Makefile.am
index dbe15d81..55379b73 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -65,6 +65,7 @@ strace_SOURCES =	\
 	file.c		\
 	file_handle.c	\
 	flock.c		\
+	flock.h		\
 	futex.c		\
 	get_robust_list.c \
 	getcpu.c	\
diff --git a/configure.ac b/configure.ac
index 286db29c..29ea904f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -338,7 +338,10 @@ AC_CHECK_MEMBERS([struct sigevent._sigev_un._pad,
 		  siginfo_t.si_timerid,
 		  siginfo_t.si_overrun],,, [#include <signal.h>])
 
-AC_CHECK_TYPES([struct flock64],,, [#include <fcntl.h>])
+AC_CHECK_TYPES([struct flock,
+		struct flock64,
+		struct __kernel_flock,
+		struct __kernel_flock64],,, [#include <linux/fcntl.h>])
 
 AC_CHECK_MEMBERS([struct timex.tai],,, [#include <sys/timex.h>])
 
diff --git a/fcntl.c b/fcntl.c
index 3cf984bc..226c946c 100644
--- a/fcntl.c
+++ b/fcntl.c
@@ -29,7 +29,7 @@
  */
 
 #include "defs.h"
-#include <fcntl.h>
+#include "flock.h"
 
 #include "xlat/fcntlcmds.h"
 #include "xlat/fdflags.h"
@@ -48,18 +48,10 @@
 
 #if USE_PRINTFLOCK64
 
-# ifndef HAVE_STRUCT_FLOCK64
-struct flock64 {
-	short int l_type, l_whence;
-	int64_t l_start, l_len;
-	int l_pid;
-};
-# endif
-
 static void
 printflock64(struct tcb *tcp, long addr, int getlk)
 {
-	struct flock64 fl;
+	struct_kernel_flock64 fl;
 
 	if (umove_or_printaddr(tcp, addr, &fl))
 		return;
@@ -78,7 +70,7 @@ printflock64(struct tcb *tcp, long addr, int getlk)
 static void
 printflock(struct tcb *tcp, long addr, int getlk)
 {
-	struct flock fl;
+	struct_kernel_flock fl;
 
 #if SUPPORTED_PERSONALITIES > 1
 	if (
diff --git a/flock.h b/flock.h
new file mode 100644
index 00000000..33b7538d
--- /dev/null
+++ b/flock.h
@@ -0,0 +1,17 @@
+#include <linux/fcntl.h>
+
+#if defined HAVE_STRUCT_FLOCK
+typedef struct flock struct_kernel_flock;
+#elif defined HAVE_STRUCT___KERNEL_FLOCK
+typedef struct __kernel_flock struct_kernel_flock;
+#else
+# error struct flock definition not found in <linux/fcntl.h>
+#endif
+
+#if defined HAVE_STRUCT_FLOCK64
+typedef struct flock64 struct_kernel_flock64;
+#elif defined HAVE_STRUCT___KERNEL_FLOCK64
+typedef struct __kernel_flock64 struct_kernel_flock64;
+#else
+# error struct flock64 definition not found in <linux/fcntl.h>
+#endif
-- 
2.40.0