Commit e316c085 by Stéphane Graber

Build lxcutmp.c without timerfd.h or utmpx.h

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: 's avatarStéphane Graber <stgraber@ubuntu.com> Acked-by: 's avatarSerge E. Hallyn <serge.hallyn@ubuntu.com>
parent 565c2d76
...@@ -23,8 +23,6 @@ ...@@ -23,8 +23,6 @@
#include "config.h" #include "config.h"
#ifdef HAVE_UTMPX_H
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
...@@ -33,7 +31,30 @@ ...@@ -33,7 +31,30 @@
#include <fcntl.h> #include <fcntl.h>
#include <sys/inotify.h> #include <sys/inotify.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#ifdef HAVE_SYS_TIMERFD_h
#include <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 "conf.h"
#include "cgroup.h" #include "cgroup.h"
...@@ -45,7 +66,44 @@ ...@@ -45,7 +66,44 @@
#ifndef __USE_GNU #ifndef __USE_GNU
#define __USE_GNU #define __USE_GNU
#endif #endif
#ifdef HAVE_UTMPX_H
#include <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 #undef __USE_GNU
/* This file watches the /var/run/utmp file in the container /* This file watches the /var/run/utmp file in the container
...@@ -173,7 +231,11 @@ out: ...@@ -173,7 +231,11 @@ out:
static int utmp_get_runlevel(struct lxc_utmp *utmp_data) static int utmp_get_runlevel(struct lxc_utmp *utmp_data)
{ {
#if HAVE_UTMPX_H
struct utmpx *utmpx; struct utmpx *utmpx;
#else
struct utmp *utmpx;
#endif
char path[MAXPATHLEN]; char path[MAXPATHLEN];
struct lxc_handler *handler = utmp_data->handler; struct lxc_handler *handler = utmp_data->handler;
...@@ -417,5 +479,3 @@ int lxc_utmp_del_timer(struct lxc_epoll_descr *descr, ...@@ -417,5 +479,3 @@ int lxc_utmp_del_timer(struct lxc_epoll_descr *descr,
else else
return 0; return 0;
} }
#endif
...@@ -26,12 +26,5 @@ ...@@ -26,12 +26,5 @@
struct lxc_handler; struct lxc_handler;
struct lxc_epoll_descr; struct lxc_epoll_descr;
#ifdef HAVE_UTMPX_H
int lxc_utmp_mainloop_add(struct lxc_epoll_descr *descr, int lxc_utmp_mainloop_add(struct lxc_epoll_descr *descr,
struct lxc_handler *handler); struct lxc_handler *handler);
#else
static inline int lxc_utmp_mainloop_add(struct lxc_epoll_descr *descr,
struct lxc_handler *handler) {
return 0;
}
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment