[lxc-devel] [PATCH 2/3] Mark functions as static and arguments/arrays as const where possible

Andrey Mazo mazo at telum.ru
Tue Dec 24 17:08:13 UTC 2013


Mark most of functions that are used within only one file as static.
After 95ee490bbdb97ab2b4f1dfa63a0a26e0dd1c2f17 it's easy to prove they
are not in public API.
Several arrays and structs are also marked static.
This prevents them from being exported from liblxc.so

List of removed previously exported symbols:
bdevs
btrfs_ops
check_autodev
create_partial
dir_ops
dump_stacktrace
get_mapped_rootid
get_next_index
lock_mutex
loop_ops
lvm_ops
lxc_abort
lxcapi_clone
lxc_attach_drop_privs
lxc_attach_get_init_uidgi
lxc_attach_getpwshell
lxc_attach_remount_sys_pr
lxc_attach_set_environmen
lxc_attach_to_ns
lxc_clear_saved_nics
lxc_config_readline
lxc_devs
lxc_free_idmap
lxc_global_config_value
lxc_poll
lxc_proc_get_context_info
lxc_set_state
lxc_spawn
mk_devtmpfs
mount_check_fs
ongoing_create
overlayfs_destroy
overlayfs_ops
prepend_lxc_header
remove_partial
save_phys_nics
setup_pivot_root
signames
static_mutex
thread_mutex
unlock_mutex
unpriv_assign_nic
zfs_ops

Signed-off-by: Andrey Mazo <mazo at telum.ru>
---
 src/lxc/attach.c         | 16 ++++++++--------
 src/lxc/attach.h         | 11 -----------
 src/lxc/bdev.c           | 20 ++++++++++----------
 src/lxc/bdev.h           |  4 ++--
 src/lxc/commands.c       |  2 +-
 src/lxc/conf.c           | 25 ++++++++++++-------------
 src/lxc/conf.h           |  3 ---
 src/lxc/confile.c        |  6 +++---
 src/lxc/confile.h        |  1 -
 src/lxc/log.h            |  2 --
 src/lxc/lxc_autostart.c  |  6 +++---
 src/lxc/lxc_clone.c      |  2 +-
 src/lxc/lxc_config.c     |  6 +++---
 src/lxc/lxc_create.c     |  2 +-
 src/lxc/lxc_info.c       |  4 ++--
 src/lxc/lxc_init.c       |  2 +-
 src/lxc/lxc_snapshot.c   | 20 ++++++++++----------
 src/lxc/lxc_stop.c       |  2 +-
 src/lxc/lxc_unshare.c    |  2 +-
 src/lxc/lxc_user_nic.c   |  2 +-
 src/lxc/lxc_usernsexec.c |  2 +-
 src/lxc/lxccontainer.c   | 12 ++++++------
 src/lxc/lxclock.c        | 16 ++++++++--------
 src/lxc/namespace.c      |  4 ++--
 src/lxc/network.c        |  4 ++--
 src/lxc/parse.c          |  6 +++---
 src/lxc/parse.h          |  6 +++---
 src/lxc/start.c          | 10 +++++-----
 src/lxc/start.h          |  6 +-----
 src/lxc/state.c          |  2 +-
 src/lxc/utils.c          |  6 +++---
 src/lxc/utils.h          |  2 --
 32 files changed, 95 insertions(+), 119 deletions(-)

diff --git a/src/lxc/attach.c b/src/lxc/attach.c
index 6749617..b7551d9 100644
--- a/src/lxc/attach.c
+++ b/src/lxc/attach.c
@@ -62,7 +62,7 @@
 
 lxc_log_define(lxc_attach, lxc);
 
-struct lxc_proc_context_info *lxc_proc_get_context_info(pid_t pid)
+static struct lxc_proc_context_info *lxc_proc_get_context_info(pid_t pid)
 {
 	struct lxc_proc_context_info *info = calloc(1, sizeof(*info));
 	FILE *proc_file;
@@ -137,7 +137,7 @@ static void lxc_proc_put_context_info(struct lxc_proc_context_info *ctx)
 	free(ctx);
 }
 
-int lxc_attach_to_ns(pid_t pid, int which)
+static int lxc_attach_to_ns(pid_t pid, int which)
 {
 	char path[MAXPATHLEN];
 	/* according to <http://article.gmane.org/gmane.linux.kernel.containers.lxc.devel/1429>,
@@ -204,7 +204,7 @@ int lxc_attach_to_ns(pid_t pid, int which)
 	return 0;
 }
 
-int lxc_attach_remount_sys_proc()
+static int lxc_attach_remount_sys_proc(void)
 {
 	int ret;
 
@@ -247,7 +247,7 @@ int lxc_attach_remount_sys_proc()
 	return 0;
 }
 
-int lxc_attach_drop_privs(struct lxc_proc_context_info *ctx)
+static int lxc_attach_drop_privs(struct lxc_proc_context_info *ctx)
 {
 	int last_cap = lxc_caps_last_cap();
 	int cap;
@@ -265,7 +265,7 @@ int lxc_attach_drop_privs(struct lxc_proc_context_info *ctx)
 	return 0;
 }
 
-int lxc_attach_set_environment(enum lxc_attach_env_policy_t policy, char** extra_env, char** extra_keep)
+static int lxc_attach_set_environment(enum lxc_attach_env_policy_t policy, char** extra_env, char** extra_keep)
 {
 	if (policy == LXC_ATTACH_CLEAR_ENV) {
 		char **extra_keep_store = NULL;
@@ -373,7 +373,7 @@ int lxc_attach_set_environment(enum lxc_attach_env_policy_t policy, char** extra
 	return 0;
 }
 
-char *lxc_attach_getpwshell(uid_t uid)
+static char *lxc_attach_getpwshell(uid_t uid)
 {
 	/* local variables */
 	pid_t pid;
@@ -528,7 +528,7 @@ char *lxc_attach_getpwshell(uid_t uid)
 	}
 }
 
-void lxc_attach_get_init_uidgid(uid_t* init_uid, gid_t* init_gid)
+static void lxc_attach_get_init_uidgid(uid_t* init_uid, gid_t* init_gid)
 {
 	FILE *proc_file;
 	char proc_fn[MAXPATHLEN];
@@ -857,7 +857,7 @@ int lxc_attach(const char* name, const char* lxcpath, lxc_attach_exec_t exec_fun
 	rexit(0);
 }
 
-int attach_child_main(void* data)
+static int attach_child_main(void* data)
 {
 	struct attach_clone_payload* payload = (struct attach_clone_payload*)data;
 	int ipc_socket = payload->ipc_socket;
diff --git a/src/lxc/attach.h b/src/lxc/attach.h
index b5f3ea1..260a609 100644
--- a/src/lxc/attach.h
+++ b/src/lxc/attach.h
@@ -33,17 +33,6 @@ struct lxc_proc_context_info {
 	unsigned long long capability_mask;
 };
 
-extern struct lxc_proc_context_info *lxc_proc_get_context_info(pid_t pid);
-
-extern int lxc_attach_to_ns(pid_t other_pid, int which);
-extern int lxc_attach_remount_sys_proc();
-extern int lxc_attach_drop_privs(struct lxc_proc_context_info *ctx);
-extern int lxc_attach_set_environment(enum lxc_attach_env_policy_t policy, char** extra_env, char** extra_keep);
-
-extern char *lxc_attach_getpwshell(uid_t uid);
-
-extern void lxc_attach_get_init_uidgid(uid_t* init_uid, gid_t* init_gid);
-
 extern int lxc_attach(const char* name, const char* lxcpath, lxc_attach_exec_t exec_function, void* exec_payload, lxc_attach_options_t* options, pid_t* attached_process);
 
 #endif
diff --git a/src/lxc/bdev.c b/src/lxc/bdev.c
index b737eff..bb73684 100644
--- a/src/lxc/bdev.c
+++ b/src/lxc/bdev.c
@@ -323,8 +323,8 @@ static int detect_fs(struct bdev *bdev, char *type, int len)
 }
 
 struct bdev_type {
-	char *name;
-	struct bdev_ops *ops;
+	const char *name;
+	const struct bdev_ops *ops;
 };
 
 static int is_dir(const char *path)
@@ -468,7 +468,7 @@ static int dir_create(struct bdev *bdev, const char *dest, const char *n,
 	return 0;
 }
 
-struct bdev_ops dir_ops = {
+static const struct bdev_ops dir_ops = {
 	.detect = &dir_detect,
 	.mount = &dir_mount,
 	.umount = &dir_umount,
@@ -725,7 +725,7 @@ static int zfs_create(struct bdev *bdev, const char *dest, const char *n,
 	exit(1);
 }
 
-struct bdev_ops zfs_ops = {
+static const struct bdev_ops zfs_ops = {
 	.detect = &zfs_detect,
 	.mount = &zfs_mount,
 	.umount = &zfs_umount,
@@ -1124,7 +1124,7 @@ static int lvm_create(struct bdev *bdev, const char *dest, const char *n,
 	return 0;
 }
 
-struct bdev_ops lvm_ops = {
+static const struct bdev_ops lvm_ops = {
 	.detect = &lvm_detect,
 	.mount = &lvm_mount,
 	.umount = &lvm_umount,
@@ -1421,7 +1421,7 @@ static int btrfs_create(struct bdev *bdev, const char *dest, const char *n,
 	return btrfs_subvolume_create(bdev->dest);
 }
 
-struct bdev_ops btrfs_ops = {
+static const struct bdev_ops btrfs_ops = {
 	.detect = &btrfs_detect,
 	.mount = &btrfs_mount,
 	.umount = &btrfs_umount,
@@ -1691,7 +1691,7 @@ static int loop_destroy(struct bdev *orig)
 	return unlink(orig->src + 5);
 }
 
-struct bdev_ops loop_ops = {
+static const struct bdev_ops loop_ops = {
 	.detect = &loop_detect,
 	.mount = &loop_mount,
 	.umount = &loop_umount,
@@ -1863,7 +1863,7 @@ static int overlayfs_clonepaths(struct bdev *orig, struct bdev *new, const char
 	return 0;
 }
 
-int overlayfs_destroy(struct bdev *orig)
+static int overlayfs_destroy(struct bdev *orig)
 {
 	char *upper;
 
@@ -1924,7 +1924,7 @@ static int overlayfs_create(struct bdev *bdev, const char *dest, const char *n,
 	return 0;
 }
 
-struct bdev_ops overlayfs_ops = {
+static const struct bdev_ops overlayfs_ops = {
 	.detect = &overlayfs_detect,
 	.mount = &overlayfs_mount,
 	.umount = &overlayfs_umount,
@@ -1933,7 +1933,7 @@ struct bdev_ops overlayfs_ops = {
 	.create = &overlayfs_create,
 };
 
-struct bdev_type bdevs[] = {
+static const struct bdev_type bdevs[] = {
 	{.name = "zfs", .ops = &zfs_ops,},
 	{.name = "lvm", .ops = &lvm_ops,},
 	{.name = "btrfs", .ops = &btrfs_ops,},
diff --git a/src/lxc/bdev.h b/src/lxc/bdev.h
index 8c17117..f4b3d29 100644
--- a/src/lxc/bdev.h
+++ b/src/lxc/bdev.h
@@ -72,8 +72,8 @@ struct bdev_ops {
  * data is so far unused.
  */
 struct bdev {
-	struct bdev_ops *ops;
-	char *type;
+	const struct bdev_ops *ops;
+	const char *type;
 	char *src;
 	char *dest;
 	char *data;
diff --git a/src/lxc/commands.c b/src/lxc/commands.c
index 19a416f..8a3c3f2 100644
--- a/src/lxc/commands.c
+++ b/src/lxc/commands.c
@@ -98,7 +98,7 @@ static int fill_sock_name(char *path, int len, const char *name,
 
 static const char *lxc_cmd_str(lxc_cmd_t cmd)
 {
-	static const char *cmdname[LXC_CMD_MAX] = {
+	static const char * const cmdname[LXC_CMD_MAX] = {
 		[LXC_CMD_CONSOLE]         = "console",
 		[LXC_CMD_STOP]            = "stop",
 		[LXC_CMD_GET_STATE]       = "get_state",
diff --git a/src/lxc/conf.c b/src/lxc/conf.c
index ed1056d..b7a6ae3 100644
--- a/src/lxc/conf.c
+++ b/src/lxc/conf.c
@@ -1111,7 +1111,7 @@ static uint64_t fnv_64a_buf(void *buf, size_t len, uint64_t hval)
 
 #define LINELEN 4096
 #define MAX_FSTYPE_LEN 128
-int mount_check_fs( const char *dir, char *fstype )
+static int mount_check_fs( const char *dir, char *fstype )
 {
 	char buf[LINELEN], *p;
 	struct stat s;
@@ -1175,7 +1175,7 @@ int mount_check_fs( const char *dir, char *fstype )
  * the devtmpfs subdirectory.
  */
 
-char *mk_devtmpfs(const char *name, char *path, const char *lxcpath)
+static char *mk_devtmpfs(const char *name, char *path, const char *lxcpath)
 {
 	int ret;
 	struct stat s;
@@ -1353,13 +1353,13 @@ static int mount_autodev(const char *name, char *root, const char *lxcpath)
 }
 
 struct lxc_devs {
-	char *name;
+	const char *name;
 	mode_t mode;
 	int maj;
 	int min;
 };
 
-struct lxc_devs lxc_devs[] = {
+static const struct lxc_devs lxc_devs[] = {
 	{ "null",	S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO, 1, 3	},
 	{ "zero",	S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO, 1, 5	},
 	{ "full",	S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO, 1, 7	},
@@ -1369,10 +1369,9 @@ struct lxc_devs lxc_devs[] = {
 	{ "console",	S_IFCHR | S_IRUSR | S_IWUSR,	       5, 1	},
 };
 
-static int setup_autodev(char *root)
+static int setup_autodev(const char *root)
 {
 	int ret;
-	struct lxc_devs *d;
 	char path[MAXPATHLEN];
 	int i;
 	mode_t cmask;
@@ -1388,7 +1387,7 @@ static int setup_autodev(char *root)
 	INFO("Populating /dev under %s\n", root);
 	cmask = umask(S_IXUSR | S_IXGRP | S_IXOTH);
 	for (i = 0; i < sizeof(lxc_devs) / sizeof(lxc_devs[0]); i++) {
-		d = &lxc_devs[i];
+		const struct lxc_devs *d = &lxc_devs[i];
 		ret = snprintf(path, MAXPATHLEN, "%s/dev/%s", root, d->name);
 		if (ret < 0 || ret >= MAXPATHLEN)
 			return -1;
@@ -1550,7 +1549,7 @@ static int setup_rootfs(struct lxc_conf *conf)
 	return 0;
 }
 
-int setup_pivot_root(const struct lxc_rootfs *rootfs)
+static int setup_pivot_root(const struct lxc_rootfs *rootfs)
 {
 	if (!rootfs->path)
 		return 0;
@@ -2980,7 +2979,7 @@ void lxc_delete_network(struct lxc_handler *handler)
 	}
 }
 
-int unpriv_assign_nic(struct lxc_netdev *netdev, pid_t pid)
+static int unpriv_assign_nic(struct lxc_netdev *netdev, pid_t pid)
 {
 	pid_t child;
 
@@ -3132,7 +3131,7 @@ int lxc_map_ids(struct lxc_list *idmap, pid_t pid)
  * return the host uid to which the container root is mapped, or -1 on
  * error
  */
-uid_t get_mapped_rootid(struct lxc_conf *conf)
+static uid_t get_mapped_rootid(struct lxc_conf *conf)
 {
 	struct lxc_list *it;
 	struct id_map *map;
@@ -3398,7 +3397,7 @@ struct start_args {
 
 #define MAX_SYMLINK_DEPTH 32
 
-int check_autodev( const char *rootfs, void *data )
+static int check_autodev( const char *rootfs, void *data )
 {
 	struct start_args *arg = data;
 	int ret;
@@ -3772,7 +3771,7 @@ int lxc_clear_config_caps(struct lxc_conf *c)
 	return 0;
 }
 
-int lxc_free_idmap(struct lxc_list *id_map) {
+static int lxc_free_idmap(struct lxc_list *id_map) {
 	struct lxc_list *it, *next;
 
 	lxc_list_for_each_safe(it, id_map, next) {
@@ -3874,7 +3873,7 @@ int lxc_clear_hooks(struct lxc_conf *c, const char *key)
 	return 0;
 }
 
-void lxc_clear_saved_nics(struct lxc_conf *conf)
+static void lxc_clear_saved_nics(struct lxc_conf *conf)
 {
 	int i;
 
diff --git a/src/lxc/conf.h b/src/lxc/conf.h
index ec76295..c983398 100644
--- a/src/lxc/conf.h
+++ b/src/lxc/conf.h
@@ -165,8 +165,6 @@ struct id_map {
 	unsigned long hostid, nsid, range;
 };
 
-extern int lxc_free_idmap(struct lxc_list *idmap);
-
 /*
  * Defines a structure containing a pty information for
  * virtualizing a tty
@@ -375,7 +373,6 @@ extern int lxc_setup(const char *name, struct lxc_conf *lxc_conf,
 
 extern void lxc_rename_phys_nics_on_shutdown(struct lxc_conf *conf);
 
-extern uid_t get_mapped_rootid(struct lxc_conf *conf);
 extern int find_unmapped_nsuid(struct lxc_conf *conf);
 extern int mapped_hostid(int id, struct lxc_conf *conf);
 extern int chown_mapped_root(char *path, struct lxc_conf *conf);
diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index c5ec4f3..b9911ed 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -152,10 +152,10 @@ static struct lxc_config_t config[] = {
 
 struct signame {
 	int num;
-	char *name;
+	const char *name;
 };
 
-struct signame signames[] = {
+static const struct signame signames[] = {
 	{ SIGHUP,    "HUP" },
 	{ SIGINT,    "INT" },
 	{ SIGQUIT,   "QUIT" },
@@ -1587,7 +1587,7 @@ out:
 	return ret;
 }
 
-int lxc_config_readline(char *buffer, struct lxc_conf *conf)
+static int lxc_config_readline(char *buffer, struct lxc_conf *conf)
 {
 	return parse_line(buffer, conf);
 }
diff --git a/src/lxc/confile.h b/src/lxc/confile.h
index eb7a8c2..a44ba96 100644
--- a/src/lxc/confile.h
+++ b/src/lxc/confile.h
@@ -40,7 +40,6 @@ extern struct lxc_config_t *lxc_getconfig(const char *key);
 extern int lxc_list_nicconfigs(struct lxc_conf *c, const char *key, char *retv, int inlen);
 extern int lxc_listconfigs(char *retv, int inlen);
 extern int lxc_config_read(const char *file, struct lxc_conf *conf);
-extern int lxc_config_readline(char *buffer, struct lxc_conf *conf);
 
 extern int lxc_config_define_add(struct lxc_list *defines, char* arg);
 extern int lxc_config_define_load(struct lxc_list *defines,
diff --git a/src/lxc/log.h b/src/lxc/log.h
index d3c40fb..4a42665 100644
--- a/src/lxc/log.h
+++ b/src/lxc/log.h
@@ -233,8 +233,6 @@ static inline void LXC_##PRIORITY(struct lxc_log_locinfo* locinfo,	\
 /*
  * top categories
  */
-extern struct lxc_log_category lxc_log_category_lxc;
-
 #define TRACE(format, ...) do {						\
 	struct lxc_log_locinfo locinfo = LXC_LOG_LOCINFO_INIT;		\
 	LXC_TRACE(&locinfo, format, ##__VA_ARGS__);			\
diff --git a/src/lxc/lxc_autostart.c b/src/lxc/lxc_autostart.c
index 1407a41..f6e6bfc 100644
--- a/src/lxc/lxc_autostart.c
+++ b/src/lxc/lxc_autostart.c
@@ -97,7 +97,7 @@ int lists_contain_common_entry(struct lxc_list *p1, struct lxc_list *p2) {
 	return 0;
 }
 
-struct lxc_list *get_list(char *input, char *delimiter) {
+static struct lxc_list *get_list(char *input, char *delimiter) {
 	char *workstr = NULL;
 	char *workptr = NULL;
 	char *sptr = NULL;
@@ -138,7 +138,7 @@ struct lxc_list *get_list(char *input, char *delimiter) {
 	return workstr_list;
 }
 
-struct lxc_list *get_config_list(struct lxc_container *c, char *key) {
+static struct lxc_list *get_config_list(struct lxc_container *c, char *key) {
 	int len = 0;
 	char* value = NULL;
 	struct lxc_list *config_list = NULL;
@@ -167,7 +167,7 @@ struct lxc_list *get_config_list(struct lxc_container *c, char *key) {
 	return config_list;
 }
 
-int get_config_integer(struct lxc_container *c, char *key) {
+static int get_config_integer(struct lxc_container *c, char *key) {
 	int len = 0;
 	int ret = 0;
 	char* value = NULL;
diff --git a/src/lxc/lxc_clone.c b/src/lxc/lxc_clone.c
index 7464dcd..71fc5c4 100644
--- a/src/lxc/lxc_clone.c
+++ b/src/lxc/lxc_clone.c
@@ -57,7 +57,7 @@ static unsigned long get_fssize(char *s)
        return ret;
 }
 
-void usage(const char *me)
+static void usage(const char *me)
 {
 	printf("Usage: %s [-s] [-B backingstore] [-L size] [-K] [-M] [-H]\n", me);
 	printf("          [-p lxcpath] [-P newlxcpath] orig new\n");
diff --git a/src/lxc/lxc_config.c b/src/lxc/lxc_config.c
index 8a4114d..c6436dc 100644
--- a/src/lxc/lxc_config.c
+++ b/src/lxc/lxc_config.c
@@ -28,7 +28,7 @@ struct lxc_config_items {
 	const char *(*fn)(void);
 };
 
-struct lxc_config_items items[] =
+static struct lxc_config_items items[] =
 {
 	{ .name = "lxcpath", .fn = &lxc_get_default_config_path, },
 	{ .name = "lvm_vg", .fn = &lxc_get_default_lvm_vg, },
@@ -37,14 +37,14 @@ struct lxc_config_items items[] =
 	{ .name = NULL, },
 };
 
-void usage(char *me)
+static void usage(char *me)
 {
 	printf("Usage: %s -l: list all available configuration items\n", me);
 	printf("       %s item: print configuration item\n", me);
 	exit(1);
 }
 
-void list_config_items(void)
+static void list_config_items(void)
 {
 	struct lxc_config_items *i;
 
diff --git a/src/lxc/lxc_create.c b/src/lxc/lxc_create.c
index 7399683..d5703d6 100644
--- a/src/lxc/lxc_create.c
+++ b/src/lxc/lxc_create.c
@@ -146,7 +146,7 @@ Options :\n\
 	.checker  = NULL,
 };
 
-bool validate_bdev_args(struct lxc_arguments *a)
+static bool validate_bdev_args(struct lxc_arguments *a)
 {
 	if (strcmp(a->bdevtype, "best") != 0) {
 		if (a->fstype || a->fssize) {
diff --git a/src/lxc/lxc_info.c b/src/lxc/lxc_info.c
index b344dca..22a0bb3 100644
--- a/src/lxc/lxc_info.c
+++ b/src/lxc/lxc_info.c
@@ -244,7 +244,7 @@ static void print_stats(struct lxc_container *c)
 	}
 }
 
-void print_info_msg_int(const char *key, int value)
+static void print_info_msg_int(const char *key, int value)
 {
 	if (humanize)
 		printf("%-15s %d\n", key, value);
@@ -256,7 +256,7 @@ void print_info_msg_int(const char *key, int value)
 	}
 }
 
-void print_info_msg_str(const char *key, const char *value)
+static void print_info_msg_str(const char *key, const char *value)
 {
 	if (humanize)
 		printf("%-15s %s\n", key, value);
diff --git a/src/lxc/lxc_init.c b/src/lxc/lxc_init.c
index 968c25d..d88a935 100644
--- a/src/lxc/lxc_init.c
+++ b/src/lxc/lxc_init.c
@@ -42,7 +42,7 @@ lxc_log_define(lxc_init, lxc);
 
 static int quiet;
 
-static struct option options[] = {
+static const struct option options[] = {
 	{ "name",        required_argument, NULL, 'n' },
 	{ "logpriority", required_argument, NULL, 'l' },
 	{ "quiet",       no_argument,       NULL, 'q' },
diff --git a/src/lxc/lxc_snapshot.c b/src/lxc/lxc_snapshot.c
index 1de5671..aebecf8 100644
--- a/src/lxc/lxc_snapshot.c
+++ b/src/lxc/lxc_snapshot.c
@@ -35,18 +35,18 @@
 
 lxc_log_define(lxc_snapshot, lxc);
 
-char *newname;
-char *snapshot;
+static char *newname;
+static char *snapshot;
 
 #define DO_SNAP 0
 #define DO_LIST 1
 #define DO_RESTORE 2
 #define DO_DESTROY 3
-int action;
-int print_comments;
-char *commentfile;
+static int action;
+static int print_comments;
+static char *commentfile;
 
-int do_snapshot(struct lxc_container *c)
+static int do_snapshot(struct lxc_container *c)
 {
 	int ret;
 
@@ -60,7 +60,7 @@ int do_snapshot(struct lxc_container *c)
 	return 0;
 }
 
-void print_file(char *path)
+static void print_file(char *path)
 {
 	if (!path)
 		return;
@@ -77,7 +77,7 @@ void print_file(char *path)
 	fclose(f);
 }
 
-int do_list_snapshots(struct lxc_container *c)
+static int do_list_snapshots(struct lxc_container *c)
 {
 	struct lxc_snapshot *s;
 	int i, n;
@@ -101,7 +101,7 @@ int do_list_snapshots(struct lxc_container *c)
 	return 0;
 }
 
-int do_restore_snapshots(struct lxc_container *c)
+static int do_restore_snapshots(struct lxc_container *c)
 {
 	if (c->snapshot_restore(c, snapshot, newname))
 		return 0;
@@ -110,7 +110,7 @@ int do_restore_snapshots(struct lxc_container *c)
 	return -1;
 }
 
-int do_destroy_snapshots(struct lxc_container *c)
+static int do_destroy_snapshots(struct lxc_container *c)
 {
 	if (c->snapshot_destroy(c, snapshot))
 		return 0;
diff --git a/src/lxc/lxc_stop.c b/src/lxc/lxc_stop.c
index 7940053..2e4baf2 100644
--- a/src/lxc/lxc_stop.c
+++ b/src/lxc/lxc_stop.c
@@ -80,7 +80,7 @@ Options :\n\
 };
 
 /* returns -1 on failure, 0 on success */
-int do_reboot_and_check(struct lxc_arguments *a, struct lxc_container *c)
+static int do_reboot_and_check(struct lxc_arguments *a, struct lxc_container *c)
 {
 	int ret;
 	pid_t pid;
diff --git a/src/lxc/lxc_unshare.c b/src/lxc/lxc_unshare.c
index 8ffdd21..827aa91 100644
--- a/src/lxc/lxc_unshare.c
+++ b/src/lxc/lxc_unshare.c
@@ -42,7 +42,7 @@
 
 lxc_log_define(lxc_unshare_ui, lxc);
 
-void usage(char *cmd)
+static void usage(char *cmd)
 {
 	fprintf(stderr, "%s <options> command [command_arguments]\n", basename(cmd));
 	fprintf(stderr, "Options are:\n");
diff --git a/src/lxc/lxc_user_nic.c b/src/lxc/lxc_user_nic.c
index 16f1495..117fc3e 100644
--- a/src/lxc/lxc_user_nic.c
+++ b/src/lxc/lxc_user_nic.c
@@ -49,7 +49,7 @@
 #include "utils.h"
 #include "network.h"
 
-void usage(char *me, bool fail)
+static void usage(char *me, bool fail)
 {
 	fprintf(stderr, "Usage: %s pid type bridge nicname\n", me);
 	fprintf(stderr, " nicname is the name to use inside the container\n");
diff --git a/src/lxc/lxc_usernsexec.c b/src/lxc/lxc_usernsexec.c
index e36ff34..0553ff9 100644
--- a/src/lxc/lxc_usernsexec.c
+++ b/src/lxc/lxc_usernsexec.c
@@ -126,7 +126,7 @@ struct id_map {
 	struct id_map *next;
 };
 
-struct id_map default_map = {
+static struct id_map default_map = {
 	.which = 'b',
 	.host_id = 100000,
 	.ns_id = 0,
diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
index e1d004f..0cc799a 100644
--- a/src/lxc/lxccontainer.c
+++ b/src/lxc/lxccontainer.c
@@ -97,7 +97,7 @@ static bool config_file_exists(const char *lxcpath, const char *cname)
  * we remove that file.  When we load or try to start a container, if
  * we find that file, without a flock, we remove the container.
  */
-int ongoing_create(struct lxc_container *c)
+static int ongoing_create(struct lxc_container *c)
 {
 	int len = strlen(c->config_path) + strlen(c->name) + 10;
 	char *path = alloca(len);
@@ -133,7 +133,7 @@ int ongoing_create(struct lxc_container *c)
 	return 2;
 }
 
-int create_partial(struct lxc_container *c)
+static int create_partial(struct lxc_container *c)
 {
 	// $lxcpath + '/' + $name + '/partial' + \0
 	int len = strlen(c->config_path) + strlen(c->name) + 10;
@@ -163,7 +163,7 @@ int create_partial(struct lxc_container *c)
 	return fd;
 }
 
-void remove_partial(struct lxc_container *c, int fd)
+static void remove_partial(struct lxc_container *c, int fd)
 {
 	// $lxcpath + '/' + $name + '/partial' + \0
 	int len = strlen(c->config_path) + strlen(c->name) + 10;
@@ -1035,7 +1035,7 @@ static bool create_run_template(struct lxc_container *c, char *tpath, bool quiet
 	return true;
 }
 
-bool prepend_lxc_header(char *path, const char *t, char *const argv[])
+static bool prepend_lxc_header(char *path, const char *t, char *const argv[])
 {
 	long flen;
 	char *contents;
@@ -2412,7 +2412,7 @@ static int create_file_dirname(char *path)
 	return ret;
 }
 
-struct lxc_container *lxcapi_clone(struct lxc_container *c, const char *newname,
+static struct lxc_container *lxcapi_clone(struct lxc_container *c, const char *newname,
 		const char *lxcpath, int flags,
 		const char *bdevtype, const char *bdevdata, unsigned long newsize,
 		char **hookargs)
@@ -2585,7 +2585,7 @@ static int lxcapi_attach_run_wait(struct lxc_container *c, lxc_attach_options_t
 	return lxc_wait_for_pid_status(pid);
 }
 
-int get_next_index(const char *lxcpath, char *cname)
+static int get_next_index(const char *lxcpath, char *cname)
 {
 	char *fname;
 	struct stat sb;
diff --git a/src/lxc/lxclock.c b/src/lxc/lxclock.c
index 28691b0..a5502b1 100644
--- a/src/lxc/lxclock.c
+++ b/src/lxc/lxclock.c
@@ -43,10 +43,10 @@
 lxc_log_define(lxc_lock, lxc);
 
 #ifdef MUTEX_DEBUGGING
-pthread_mutex_t thread_mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
-pthread_mutex_t static_mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
+static pthread_mutex_t thread_mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
+static pthread_mutex_t static_mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
 
-inline void dump_stacktrace(void)
+static inline void dump_stacktrace(void)
 {
 	void *array[MAX_STACKDEPTH];
 	size_t size;
@@ -65,13 +65,13 @@ inline void dump_stacktrace(void)
 	free (strings);
 }
 #else
-pthread_mutex_t thread_mutex = PTHREAD_MUTEX_INITIALIZER;
-pthread_mutex_t static_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t thread_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t static_mutex = PTHREAD_MUTEX_INITIALIZER;
 
-inline void dump_stacktrace(void) {;}
+static inline void dump_stacktrace(void) {;}
 #endif
 
-void lock_mutex(pthread_mutex_t *l)
+static void lock_mutex(pthread_mutex_t *l)
 {
 	int ret;
 
@@ -82,7 +82,7 @@ void lock_mutex(pthread_mutex_t *l)
 	}
 }
 
-void unlock_mutex(pthread_mutex_t *l)
+static void unlock_mutex(pthread_mutex_t *l)
 {
 	int ret;
 
diff --git a/src/lxc/namespace.c b/src/lxc/namespace.c
index a152c6b..31d4e72 100644
--- a/src/lxc/namespace.c
+++ b/src/lxc/namespace.c
@@ -69,11 +69,11 @@ pid_t lxc_clone(int (*fn)(void *), void *arg, int flags)
 	return ret;
 }
 
-static char *namespaces_list[] = {
+static const char * const namespaces_list[] = {
 	"MOUNT", "PID", "UTSNAME", "IPC",
 	"USER", "NETWORK"
 };
-static int cloneflags_list[] = {
+static const int cloneflags_list[] = {
 	CLONE_NEWNS, CLONE_NEWPID, CLONE_NEWUTS, CLONE_NEWIPC,
 	CLONE_NEWUSER, CLONE_NEWNET
 };
diff --git a/src/lxc/network.c b/src/lxc/network.c
index 361bb99..bd2a37c 100644
--- a/src/lxc/network.c
+++ b/src/lxc/network.c
@@ -1092,7 +1092,7 @@ int lxc_bridge_attach(const char *bridge, const char *ifname)
 	return err;
 }
 
-static char* lxc_network_types[LXC_NET_MAXCONFTYPE + 1] = {
+static const char* const lxc_network_types[LXC_NET_MAXCONFTYPE + 1] = {
 	[LXC_NET_VETH]    = "veth",
 	[LXC_NET_MACVLAN] = "macvlan",
 	[LXC_NET_VLAN]    = "vlan",
@@ -1107,7 +1107,7 @@ const char *lxc_net_type_to_str(int type)
 	return lxc_network_types[type];
 }
 
-static char padchar[] =
+static const char padchar[] =
 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
 
 char *lxc_mkifname(char *template)
diff --git a/src/lxc/parse.c b/src/lxc/parse.c
index c2cd621..6c85304 100644
--- a/src/lxc/parse.c
+++ b/src/lxc/parse.c
@@ -113,7 +113,7 @@ int lxc_file_for_each_line(const char *file, lxc_file_cb callback, void *data)
 	return err;
 }
 
-int lxc_char_left_gc(char *buffer, size_t len)
+int lxc_char_left_gc(const char *buffer, size_t len)
 {
 	int i;
 	for (i = 0; i < len; i++) {
@@ -125,7 +125,7 @@ int lxc_char_left_gc(char *buffer, size_t len)
 	return 0;
 }
 
-int lxc_char_right_gc(char *buffer, size_t len)
+int lxc_char_right_gc(const char *buffer, size_t len)
 {
 	int i;
 	for (i = len - 1; i >= 0; i--) {
@@ -139,7 +139,7 @@ int lxc_char_right_gc(char *buffer, size_t len)
 	return 0;
 }
 
-int lxc_is_line_empty(char *line)
+int lxc_is_line_empty(const char *line)
 {
 	int i;
 	size_t len = strlen(line);
diff --git a/src/lxc/parse.h b/src/lxc/parse.h
index e91bfd9..aead0da 100644
--- a/src/lxc/parse.h
+++ b/src/lxc/parse.h
@@ -34,10 +34,10 @@ extern int lxc_dir_for_each(const char *name, const char *directory,
 extern int lxc_file_for_each_line(const char *file, lxc_file_cb callback,
 				  void* data);
 
-extern int lxc_char_left_gc(char *buffer, size_t len);
+extern int lxc_char_left_gc(const char *buffer, size_t len);
 
-extern int lxc_char_right_gc(char *buffer, size_t len);
+extern int lxc_char_right_gc(const char *buffer, size_t len);
 
-extern int lxc_is_line_empty(char *line);
+extern int lxc_is_line_empty(const char *line);
 
 #endif
diff --git a/src/lxc/start.c b/src/lxc/start.c
index 7395aea..a5d6e56 100644
--- a/src/lxc/start.c
+++ b/src/lxc/start.c
@@ -277,14 +277,14 @@ static int signal_handler(int fd, uint32_t events, void *data,
 	return 1;
 }
 
-int lxc_set_state(const char *name, struct lxc_handler *handler, lxc_state_t state)
+static int lxc_set_state(const char *name, struct lxc_handler *handler, lxc_state_t state)
 {
 	handler->state = state;
 	lxc_monitor_send_state(name, state, handler->lxcpath);
 	return 0;
 }
 
-int lxc_poll(const char *name, struct lxc_handler *handler)
+static int lxc_poll(const char *name, struct lxc_handler *handler)
 {
 	int sigfd = handler->sigfd;
 	int pid = handler->pid;
@@ -464,7 +464,7 @@ static void lxc_fini(const char *name, struct lxc_handler *handler)
 	free(handler);
 }
 
-void lxc_abort(const char *name, struct lxc_handler *handler)
+static void lxc_abort(const char *name, struct lxc_handler *handler)
 {
 	int ret, status;
 
@@ -656,7 +656,7 @@ out_warn_father:
 	return -1;
 }
 
-int save_phys_nics(struct lxc_conf *conf)
+static int save_phys_nics(struct lxc_conf *conf)
 {
 	struct lxc_list *iterator;
 
@@ -686,7 +686,7 @@ int save_phys_nics(struct lxc_conf *conf)
 	return 0;
 }
 
-int lxc_spawn(struct lxc_handler *handler)
+static int lxc_spawn(struct lxc_handler *handler)
 {
 	int failed_before_rename = 0;
 	const char *name = handler->name;
diff --git a/src/lxc/start.h b/src/lxc/start.h
index c1f7909..e756236 100644
--- a/src/lxc/start.h
+++ b/src/lxc/start.h
@@ -55,7 +55,7 @@ struct ns_info {
 	int clone_flag;
 };
 
-const struct ns_info ns_info[LXC_NS_MAX];
+extern const struct ns_info ns_info[LXC_NS_MAX];
 
 struct lxc_handler {
 	pid_t pid;
@@ -74,11 +74,7 @@ struct lxc_handler {
 };
 
 extern struct lxc_handler *lxc_init(const char *name, struct lxc_conf *, const char *);
-extern int lxc_spawn(struct lxc_handler *);
 
-extern int lxc_poll(const char *name, struct lxc_handler *handler);
-extern void lxc_abort(const char *name, struct lxc_handler *handler);
-extern int lxc_set_state(const char *, struct lxc_handler *, lxc_state_t);
 extern int lxc_check_inherited(struct lxc_conf *conf, int fd_to_ignore);
 int __lxc_start(const char *, struct lxc_conf *, struct lxc_operations *,
 		void *, const char *);
diff --git a/src/lxc/state.c b/src/lxc/state.c
index 398833a..b42ea45 100644
--- a/src/lxc/state.c
+++ b/src/lxc/state.c
@@ -42,7 +42,7 @@
 
 lxc_log_define(lxc_state, lxc);
 
-static char *strstate[] = {
+static const char * const strstate[] = {
 	"STOPPED", "STARTING", "RUNNING", "STOPPING",
 	"ABORTING", "FREEZING", "FROZEN", "THAWED",
 };
diff --git a/src/lxc/utils.c b/src/lxc/utils.c
index 9f618e7..40cca57 100644
--- a/src/lxc/utils.c
+++ b/src/lxc/utils.c
@@ -238,9 +238,9 @@ static char *copy_global_config_value(char *p)
 #define DEFAULT_THIN_POOL "lxc"
 #define DEFAULT_ZFSROOT "lxc"
 
-const char *lxc_global_config_value(const char *option_name)
+static const char *lxc_global_config_value(const char *option_name)
 {
-	static const char *options[][2] = {
+	static const char * const options[][2] = {
 		{ "lvm_vg",          DEFAULT_VG      },
 		{ "lvm_thin_pool",   DEFAULT_THIN_POOL },
 		{ "zfsroot",         DEFAULT_ZFSROOT },
@@ -272,7 +272,7 @@ const char *lxc_global_config_value(const char *option_name)
 		user_lxc_path = strdup(LXCPATH);
 	}
 
-	const char *(*ptr)[2];
+	const char * const (*ptr)[2];
 	const char *value;
 	size_t i;
 	char buf[1024], *p, *p2;
diff --git a/src/lxc/utils.h b/src/lxc/utils.h
index 2992f90..86ebe3a 100644
--- a/src/lxc/utils.h
+++ b/src/lxc/utils.h
@@ -44,7 +44,6 @@ extern const char *get_rundir(void);
  * Return a buffer containing the default container path.
  * Caller must NOT free this buffer, since it may be static.
  */
-extern const char *lxc_global_config_value(const char *option_name);
 extern const char *default_lxc_path(void);
 extern const char *default_zfs_root(void);
 extern const char *default_lvm_vg(void);
@@ -267,5 +266,4 @@ extern void **lxc_dup_array(void **array, lxc_dup_fn element_dup_fn, lxc_free_fn
 
 extern void **lxc_append_null_to_array(void **array, size_t count);
 
-extern void dump_stacktrace(void);
 #endif
-- 
1.8.4.5



More information about the lxc-devel mailing list