[lxc-devel] [PATCH] Reduce public API

Stéphane Graber stgraber at ubuntu.com
Mon Dec 2 19:17:37 UTC 2013


This removes all but the following headers from our includes:
 - attach_options.h
 - lxccontainer.h
 - version.h

This also removes the duplicate lxc_version function (lxc_get_version
has been preferred for a while).

lxclock.h is now considered private, the lxc_lock struct has therefore
been moved to lxccontainer.h (as it's a dependency of lxc_container) but
all other locking functions are now strictly internal.

As a result quite a lot of files needed addition of extra includes
previously inherited from lxclock.h.

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 src/lxc/Makefile.am        | 19 +------------------
 src/lxc/bdev.c             |  1 +
 src/lxc/lxc_config.c       |  1 +
 src/lxc/lxc_create.c       |  1 +
 src/lxc/lxc_snapshot.c     |  1 +
 src/lxc/lxccontainer.c     |  3 ++-
 src/lxc/lxccontainer.h     | 21 ++++++++++++++++++---
 src/lxc/lxclock.h          | 17 +----------------
 src/lxc/version.c          | 29 -----------------------------
 src/lxc/version.h.in       |  5 -----
 src/tests/attach.c         |  2 ++
 src/tests/cgpath.c         |  2 ++
 src/tests/concurrent.c     |  2 ++
 src/tests/console.c        |  2 ++
 src/tests/containertests.c |  1 +
 src/tests/get_item.c       |  1 +
 src/tests/list.c           |  1 +
 src/tests/lxcpath.c        |  1 +
 src/tests/snapshot.c       |  2 ++
 src/tests/startone.c       |  1 +
 20 files changed, 41 insertions(+), 72 deletions(-)
 delete mode 100644 src/lxc/version.c

diff --git a/src/lxc/Makefile.am b/src/lxc/Makefile.am
index bf93baa..5369700 100644
--- a/src/lxc/Makefile.am
+++ b/src/lxc/Makefile.am
@@ -1,23 +1,6 @@
 pkginclude_HEADERS = \
-		arguments.h \
-		attach.h \
 		attach_options.h \
-		bdev.h \
-		caps.h \
-		cgroup.h \
-		conf.h \
-		console.h \
-		error.h \
-		list.h \
-		log.h \
 		lxccontainer.h \
-		lxc.h \
-		lxclock.h \
-		monitor.h \
-		namespace.h \
-		start.h \
-		state.h \
-		utils.h \
 		version.h
 
 if IS_BIONIC
@@ -87,7 +70,7 @@ liblxc_so_SOURCES = \
 	lxcutmp.c lxcutmp.h \
 	lxclock.h lxclock.c \
 	lxccontainer.c lxccontainer.h \
-	version.c version.h \
+	version.h \
 	\
 	$(LSM_SOURCES)
 
diff --git a/src/lxc/bdev.c b/src/lxc/bdev.c
index 03fecfb..249815e 100644
--- a/src/lxc/bdev.c
+++ b/src/lxc/bdev.c
@@ -47,6 +47,7 @@
 #include "namespace.h"
 #include "parse.h"
 #include "utils.h"
+#include "lxclock.h"
 
 #ifndef BLKGETSIZE64
 #define BLKGETSIZE64 _IOR(0x12,114,size_t)
diff --git a/src/lxc/lxc_config.c b/src/lxc/lxc_config.c
index 21bde64..8a4114d 100644
--- a/src/lxc/lxc_config.c
+++ b/src/lxc/lxc_config.c
@@ -19,6 +19,7 @@
  */
 
 #include <stdio.h>
+#include <string.h>
 #include "config.h"
 #include <lxc/lxccontainer.h>
 
diff --git a/src/lxc/lxc_create.c b/src/lxc/lxc_create.c
index 754afbf..7399683 100644
--- a/src/lxc/lxc_create.c
+++ b/src/lxc/lxc_create.c
@@ -23,6 +23,7 @@
 #include <libgen.h>
 #include <unistd.h>
 #include <ctype.h>
+#include <fcntl.h>
 #include <sys/types.h>
 
 #include <lxc/lxc.h>
diff --git a/src/lxc/lxc_snapshot.c b/src/lxc/lxc_snapshot.c
index d80dd39..f80afe5 100644
--- a/src/lxc/lxc_snapshot.c
+++ b/src/lxc/lxc_snapshot.c
@@ -24,6 +24,7 @@
 #include <unistd.h>
 #include <ctype.h>
 #include <sys/types.h>
+#include <fcntl.h>
 
 #include <lxc/lxc.h>
 #include <lxc/log.h>
diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
index 50796ae..7f54f50 100644
--- a/src/lxc/lxccontainer.c
+++ b/src/lxc/lxccontainer.c
@@ -50,6 +50,7 @@
 #include <sched.h>
 #include <arpa/inet.h>
 #include <libgen.h>
+#include "lxclock.h"
 
 #if HAVE_IFADDRS_H
 #include <ifaddrs.h>
@@ -2107,7 +2108,7 @@ const char *lxc_get_default_zfs_root(void)
 
 const char *lxc_get_version(void)
 {
-	return lxc_version();
+	return LXC_VERSION;
 }
 
 static int copy_file(char *old, char *new)
diff --git a/src/lxc/lxccontainer.h b/src/lxc/lxccontainer.h
index d57aead..832440d 100644
--- a/src/lxc/lxccontainer.h
+++ b/src/lxc/lxccontainer.h
@@ -22,12 +22,11 @@
 
 #ifndef __LXC_CONTAINER_H
 #define __LXC_CONTAINER_H
-#include "lxclock.h"
 #include "attach_options.h"
-#include <stdlib.h>
 #include <malloc.h>
-
+#include <semaphore.h>
 #include <stdbool.h>
+#include <stdlib.h>
 
 #define LXC_CLONE_KEEPNAME        (1 << 0) /*!< Do not edit the rootfs to change the hostname */
 #define LXC_CLONE_COPYHOOKS       (1 << 1) /*!< Copy all hooks into the container directory */
@@ -42,6 +41,22 @@ struct bdev_specs;
 struct lxc_snapshot;
 
 /*!
+ * LXC Lock
+*/
+struct lxc_lock {
+	short type; //!< Lock type
+
+	union {
+		sem_t *sem; //!< Anonymous semaphore (LXC_LOCK_ANON_SEM)
+		/*! LXC_LOCK_FLOCK details */
+		struct {
+			int   fd; //!< fd on which a lock is held (if not -1)
+			char *fname; //!< Name of lock
+		} f;
+	} u; //!< Container for lock type elements
+};
+
+/*!
  * An LXC container.
  */
 struct lxc_container {
diff --git a/src/lxc/lxclock.h b/src/lxc/lxclock.h
index 820e819..456e6a3 100644
--- a/src/lxc/lxclock.h
+++ b/src/lxc/lxclock.h
@@ -29,28 +29,13 @@
 #include <semaphore.h>
 #include <string.h>
 #include <time.h>
+#include "lxccontainer.h"
 
 #define LXC_LOCK_ANON_SEM 1 /*!< Anonymous semaphore lock */
 #define LXC_LOCK_FLOCK    2 /*!< flock(2) lock */
 
 // private
 /*!
- * LXC Lock
-*/
-struct lxc_lock {
-	short type; //!< Lock type
-
-	union {
-		sem_t *sem; //!< Anonymous semaphore (LXC_LOCK_ANON_SEM)
-		/*! LXC_LOCK_FLOCK details */
-		struct {
-			int   fd; //!< fd on which a lock is held (if not -1)
-			char *fname; //!< Name of lock
-		} f;
-	} u; //!< Container for lock type elements
-};
-
-/*!
  * \brief Create a new (unlocked) lock.
  *
  * \param lxcpath lxcpath lock should relate to.
diff --git a/src/lxc/version.c b/src/lxc/version.c
deleted file mode 100644
index bfa34bd..0000000
--- a/src/lxc/version.c
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * lxc: linux Container library
- *
- * (C) Copyright IBM Corp. 2007, 2008
- *
- * Authors:
- * Daniel Lezcano <daniel.lezcano at free.fr>
- *
- * 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 "../config.h"
-
-const char *lxc_version(void)
-{
-	return PACKAGE_VERSION;
-}
diff --git a/src/lxc/version.h.in b/src/lxc/version.h.in
index 6867b6e..eb9f103 100644
--- a/src/lxc/version.h.in
+++ b/src/lxc/version.h.in
@@ -28,9 +28,4 @@
 #define LXC_VERSION_MICRO @LXC_VERSION_MICRO@
 #define LXC_VERSION "@LXC_VERSION@"
 
-/*
- * Returns the version number of the library
- */
-extern const char *lxc_version(void);
-
 #endif
diff --git a/src/tests/attach.c b/src/tests/attach.c
index 2f0cb08..54f899f 100644
--- a/src/tests/attach.c
+++ b/src/tests/attach.c
@@ -23,6 +23,8 @@
 #include <lxc/utils.h>
 #include <lxc/lsm/lsm.h>
 
+#include <string.h>
+#include <sys/stat.h>
 #include <errno.h>
 #include <unistd.h>
 
diff --git a/src/tests/cgpath.c b/src/tests/cgpath.c
index 1c14468..ef192c6 100644
--- a/src/tests/cgpath.c
+++ b/src/tests/cgpath.c
@@ -26,6 +26,8 @@
 #include <sys/wait.h>
 #include <stdlib.h>
 #include <errno.h>
+#include <string.h>
+#include <sys/stat.h>
 #include "../lxc/cgroup.h"
 #include "../lxc/lxc.h"
 #include "../lxc/commands.h"
diff --git a/src/tests/concurrent.c b/src/tests/concurrent.c
index 6ae2662..b9749df 100644
--- a/src/tests/concurrent.c
+++ b/src/tests/concurrent.c
@@ -20,6 +20,8 @@
 #include <stdio.h>
 #include <pthread.h>
 #include <unistd.h>
+#include <string.h>
+#include <fcntl.h>
 #define _GNU_SOURCE
 #include <getopt.h>
 
diff --git a/src/tests/console.c b/src/tests/console.c
index 558e279..351f47a 100644
--- a/src/tests/console.c
+++ b/src/tests/console.c
@@ -24,6 +24,8 @@
 #include <errno.h>
 #include <unistd.h>
 #include <stdio.h>
+#include <string.h>
+#include <sys/stat.h>
 
 #define TTYCNT      4
 #define TTYCNT_STR "4"
diff --git a/src/tests/containertests.c b/src/tests/containertests.c
index 8ec840f..e6f05af 100644
--- a/src/tests/containertests.c
+++ b/src/tests/containertests.c
@@ -25,6 +25,7 @@
 #include <sys/wait.h>
 #include <stdlib.h>
 #include <errno.h>
+#include <string.h>
 #include <lxc/state.h>
 
 #define MYNAME "lxctest1"
diff --git a/src/tests/get_item.c b/src/tests/get_item.c
index 9475130..10ab3d1 100644
--- a/src/tests/get_item.c
+++ b/src/tests/get_item.c
@@ -25,6 +25,7 @@
 #include <sys/wait.h>
 #include <stdlib.h>
 #include <errno.h>
+#include <string.h>
 #include <lxc/state.h>
 
 #define MYNAME "lxctest1"
diff --git a/src/tests/list.c b/src/tests/list.c
index 639f7d5..9559c23 100644
--- a/src/tests/list.c
+++ b/src/tests/list.c
@@ -19,6 +19,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <lxc/lxccontainer.h>
 
 static void test_list_func(const char *lxcpath, const char *type,
diff --git a/src/tests/lxcpath.c b/src/tests/lxcpath.c
index 0fa5b2d..6018990 100644
--- a/src/tests/lxcpath.c
+++ b/src/tests/lxcpath.c
@@ -24,6 +24,7 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <stdlib.h>
+#include <string.h>
 #include <errno.h>
 
 #define MYNAME "lxctest1"
diff --git a/src/tests/snapshot.c b/src/tests/snapshot.c
index 79805af..d9fed36 100644
--- a/src/tests/snapshot.c
+++ b/src/tests/snapshot.c
@@ -21,6 +21,8 @@
 #include <errno.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <string.h>
+#include <sys/stat.h>
 #include "../lxc/lxc.h"
 
 #define MYNAME "snapxxx1"
diff --git a/src/tests/startone.c b/src/tests/startone.c
index 31ef503..08587ea 100644
--- a/src/tests/startone.c
+++ b/src/tests/startone.c
@@ -24,6 +24,7 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <stdlib.h>
+#include <string.h>
 #include <errno.h>
 
 #define MYNAME "lxctest1"
-- 
1.8.4.4





More information about the lxc-devel mailing list