From: Marcos Paulo de Souza Date: Tue, 28 Nov 2017 01:48:57 +0000 (-0200) Subject: utils.h: Avoid duplicated sethostname implementation X-Git-Tag: lxc-3.0.0.beta1~167^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ac181b5c3cb8b243b1476919e5bf2142eb1082b7;p=thirdparty%2Flxc.git 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 --- 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)