From ac181b5c3cb8b243b1476919e5bf2142eb1082b7 Mon Sep 17 00:00:00 2001 From: Marcos Paulo de Souza Date: Mon, 27 Nov 2017 23:48:57 -0200 Subject: [PATCH] utils.h: Avoid duplicated sethostname implementation Move duplicated implementatin of sethostname from conf.c and lxc_unshare.c to utils.h Signed-off-by: Marcos Paulo de Souza --- src/lxc/conf.c | 13 ------------- src/lxc/tools/lxc_unshare.c | 14 -------------- src/lxc/utils.h | 13 +++++++++++++ 3 files changed, 13 insertions(+), 27 deletions(-) diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 2d2a3fca2..ae30b5b87 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -122,19 +122,6 @@ static int pivot_root(const char * new_root, const char * put_old) 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 - #ifndef MS_PRIVATE #define MS_PRIVATE (1<<18) #endif diff --git a/src/lxc/tools/lxc_unshare.c b/src/lxc/tools/lxc_unshare.c index 25af97119..1c790737b 100644 --- a/src/lxc/tools/lxc_unshare.c +++ b/src/lxc/tools/lxc_unshare.c @@ -32,7 +32,6 @@ #include #include #include -#include #include #include #include @@ -45,19 +44,6 @@ #include "network.h" #include "utils.h" -/* 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 - lxc_log_define(lxc_unshare_ui, lxc); struct my_iflist diff --git a/src/lxc/utils.h b/src/lxc/utils.h index 94646326f..5273203cf 100644 --- a/src/lxc/utils.h +++ b/src/lxc/utils.h @@ -120,6 +120,19 @@ static inline int setns(int fd, int nstype) } #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 + /* Define unshare() if missing from the C library */ #ifndef HAVE_UNSHARE static inline int unshare(int flags) -- 2.47.2