Commit 6a44839f by Dwight Engen Committed by Serge Hallyn

consolidate missing C library functions into utils.h

This fixes the build of lxccontainer.c on systems that have __NR_setns but not HAVE_SETNS. Signed-off-by: 's avatarDwight Engen <dwight.engen@oracle.com> Signed-off-by: 's avatarSerge Hallyn <serge.hallyn@ubuntu.com>
parent ad5f1515
...@@ -46,42 +46,10 @@ ...@@ -46,42 +46,10 @@
#include "caps.h" #include "caps.h"
#include "config.h" #include "config.h"
#include "apparmor.h" #include "apparmor.h"
#include "utils.h"
lxc_log_define(lxc_attach, lxc); lxc_log_define(lxc_attach, lxc);
/* Define setns() if missing from the C library */
#ifndef HAVE_SETNS
static int setns(int fd, int nstype)
{
#ifdef __NR_setns
return syscall(__NR_setns, fd, nstype);
#else
errno = ENOSYS;
return -1;
#endif
}
#endif
/* Define unshare() if missing from the C library */
#ifndef HAVE_UNSHARE
static int unshare(int flags)
{
#ifdef __NR_unshare
return syscall(__NR_unshare, flags);
#else
errno = ENOSYS;
return -1;
#endif
}
#endif
/* Define getline() if missing from the C library */
#ifndef HAVE_GETLINE
#ifdef HAVE_FGETLN
#include <../include/getline.h>
#endif
#endif
struct lxc_proc_context_info *lxc_proc_get_context_info(pid_t pid) struct lxc_proc_context_info *lxc_proc_get_context_info(pid_t pid)
{ {
struct lxc_proc_context_info *info = calloc(1, sizeof(*info)); struct lxc_proc_context_info *info = calloc(1, sizeof(*info));
......
...@@ -44,23 +44,10 @@ ...@@ -44,23 +44,10 @@
#include "utils.h" #include "utils.h"
#include "namespace.h" #include "namespace.h"
#include "parse.h" #include "parse.h"
#include "utils.h"
lxc_log_define(bdev, lxc); lxc_log_define(bdev, lxc);
/* Define unshare() if missing from the C library */
/* this is also in attach.c and lxccontainer.c: commonize it in utils.c */
#ifndef HAVE_UNSHARE
static int unshare(int flags)
{
#ifdef __NR_unshare
return syscall(__NR_unshare, flags);
#else
errno = ENOSYS;
return -1;
#endif
}
#endif
static int do_rsync(const char *src, const char *dest) static int do_rsync(const char *src, const char *dest)
{ {
// call out to rsync // call out to rsync
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "version.h" #include "version.h"
#include "log.h" #include "log.h"
#include "bdev.h" #include "bdev.h"
#include "utils.h"
#include <lxc/utils.h> #include <lxc/utils.h>
#include <lxc/monitor.h> #include <lxc/monitor.h>
#include <sched.h> #include <sched.h>
...@@ -44,22 +45,6 @@ ...@@ -44,22 +45,6 @@
static pthread_mutex_t thread_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t thread_mutex = PTHREAD_MUTEX_INITIALIZER;
/* Define unshare() if missing from the C library */
/* this is also in attach.c and lxccontainer.c: commonize it in utils.c */
#ifndef HAVE_UNSHARE
static int unshare(int flags)
{
#ifdef __NR_unshare
return syscall(__NR_unshare, flags);
#else
errno = ENOSYS;
return -1;
#endif
}
#else
int unshare(int);
#endif
lxc_log_define(lxc_container, lxc); lxc_log_define(lxc_container, lxc);
/* LOCKING /* LOCKING
......
...@@ -30,15 +30,9 @@ ...@@ -30,15 +30,9 @@
#include "parse.h" #include "parse.h"
#include "config.h" #include "config.h"
#include "utils.h"
#include <lxc/log.h> #include <lxc/log.h>
/* Define getline() if missing from the C library */
#ifndef HAVE_GETLINE
#ifdef HAVE_FGETLN
#include <../include/getline.h>
#endif
#endif
/* Workaround for the broken signature of alphasort() in bionic. /* Workaround for the broken signature of alphasort() in bionic.
This was fixed upstream in 40e467ec668b59be25491bd44bf348a884d6a68d so the This was fixed upstream in 40e467ec668b59be25491bd44bf348a884d6a68d so the
workaround can probably be dropped with the next version of the Android NDK. workaround can probably be dropped with the next version of the Android NDK.
......
...@@ -23,7 +23,9 @@ ...@@ -23,7 +23,9 @@
#ifndef _utils_h #ifndef _utils_h
#define _utils_h #define _utils_h
#include <errno.h>
#include <sys/types.h> #include <sys/types.h>
#include "config.h"
extern int lxc_setup_fs(void); extern int lxc_setup_fs(void);
extern int get_u16(unsigned short *val, const char *arg, int base); extern int get_u16(unsigned short *val, const char *arg, int base);
...@@ -36,6 +38,41 @@ extern const char *default_lxc_path(void); ...@@ -36,6 +38,41 @@ extern const char *default_lxc_path(void);
extern const char *default_zfs_root(void); extern const char *default_zfs_root(void);
extern const char *default_lvm_vg(void); extern const char *default_lvm_vg(void);
/* Define getline() if missing from the C library */
#ifndef HAVE_GETLINE
#ifdef HAVE_FGETLN
#include <../include/getline.h>
#endif
#endif
/* Define setns() if missing from the C library */
#ifndef HAVE_SETNS
static inline int setns(int fd, int nstype)
{
#ifdef __NR_setns
return syscall(__NR_setns, fd, nstype);
#else
errno = ENOSYS;
return -1;
#endif
}
#endif
/* Define unshare() if missing from the C library */
#ifndef HAVE_UNSHARE
static inline int unshare(int flags)
{
#ifdef __NR_unshare
return syscall(__NR_unshare, flags);
#else
errno = ENOSYS;
return -1;
#endif
}
#else
int unshare(int);
#endif
/** /**
* BUILD_BUG_ON - break compile if a condition is true. * BUILD_BUG_ON - break compile if a condition is true.
* @condition: the condition which the compiler should know is false. * @condition: the condition which the compiler should know is false.
......
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