Skip to content

Commit

Permalink
linux/time.h: glibc time.h header file compatibility fixes
Browse files Browse the repository at this point in the history
Fixes these userspace compile errors and warnings when glibc time.h
is included before linux/time.h:

linux/time.h:9:8: error: redefinition of ‘struct timespec’
linux/time.h:15:8: error: redefinition of ‘struct timeval’
linux/time.h:20:8: error: redefinition of ‘struct timezone’
linux/time.h:30:0: warning: "ITIMER_REAL" redefined
linux/time.h:31:0: warning: "ITIMER_VIRTUAL" redefined
linux/time.h:32:0: warning: "ITIMER_PROF" redefined
linux/time.h:34:8: error: redefinition of ‘struct itimerspec’
linux/time.h:39:8: error: redefinition of ‘struct itimerval’
linux/time.h:67:0: warning: "TIMER_ABSTIME" redefined

<linux/time.h> conflicts with glibc <time.h> is the root cause of several
compatibility problems in uapi headers.

Signed-off-by: Mikko Rapeli <mikko.rapeli@iki.fi>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Michael Kerrisk <mtk.manpages@gmail.com>
  • Loading branch information
mcfrisk committed Aug 6, 2017
1 parent a362bc8 commit f3952a2
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
37 changes: 37 additions & 0 deletions include/uapi/linux/libc-compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,41 @@

#endif /* defined(_NETROSE_ROSE_H) */

/* Coordinate with glibc time.h */
#if defined(_TIME_H)
#define __UAPI_DEF_TIMESPEC 0
#define __UAPI_DEF_TIMEVAL 0
#define __UAPI_DEF_ITIMERSPEC 0
#define __UAPI_DEF_TIMER_ABSTIME 0

#else /* defined(_TIME_H) */
#define __UAPI_DEF_TIMESPEC 1
#define __UAPI_DEF_TIMEVAL 1
#define __UAPI_DEF_ITIMERSPEC 1
#define __UAPI_DEF_TIMER_ABSTIME 1

#endif /* defined(_TIME_H) */

/* Definitions for sys/uio.h */
#if defined(_SYS_UIO_H)
#define __UAPI_DEF_IOVEC 0
#else /* defined(_SYS_UIO_H) */
#define __UAPI_DEF_IOVEC 1
#endif /* defined(_SYS_UIO_H) */

/* Definitions for sys/time.h */
#if defined(_SYS_TIME_H)
#define __UAPI_DEF_TIMEZONE 0
#define __UAPI_DEF_ITIMER_REAL_VIRTUAL_PROF 0
#define __UAPI_DEF_ITIMERVAL 0

#else /* defined(_SYS_TIME_H) */
#define __UAPI_DEF_TIMEZONE 1
#define __UAPI_DEF_ITIMER_REAL_VIRTUAL_PROF 1
#define __UAPI_DEF_ITIMERVAL 1

#endif /* defined(_SYS_TIME_H) */

/* Definitions for xattr.h */
#if defined(_SYS_XATTR_H)
#define __UAPI_DEF_XATTR 0
Expand Down Expand Up @@ -313,6 +341,15 @@
#define __UAPI_DEF_ROSE_CAUSE_STRUCT 1
#define __UAPI_DEF_ROSE_FACILITIES_STRUCT 1

/* Definitions for time.h */
#define __UAPI_DEF_TIMESPEC 1
#define __UAPI_DEF_TIMEVAL 1
#define __UAPI_DEF_TIMEZONE 1
#define __UAPI_DEF_ITIMER_REAL_VIRTUAL_PROF 1
#define __UAPI_DEF_ITIMERSPEC 1
#define __UAPI_DEF_ITIMERVAL 1
#define __UAPI_DEF_TIMER_ABSTIME 1

/* Definitions for uio.h */
#define __UAPI_DEF_IOVEC 1

Expand Down
18 changes: 16 additions & 2 deletions include/uapi/linux/time.h
Original file line number Diff line number Diff line change
@@ -1,45 +1,57 @@
#ifndef _UAPI_LINUX_TIME_H
#define _UAPI_LINUX_TIME_H

#include <linux/libc-compat.h>
#include <linux/types.h>


#ifndef _STRUCT_TIMESPEC
#define _STRUCT_TIMESPEC
#if __UAPI_DEF_TIMESPEC
struct timespec {
__kernel_time_t tv_sec; /* seconds */
long tv_nsec; /* nanoseconds */
};
#endif
#endif /* __UAPI_DEF_TIMESPEC */
#endif /* _STRUCT_TIMESPEC */

#if __UAPI_DEF_TIMEVAL
struct timeval {
__kernel_time_t tv_sec; /* seconds */
__kernel_suseconds_t tv_usec; /* microseconds */
};
#endif /* __UAPI_DEF_TIMEVAL */

#if __UAPI_DEF_TIMEZONE
struct timezone {
int tz_minuteswest; /* minutes west of Greenwich */
int tz_dsttime; /* type of dst correction */
};

#endif /* __UAPI_DEF_TIMEZONE */

/*
* Names of the interval timers, and structure
* defining a timer setting:
*/
#if __UAPI_DEF_ITIMER_REAL_VIRTUAL_PROF
#define ITIMER_REAL 0
#define ITIMER_VIRTUAL 1
#define ITIMER_PROF 2
#endif /* __UAPI_DEF_ITIMER_REAL_VIRTUAL_PROF */

#if __UAPI_DEF_ITIMERSPEC
struct itimerspec {
struct timespec it_interval; /* timer period */
struct timespec it_value; /* timer expiration */
};
#endif /* __UAPI_DEF_ITIMERSPEC */

#if __UAPI_DEF_ITIMERVAL
struct itimerval {
struct timeval it_interval; /* timer interval */
struct timeval it_value; /* current value */
};
#endif /* __UAPI_DEF_ITIMERVAL */

/*
* The IDs of the various system clocks (for POSIX.1b interval timers):
Expand Down Expand Up @@ -68,6 +80,8 @@ struct itimerval {
/*
* The various flags for setting POSIX.1b interval timers:
*/
#if __UAPI_DEF_TIMER_ABSTIME
#define TIMER_ABSTIME 0x01
#endif /* __UAPI_DEF_TIMER_ABSTIME */

#endif /* _UAPI_LINUX_TIME_H */

0 comments on commit f3952a2

Please sign in to comment.