Skip to content

Commit

Permalink
tools/lxc_unshare: satisfy Android
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
  • Loading branch information
Christian Brauner committed Feb 8, 2018
1 parent c666871 commit 1323838
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/lxc/tools/lxc_unshare.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 1323838

Please sign in to comment.