From: Christian Brauner Date: Thu, 8 Feb 2018 14:23:49 +0000 (+0100) Subject: tools/lxc_unshare: satisfy Android X-Git-Tag: lxc-3.0.0.beta1~36^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1323838283dd5859a5a6bec92088b210d270d4e5;p=thirdparty%2Flxc.git tools/lxc_unshare: satisfy Android Signed-off-by: Christian Brauner --- diff --git a/src/lxc/tools/lxc_unshare.c b/src/lxc/tools/lxc_unshare.c index 98143d662..54f0fd545 100644 --- a/src/lxc/tools/lxc_unshare.c +++ b/src/lxc/tools/lxc_unshare.c @@ -42,6 +42,23 @@ #include "arguments.h" #include "tool_utils.h" +/* Define sethostname() if missing from the C library also workaround some + * quirky with having this defined in multiple places. + */ +static inline int sethostname_including_android(const char *name, size_t len) +{ +#ifndef HAVE_SETHOSTNAME +#ifdef __NR_sethostname + return syscall(__NR_sethostname, name, len); +#else + errno = ENOSYS; + return -1; +#endif +#else + return sethostname(name, len); +#endif +} + struct my_iflist { char *mi_ifname; @@ -127,7 +144,7 @@ static int do_start(void *arg) lxc_setup_fs(); if ((flags & CLONE_NEWUTS) && want_hostname) - if (sethostname(want_hostname, strlen(want_hostname)) < 0) { + if (sethostname_including_android(want_hostname, strlen(want_hostname)) < 0) { fprintf(stderr, "failed to set hostname %s: %s\n", want_hostname, strerror(errno)); exit(EXIT_FAILURE); }