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-2.0.10~563 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=370f320c2593a8b76942b65035c7fb606740e7f0;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 9115f50e6..898c728ad 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -117,19 +117,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 b6b7f4ca5..fe743411b 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 94ca49f41..026599806 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)