[lxc-devel] [lxc/master] lxc_helper.h: Avoid duplicated sethostname
marcosps on Github
lxc-bot at linuxcontainers.org
Tue Nov 28 01:51:55 UTC 2017
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 500 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20171128/ab938ea6/attachment.bin>
-------------- next part --------------
From 5eb15640b8234d425404b06ed9cceae568051906 Mon Sep 17 00:00:00 2001
From: Marcos Paulo de Souza <marcos.souza.org at gmail.com>
Date: Mon, 27 Nov 2017 23:48:57 -0200
Subject: [PATCH] lxc_helper.h: Avoid duplicated sethostname
Create new lxc_helper.h header to hold the implementation of
sethostname, instead of duplicating code in conf.c and lxc_unshare.c
Signed-off-by: Marcos Paulo de Souza <marcos.souza.org at gmail.com>
---
src/include/lxc_helper.h | 35 +++++++++++++++++++++++++++++++++++
src/lxc/conf.c | 15 +--------------
src/lxc/tools/lxc_unshare.c | 15 +--------------
3 files changed, 37 insertions(+), 28 deletions(-)
create mode 100644 src/include/lxc_helper.h
diff --git a/src/include/lxc_helper.h b/src/include/lxc_helper.h
new file mode 100644
index 000000000..18a627103
--- /dev/null
+++ b/src/include/lxc_helper.h
@@ -0,0 +1,35 @@
+/*
+ * lxc: linux Container library
+ *
+ * Authors:
+ * Marcos Paulo de Souza <marcos.souza.org at gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <sys/syscall.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
diff --git a/src/lxc/conf.c b/src/lxc/conf.c
index 2d2a3fca2..c027b69cf 100644
--- a/src/lxc/conf.c
+++ b/src/lxc/conf.c
@@ -48,10 +48,10 @@
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/sysmacros.h>
-#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/utsname.h>
#include <sys/wait.h>
+#include <../include/lxc_helper.h>
/* makedev() */
#ifdef MAJOR_IN_MKDEV
@@ -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..eda6c92ea 100644
--- a/src/lxc/tools/lxc_unshare.c
+++ b/src/lxc/tools/lxc_unshare.c
@@ -32,10 +32,10 @@
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
-#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
+#include <../include/lxc_helper.h>
#include "caps.h"
#include "cgroup.h"
@@ -45,19 +45,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
More information about the lxc-devel
mailing list