Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/sys/unix: mkerrors.sh fails on linux/pidfd.h #48221

Closed
lmb opened this issue Sep 7, 2021 · 2 comments
Closed

x/sys/unix: mkerrors.sh fails on linux/pidfd.h #48221

lmb opened this issue Sep 7, 2021 · 2 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@lmb
Copy link
Contributor

lmb commented Sep 7, 2021

What operating system and processor architecture are you using (go env)?

Linux on amd64

What did you do?

The following diff will make mkerrors.sh error out:

diff --git a/unix/mkerrors.sh b/unix/mkerrors.sh
index 0bcb8c3..e92d8d7 100755
--- a/unix/mkerrors.sh
+++ b/unix/mkerrors.sh
@@ -240,6 +240,7 @@ struct ltchars {
 #include <linux/nfc.h>
 #include <linux/nsfs.h>
 #include <linux/perf_event.h>
+#include <linux/pidfd.h>
 #include <linux/pps.h>
 #include <linux/ptrace.h>
 #include <linux/random.h>

Output:

----- GENERATING: 386 -----
configure: WARNING: minimum kernel version reset to 3.2.0
header files generated
zsysnum file generated
zsyscall file generated
ztypes file generated
In file included from /tmp/include/fcntl.h:35,
                 from /tmp/include/sys/file.h:24,
                 from /build/_const.go:180:
/tmp/include/bits/fcntl.h:35:8: error: redefinition of 'struct flock'
   35 | struct flock
      |        ^~~~~
In file included from /tmp/include/asm/fcntl.h:1,
                 from /tmp/include/linux/fcntl.h:5,
                 from /tmp/include/linux/pidfd.h:7,
                 from /build/_const.go:101:
/tmp/include/asm-generic/fcntl.h:196:8: note: originally defined here
  196 | struct flock {
      |        ^~~~~
In file included from /tmp/include/fcntl.h:35,
                 from /tmp/include/sys/file.h:24,
                 from /build/_const.go:180:
/tmp/include/bits/fcntl.h:50:8: error: redefinition of 'struct flock64'
   50 | struct flock64
      |        ^~~~~~~
In file included from /tmp/include/asm/fcntl.h:1,
                 from /tmp/include/linux/fcntl.h:5,
                 from /tmp/include/linux/pidfd.h:7,
                 from /build/_const.go:101:
/tmp/include/asm-generic/fcntl.h:211:8: note: originally defined here
  211 | struct flock64 {
      |        ^~~~~~~
/tmp/include/asm-generic/fcntl.h:152:21: error: expected identifier before numeric constant
  152 | #define F_OWNER_TID 0
      |                     ^
/tmp/include/bits/fcntl-linux.h:267:5: note: in expansion of macro 'F_OWNER_TID'
  267 |     F_OWNER_TID = 0,  /* Kernel thread.  */
      |     ^~~~~~~~~~~
In file included from /tmp/include/bits/fcntl.h:61,
                 from /tmp/include/fcntl.h:35,
                 from /tmp/include/sys/file.h:24,
                 from /build/_const.go:180:
/tmp/include/bits/fcntl-linux.h:274:8: error: redefinition of 'struct f_owner_ex'
  274 | struct f_owner_ex
      |        ^~~~~~~~~~
In file included from /tmp/include/asm/fcntl.h:1,
                 from /tmp/include/linux/fcntl.h:5,
                 from /tmp/include/linux/pidfd.h:7,
                 from /build/_const.go:101:
/tmp/include/asm-generic/fcntl.h:156:8: note: originally defined here
  156 | struct f_owner_ex {
      |        ^~~~~~~~~~
zerrors file generated
----- SUCCESS:    386 -----

<...>

There is source generated, but the diff is huge and it's not well formed Go.

@gopherbot gopherbot added this to the Unreleased milestone Sep 7, 2021
@tklauser
Copy link
Member

tklauser commented Sep 7, 2021

We occasionally run into this of problem when types (struct flock and struct flock64 in this case) are defined in both kernel headers and libc headers. The solution so far has usually been to add the respective include and definition to linux/type.go instead.

@thanm thanm added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 7, 2021
@ianlancetaylor
Copy link
Contributor

Resolved by just adding a definition to linux/type.go.

pevik pushed a commit to pevik/ltp that referenced this issue Feb 9, 2022
As pidfd_open man-page said
"PIDFD_NONBLOCK (since Linux 5.10)
Return a nonblocking file descriptor.  If the process referred to by
the file descriptor has not yet terminated, then an attempt to wait
on the file descriptor using waitid(2) will immediately  return
the error EAGAIN rather than blocking."

Test this and also test whether set NONBLOCK flag in its pidfd.

Noticed that, don't introduce lapi/pidfd.h because linux/pidfd.h uses
kernel header fcntl.h but ltp api uses libc header. so it may
exist redefinition error of 'struct flock'[1].

[1]golang/go#48221

Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
xuyang0410 added a commit to linux-test-project/ltp that referenced this issue Feb 11, 2022
As pidfd_open man-page said
"PIDFD_NONBLOCK (since Linux 5.10)
Return a nonblocking file descriptor.  If the process referred to by
the file descriptor has not yet terminated, then an attempt to wait
on the file descriptor using waitid(2) will immediately  return
the error EAGAIN rather than blocking."

Test this and also test whether set NONBLOCK flag in its pidfd.

Noticed that, don't introduce lapi/pidfd.h because linux/pidfd.h uses
kernel header fcntl.h but ltp api uses libc header. so it may
exist redefinition error of 'struct flock'[1].

[1]golang/go#48221

Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
@golang golang locked and limited conversation to collaborators Sep 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants