[lxc-devel] [PATCH 13/21] Workaround missing functions in other libc
Serge Hallyn
serge.hallyn at canonical.com
Thu Jan 3 21:15:57 UTC 2013
Quoting Stéphane Graber (stgraber at ubuntu.com):
> Some libc implementation (bionic) is lacking some of the syscall functions
> that are present in the glibc.
>
> For those, detect at build time the they are missing and implement a minimal
> syscall() wrapper that will essentially give the same result as the glibc
> function.
>
> Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn at ubuntu.com>
> ---
> src/lxc/attach.c | 26 +++++++++++++++++++++-----
> src/lxc/conf.c | 30 ++++++++++++++++++++++++++++--
> 2 files changed, 49 insertions(+), 7 deletions(-)
>
> diff --git a/src/lxc/attach.c b/src/lxc/attach.c
> index 9adb8f9..103f223 100644
> --- a/src/lxc/attach.c
> +++ b/src/lxc/attach.c
> @@ -46,15 +46,31 @@
>
> lxc_log_define(lxc_attach, lxc);
>
> -int setns(int fd, int nstype)
> +/* Define setns() if missing from the C library */
> +#ifndef HAVE_SETNS
> +static int setns(int fd, int nstype)
> {
> -#ifndef __NR_setns
> - errno = ENOSYS;
> - return -1;
> +#ifdef __NR_setns
> +return syscall(__NR_setns, fd, nstype);
> #else
> - return syscall(__NR_setns, fd, nstype);
> +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
>
> struct lxc_proc_context_info *lxc_proc_get_context_info(pid_t pid)
> {
> diff --git a/src/lxc/conf.c b/src/lxc/conf.c
> index 2136feb..7963b00 100644
> --- a/src/lxc/conf.c
> +++ b/src/lxc/conf.c
> @@ -132,11 +132,37 @@ lxc_log_define(lxc_conf, lxc);
> #define LO_FLAGS_AUTOCLEAR 4
> #endif
>
> +/* Define pivot_root() if missing from the C library */
> +#ifndef HAVE_PIVOT_ROOT
> +static int pivot_root(const char * new_root, const char * put_old)
> +{
> +#ifdef __NR_pivot_root
> +return syscall(__NR_pivot_root, new_root, put_old);
> +#else
> +errno = ENOSYS;
> +return -1;
> +#endif
> +}
> +#else
> +extern int pivot_root(const char * new_root, const char * put_old);
> +#endif
> +
> +/* Define sethostname() if missing from the C library */
> +#ifndef HAVE_SETHOSTNAME
> +static int sethostname(const char * name, size_t len)
> +{
> +#ifdef __NR_sethostname
> +return syscall(__NR_sethostname, name, len);
> +#else
> +errno = ENOSYS;
> +return -1;
> +#endif
> +}
> +#endif
> +
> char *lxchook_names[NUM_LXC_HOOKS] = {
> "pre-start", "pre-mount", "mount", "start", "post-stop" };
>
> -extern int pivot_root(const char * new_root, const char * put_old);
> -
> typedef int (*instanciate_cb)(struct lxc_handler *, struct lxc_netdev *);
>
> struct mount_opt {
> --
> 1.8.0
>
>
> ------------------------------------------------------------------------------
> Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
> MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
> with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
> MVPs and experts. ON SALE this month only -- learn more at:
> http://p.sf.net/sfu/learnmore_122712
> _______________________________________________
> Lxc-devel mailing list
> Lxc-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/lxc-devel
More information about the lxc-devel
mailing list