]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Build lxcutmp.c without timerfd.h or utmpx.h
authorStéphane Graber <stgraber@ubuntu.com>
Fri, 11 Jan 2013 17:29:55 +0000 (12:29 -0500)
committerStéphane Graber <stgraber@ubuntu.com>
Fri, 11 Jan 2013 20:14:51 +0000 (15:14 -0500)
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 <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
src/lxc/lxcutmp.c
src/lxc/lxcutmp.h

index f32ed632dbe0d50f248549f09d65f10fe32a3816..d00567e59023f9f40e3a5ef98cd73bcc0bd8c040 100644 (file)
@@ -23,8 +23,6 @@
 
 #include "config.h"
 
-#ifdef HAVE_UTMPX_H
-
 #include <stdio.h>
 #include <unistd.h>
 #include <errno.h>
 #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"
 #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
index ad4a8ab38b5dda8c9858665265570f650297c6eb..3f51a0be39e557881cd895a1e5a0d34306e82ddd 100644 (file)
 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