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

timerfd.h only includes a forward declaration of struct itimerspec #44

Open
jeremyhu opened this issue Jan 28, 2023 · 5 comments
Open

Comments

@jeremyhu
Copy link

Please define the struct in the header. Failure to do so results in build failures in clients such as Wayland:

../src/event-loop.c:261:20: error: variable has incomplete type 'struct itimerspec'
        struct itimerspec its;
                          ^
/opt/X11/include/libepoll-shim/sys/timerfd.h:17:8: note: forward declaration of 'struct itimerspec'
struct itimerspec;
       ^
../src/event-loop.c:272:20: error: variable has incomplete type 'struct itimerspec'
        struct itimerspec its;
                          ^
/opt/X11/include/libepoll-shim/sys/timerfd.h:17:8: note: forward declaration of 'struct itimerspec'
struct itimerspec;
       ^
2 errors generated.
@jeremyhu
Copy link
Author

jeremyhu commented Jan 28, 2023

Wayland does:

static int
set_timer(int timerfd, struct timespec deadline) {
        struct itimerspec its;

        its.it_interval.tv_sec = 0;
        its.it_interval.tv_nsec = 0;
        its.it_value = deadline;
        return timerfd_settime(timerfd, TFD_TIMER_ABSTIME, &its, NULL);
}

static int
clear_timer(int timerfd)
{
        struct itimerspec its;

        its.it_interval.tv_sec = 0;
        its.it_interval.tv_nsec = 0;
        its.it_value.tv_sec = 0;
        its.it_value.tv_nsec = 0;
        return timerfd_settime(timerfd, 0, &its, NULL);
}

@jiixyj
Copy link
Owner

jiixyj commented Jan 28, 2023

Thanks for the report! I had hoped to avoid defining that struct since it's either:

  • ...defined in POSIX's <time.h>
  • ...or might conflict with a possibly user provided definition when the OS is not POSIX compliant

But that would of course mean that every program using epoll-shim on an OS that doesn't provide itimerspec would have to shim that struct itself, which leads to much duplication.

On which OS did that build error happen? macOS?

A solution could be for epoll-shim to provide a <time.h> shim header on OS's that need it.

@jeremyhu
Copy link
Author

Yep, this is happening on macOS.

@jeremyhu
Copy link
Author

jeremyhu commented Feb 5, 2023

Note that macOS is POSIX compliant. It's one of the few OSs that actually is certified POSIX compliant.

struct itimerspec is part of a the RT POSIX extension and is not required for POSIX compliance.

@jiixyj
Copy link
Owner

jiixyj commented Feb 7, 2023

struct itimerspec is required for POSIX.1-2008 compliance: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/time.h.html

macOS seems to be stuck on POSIX.1-2001, which is a shame, really...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants