Skip to contentSkip to conversation

Build fix undefined struct file_handle

PATCH New Petr Vorel 2 participants 6 messages Jan 12, 2021 – Jan 13, 2021

lore
Share & tools
lore

Petr Vorel

author
#0 lore raw

cover Build fix undefined struct file_handle

Hi all,

this would be great to get merged before release.

Kind regards,
Petr

Petr Vorel (3):
lapi: Move struct file_handle into lapi/fcntl.h
fanotify: Fix build on undefined struct file_handle
syscalls: Remove unused include <fcntl.h>

 include/lapi/fcntl.h                                   | 10 ++++++++++
 include/lapi/name_to_handle_at.h                       |  9 +--------
 testcases/kernel/syscalls/fanotify/fanotify.h          |  2 +-
 testcases/kernel/syscalls/fanotify/fanotify09.c        |  1 -
 testcases/kernel/syscalls/fanotify/fanotify13.c        |  1 -
 testcases/kernel/syscalls/fanotify/fanotify15.c        |  1 -
 testcases/kernel/syscalls/fanotify/fanotify16.c        |  1 -
 .../syscalls/name_to_handle_at/name_to_handle_at01.c   |  1 -
 .../syscalls/name_to_handle_at/name_to_handle_at02.c   |  1 -
 .../syscalls/open_by_handle_at/open_by_handle_at01.c   |  1 -
 .../syscalls/open_by_handle_at/open_by_handle_at02.c   |  1 -
 11 files changed, 12 insertions(+), 17 deletions(-)
Signature · 1 line
2.29.2
author
#1 lore raw

PATCH 1/3 lapi: Move struct file_handle into lapi/fcntl.h

that way it can be used in fanotify tests
(some of use the struct, but not name_to_handle_at() syscall) and the struct is defined in <fcntl.h> anyway.

---
 include/lapi/fcntl.h             | 10 ++++++++++
 include/lapi/name_to_handle_at.h |  9 +--------
 2 files changed, 11 insertions(+), 8 deletions(-)
include/lapi/fcntl.h +10 -0
index d6665915f..ab460beb3 100644
@@ -6,6 +6,7 @@
 #ifndef __LAPI_FCNTL_H__
 #define __LAPI_FCNTL_H__
 
+#include "config.h"
 #include <fcntl.h>
 #include <sys/socket.h>
 
@@ -140,4 +141,13 @@
 # define MAX_HANDLE_SZ	128
 #endif
 
+#ifndef HAVE_NAME_TO_HANDLE_AT
+struct file_handle {
+	unsigned int handle_bytes;
+	int handle_type;
+	/* File identifier.  */
+	unsigned char f_handle[0];
+};
+#endif /* HAVE_NAME_TO_HANDLE_AT */
+
 #endif /* __LAPI_FCNTL_H__ */
include/lapi/name_to_handle_at.h +1 -8
index 3484133d1..275db4ae0 100644
@@ -15,13 +15,6 @@
 #include "tst_test.h"
 
 #ifndef HAVE_NAME_TO_HANDLE_AT
-struct file_handle {
-	unsigned int handle_bytes;
-	int handle_type;
-	/* File identifier.  */
-	unsigned char f_handle[0];
-};
-
 static inline int name_to_handle_at(int dfd, const char *pathname,
                                     struct file_handle *handle,
                                     int *mount_id, int flags)
@@ -35,7 +28,7 @@ static inline int open_by_handle_at(int mount_fd, struct file_handle *handle,
 {
 	return tst_syscall(__NR_open_by_handle_at, mount_fd, handle, flags);
 }
-#endif
+#endif /* HAVE_NAME_TO_HANDLE_AT */
 
 /* Returns a valid pointer on success, NULL on errors */
 static inline struct file_handle *
Signature · 1 line
2.29.2
author
#2 lore raw

PATCH 2/3 fanotify: Fix build on undefined struct file_handle

In reply to Petr Vorel

This fixes error:
fanotify09.c:201:32: error: dereferencing pointer to incomplete type ?struct file_handle?
201 | filename = (char *)file_handle->f_handle + file_handle->handle_bytes;

---
 testcases/kernel/syscalls/fanotify/fanotify.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/kernel/syscalls/fanotify/fanotify.h +1 -1
index 8907db052..039379961 100644
@@ -12,8 +12,8 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <errno.h>
-#include <fcntl.h>
 #include <sys/fanotify.h>
+#include "lapi/fcntl.h"
 
 int safe_fanotify_init(const char *file, const int lineno,
 	unsigned int flags, unsigned int event_f_flags)
Signature · 1 line
2.29.2
author
#3 lore raw

PATCH 3/3 syscalls: Remove unused include <fcntl.h>

In reply to Petr Vorel

Tests should always use lapi/fcntl.h instead of <fcntl.h> to fix possible missing definitions.

But in this case removing include, because fanotify tests include <fcntl.h> in lapi/fcntl.h (via fanotify.h) and {name_to,open_by}_handle_at tests include lapi/fcntl.h in lapi/name_to_handle_at.h.

---
 testcases/kernel/syscalls/fanotify/fanotify09.c                  | 1 -
 testcases/kernel/syscalls/fanotify/fanotify13.c                  | 1 -
 testcases/kernel/syscalls/fanotify/fanotify15.c                  | 1 -
 testcases/kernel/syscalls/fanotify/fanotify16.c                  | 1 -
 .../kernel/syscalls/name_to_handle_at/name_to_handle_at01.c      | 1 -
 .../kernel/syscalls/name_to_handle_at/name_to_handle_at02.c      | 1 -
 .../kernel/syscalls/open_by_handle_at/open_by_handle_at01.c      | 1 -
 .../kernel/syscalls/open_by_handle_at/open_by_handle_at02.c      | 1 -
 8 files changed, 8 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify09.c +0 -1
index 30e212f44..918e40274 100644
@@ -30,7 +30,6 @@
 #include <stdio.h>
 #include <sys/stat.h>
 #include <sys/types.h>
-#include <fcntl.h>
 #include <errno.h>
 #include <string.h>
 #include <sys/mount.h>
testcases/kernel/syscalls/fanotify/fanotify13.c +0 -1
index c9cf10555..6d812cdd1 100644
@@ -21,7 +21,6 @@
 #include <sys/statfs.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <fcntl.h>
 #include <errno.h>
 #include <unistd.h>
 #include "tst_test.h"
testcases/kernel/syscalls/fanotify/fanotify15.c +0 -1
index ba8259c7c..fe143823e 100644
@@ -19,7 +19,6 @@
 
 #include <string.h>
 #include <errno.h>
-#include <fcntl.h>
 #include <sys/statfs.h>
 #include <sys/types.h>
 #include "tst_test.h"
testcases/kernel/syscalls/fanotify/fanotify16.c +0 -1
index 5ffaec92f..c4b8a5abc 100644
@@ -18,7 +18,6 @@
 #include <stdio.h>
 #include <sys/stat.h>
 #include <sys/types.h>
-#include <fcntl.h>
 #include <errno.h>
 #include <string.h>
 #include <sys/mount.h>
testcases/kernel/syscalls/name_to_handle_at/name_to_handle_at01.c +0 -1
index 84ac32eab..1ac9d8214 100644
@@ -15,7 +15,6 @@
 \*/
 
 #define _GNU_SOURCE
-#include <fcntl.h>
 #include <sys/stat.h>
 #include "lapi/name_to_handle_at.h"
 
testcases/kernel/syscalls/name_to_handle_at/name_to_handle_at02.c +0 -1
index 7c0d57485..020b25531 100644
@@ -10,7 +10,6 @@
 \*/
 
 #define _GNU_SOURCE
-#include <fcntl.h>
 #include "lapi/name_to_handle_at.h"
 
 #define TEST_FILE "test_file"
testcases/kernel/syscalls/open_by_handle_at/open_by_handle_at01.c +0 -1
index c1b08f1b8..0d09e1ed8 100644
@@ -15,7 +15,6 @@
 \*/
 
 #define _GNU_SOURCE
-#include <fcntl.h>
 #include <sys/stat.h>
 #include "lapi/name_to_handle_at.h"
 
testcases/kernel/syscalls/open_by_handle_at/open_by_handle_at02.c +0 -1
index 3c8f06d85..0f60752c4 100644
@@ -10,7 +10,6 @@
 \*/
 #define _GNU_SOURCE
 #include <linux/capability.h>
-#include <fcntl.h>
 #include "tst_capability.h"
 #include "lapi/name_to_handle_at.h"
 
Signature · 1 line
2.29.2
#4 lore raw

cover Build fix undefined struct file_handle

In reply to Petr Vorel

Hi Petr
I think detecting file_handle struct(it is in fcntl.h) in configure.ac is correct instead of using HAVE_NAME_TO_HANDLE_AT macro directly.

Best Regards
Yang Xu

Quoted 25 lines

Hi all,

this would be great to get merged before release.

Kind regards,
Petr

Petr Vorel (3):
lapi: Move struct file_handle into lapi/fcntl.h
fanotify: Fix build on undefined struct file_handle
syscalls: Remove unused include<fcntl.h>

  include/lapi/fcntl.h                                   | 10 ++++++++++
  include/lapi/name_to_handle_at.h                       |  9 +--------
  testcases/kernel/syscalls/fanotify/fanotify.h          |  2 +-
  testcases/kernel/syscalls/fanotify/fanotify09.c        |  1 -
  testcases/kernel/syscalls/fanotify/fanotify13.c        |  1 -
  testcases/kernel/syscalls/fanotify/fanotify15.c        |  1 -
  testcases/kernel/syscalls/fanotify/fanotify16.c        |  1 -
  .../syscalls/name_to_handle_at/name_to_handle_at01.c   |  1 -
  .../syscalls/name_to_handle_at/name_to_handle_at02.c   |  1 -
  .../syscalls/open_by_handle_at/open_by_handle_at01.c   |  1 -
  .../syscalls/open_by_handle_at/open_by_handle_at02.c   |  1 -
  11 files changed, 12 insertions(+), 17 deletions(-)
author
#5 lore raw

cover Build fix undefined struct file_handle

Hi Xu,

Quoted 3 lines

Hi Petr
I think detecting file_handle struct(it is in fcntl.h) in configure.ac is correct instead of using HAVE_NAME_TO_HANDLE_AT macro directly.

You're right, using AC_CHECK_TYPES([struct, ],,,[#include <fcntl.h>]) is probably safer. I'll send v2.

Kind regards,
Petr Vorel

Quoted 2 lines

Best Regards
Yang Xu