This adds a local implementation of the bits we need form timerfd.h and utmpx.h so that the LXC utmp watch can be used with libc that don't implement the same functions as eglibc.
Signed-off-by: Stéphane Graber <stgra...@ubuntu.com> --- src/lxc/lxcutmp.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++---- src/lxc/lxcutmp.h | 7 ------ 2 files changed, 64 insertions(+), 11 deletions(-) diff --git a/src/lxc/lxcutmp.c b/src/lxc/lxcutmp.c index f32ed63..d00567e 100644 --- a/src/lxc/lxcutmp.c +++ b/src/lxc/lxcutmp.c @@ -23,8 +23,6 @@ #include "config.h" -#ifdef HAVE_UTMPX_H - #include <stdio.h> #include <unistd.h> #include <errno.h> @@ -33,7 +31,30 @@ #include <fcntl.h> #include <sys/inotify.h> #include <sys/ioctl.h> +#ifdef HAVE_SYS_TIMERFD_h #include <sys/timerfd.h> +#else +#include <sys/syscall.h> +#ifndef TFD_NONBLOCK +#define TFD_NONBLOCK O_NONBLOCK +#endif + +#ifndef TFD_CLOEXEC +#define TFD_CLOEXEC O_CLOEXEC +#endif +static int timerfd_create (clockid_t __clock_id, int __flags) { + return syscall(__NR_timerfd_create, __clock_id, __flags); +} + +static int timerfd_settime (int __ufd, int __flags, + const struct itimerspec *__utmr, + struct itimerspec *__otmr) { + + return syscall(__NR_timerfd_settime, __ufd, __flags, + __utmr, __otmr); +} + +#endif #include "conf.h" #include "cgroup.h" @@ -45,7 +66,44 @@ #ifndef __USE_GNU #define __USE_GNU #endif +#ifdef HAVE_UTMPX_H #include <utmpx.h> +#else +#include <utmp.h> + +#ifndef RUN_LVL +#define RUN_LVL 1 +#endif + +static int utmpxname(const char *file) { + int result; + result = utmpname(file); + +#ifdef IS_BIONIC + /* Yeah bionic is that weird */ + result = result - 1; +#endif + + return result; +} + +static void setutxent(void) { + return setutent(); +} + +static struct utmp * getutxent (void) { + return (struct utmp *) getutent(); +} + +static void endutxent (void) { +#ifdef IS_BIONIC + /* bionic isn't exporting endutend */ + return; +#else + return endutent(); +#endif +} +#endif #undef __USE_GNU /* This file watches the /var/run/utmp file in the container @@ -173,7 +231,11 @@ out: static int utmp_get_runlevel(struct lxc_utmp *utmp_data) { + #if HAVE_UTMPX_H struct utmpx *utmpx; + #else + struct utmp *utmpx; + #endif char path[MAXPATHLEN]; struct lxc_handler *handler = utmp_data->handler; @@ -417,5 +479,3 @@ int lxc_utmp_del_timer(struct lxc_epoll_descr *descr, else return 0; } - -#endif diff --git a/src/lxc/lxcutmp.h b/src/lxc/lxcutmp.h index ad4a8ab..3f51a0b 100644 --- a/src/lxc/lxcutmp.h +++ b/src/lxc/lxcutmp.h @@ -26,12 +26,5 @@ struct lxc_handler; struct lxc_epoll_descr; -#ifdef HAVE_UTMPX_H int lxc_utmp_mainloop_add(struct lxc_epoll_descr *descr, struct lxc_handler *handler); -#else -static inline int lxc_utmp_mainloop_add(struct lxc_epoll_descr *descr, - struct lxc_handler *handler) { - return 0; -} -#endif -- 1.8.0 ------------------------------------------------------------------------------ Master HTML5, CSS3, ASP.NET, MVC, AJAX, Knockout.js, Web API and much more. Get web development skills now with LearnDevNow - 350+ hours of step-by-step video tutorials by Microsoft MVPs and experts. SALE $99.99 this month only -- learn more at: http://p.sf.net/sfu/learnmore_122812 _______________________________________________ Lxc-devel mailing list Lxc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/lxc-devel