We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 5395

Summary: implicit declaration of function ‘inotify_init1’
Product: SDL Reporter: Rene Dudfield <renesd>
Component: joystickAssignee: Ozkan Sezer <sezeroz>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: blocker    
Priority: P2 CC: sezeroz
Version: HG 2.0Keywords: target-2.0.14
Hardware: x86   
OS: Linux   

Description Rene Dudfield 2020-12-12 21:08:18 UTC
I'm getting a build error on a Centos5 machine. I know it's very old... but this is used as the base for compatible 'manylinux' builds in python land.


----

/sdl_build/SDL2-2.0.14/src/joystick/linux/SDL_sysjoystick.c: In function ‘LINUX_JoystickInit’:
/sdl_build/SDL2-2.0.14/src/joystick/linux/SDL_sysjoystick.c:702:9: warning: implicit declaration of function ‘inotify_init1’ [-Wimplicit-function-declaration]
         inotify_fd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
         ^
/sdl_build/SDL2-2.0.14/src/joystick/linux/SDL_sysjoystick.c:702:36: error: ‘IN_NONBLOCK’ undeclared (first use in this function)
         inotify_fd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
                                    ^
/sdl_build/SDL2-2.0.14/src/joystick/linux/SDL_sysjoystick.c:702:36: note: each undeclared identifier is reported only once for each function it appears in
/sdl_build/SDL2-2.0.14/src/joystick/linux/SDL_sysjoystick.c:702:50: error: ‘IN_CLOEXEC’ undeclared (first use in this function)
         inotify_fd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
                                                  ^
make: *** [build/SDL_sysjoystick.lo] Error 1
make: *** Waiting for unfinished jobs....
Comment 1 Ozkan Sezer 2020-12-12 21:21:31 UTC
inotify_init1 man page says: "inotify_init1() was added in
Linux 2.6.27; library support was added to glibc in version 2.9."
https://man7.org/linux/man-pages/man2/inotify_init1.2.html

I don't think anything can be done about CentOS5 (and I do
know and like compatible 'manylinux' builds.)  I can only
suggest moving to CentOS-6.10 (which just hit its EOL) on
which SDL2-2.0.14 builds just fine.

Sam, Ryan?
Comment 2 Ozkan Sezer 2020-12-12 22:05:47 UTC
(In reply to Ozkan Sezer from comment #1)
> I don't think anything can be done about CentOS5 (and I do
> know and like compatible 'manylinux' builds.)  I can only
> suggest moving to CentOS-6.10 (which just hit its EOL) on
> which SDL2-2.0.14 builds just fine.
> 
> Sam, Ryan?

Maybe something like the following though:

diff --git a/src/joystick/linux/SDL_sysjoystick.c b/src/joystick/linux/SDL_sysjoystick.c
--- a/src/joystick/linux/SDL_sysjoystick.c
+++ b/src/joystick/linux/SDL_sysjoystick.c
@@ -698,7 +698,7 @@ LINUX_JoystickInit(void)
     else
 #endif
     {
-#ifdef HAVE_INOTIFY_H
+#if defined(HAVE_INOTIFY_H) && defined(IN_NONBLOCK)
         inotify_fd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
 
         if (inotify_fd < 0) {


Or maybe adding a configury check for inotify_init1()?
Comment 3 Sam Lantinga 2020-12-13 03:19:53 UTC
Let's add a configure check for inotify_init1() and change the #define to HAVE_INOTIFY

Ozkan, you want to take that for release?
Comment 4 Ozkan Sezer 2020-12-13 12:33:33 UTC
(In reply to Sam Lantinga from comment #3)
> Let's add a configure check for inotify_init1() and change the #define
> to HAVE_INOTIFY
> 
> Ozkan, you want to take that for release?

I did that and a bit more by providing a fallback when inotify_init1()
isn't available:
https://hg.libsdl.org/SDL/rev/d08f9559922f

If all is good, we can close this.
Comment 5 Rene Dudfield 2020-12-13 13:28:53 UTC
It compiles now. Thanks!


However, I haven't been able to test it yet, because for some reason it's not building with threads support (I'll open a new bug for that).
Comment 6 Ozkan Sezer 2020-12-13 13:43:27 UTC
(In reply to Rene Dudfield from comment #5)
> It compiles now. Thanks!

And it does enable inotify (except for inotify_init1), yes?
If yes, feel free to close this.

> However, I haven't been able to test it yet, because for some reason
> it's not building with threads support (I'll open a new bug for that).

OK.
Comment 7 Ozkan Sezer 2020-12-13 15:01:20 UTC
This seems to have been fixed. Closing.