[lxc-devel] [lxc/master] cmd: Fix up checkpatch warnings

tcharding on Github lxc-bot at linuxcontainers.org
Fri Aug 17 06:28:19 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 1186 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180817/664c7ab5/attachment.bin>
-------------- next part --------------
From e8fcdf3db293a7772390c4e289a03e04b9660237 Mon Sep 17 00:00:00 2001
From: "Tobin C. Harding" <me at tobin.cc>
Date: Fri, 17 Aug 2018 15:42:32 +1000
Subject: [PATCH 1/9] cmd: Use parenthesis around complex macro

checkpatch emits error:

    ERROR: Macros with complex values should be enclosed in parentheses

Safeguard macro by use of parenthesis.

Signed-off-by: Tobin C. Harding <me at tobin.cc>
---
 src/lxc/cmd/lxc_init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/lxc/cmd/lxc_init.c b/src/lxc/cmd/lxc_init.c
index 7f47cbddb..86577e245 100644
--- a/src/lxc/cmd/lxc_init.c
+++ b/src/lxc/cmd/lxc_init.c
@@ -47,7 +47,7 @@
 
 /* option keys for long only options */
 #define OPT_USAGE 0x1000
-#define OPT_VERSION OPT_USAGE - 1
+#define OPT_VERSION (OPT_USAGE - 1)
 
 #define QUOTE(macro) #macro
 #define QUOTEVAL(macro) QUOTE(macro)

From 2b360805d029058b99871dc6a5706231eee30236 Mon Sep 17 00:00:00 2001
From: "Tobin C. Harding" <me at tobin.cc>
Date: Fri, 17 Aug 2018 15:44:25 +1000
Subject: [PATCH 2/9] cmd: Use 'void' instead of empty parameter list

checkpatch warns because of function definitions using empty parameter
list.  We should define these functions with 'void' as the parameter.

Use 'void' instead of empty parameter list for function definitions.

Signed-off-by: Tobin C. Harding <me at tobin.cc>
---
 src/lxc/cmd/lxc_init.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/lxc/cmd/lxc_init.c b/src/lxc/cmd/lxc_init.c
index 86577e245..175c41a83 100644
--- a/src/lxc/cmd/lxc_init.c
+++ b/src/lxc/cmd/lxc_init.c
@@ -473,13 +473,13 @@ static void print_usage(const struct option longopts[])
 	exit(0);
 }
 
-static void print_version()
+static void print_version(void)
 {
 	printf("%s\n", LXC_VERSION);
 	exit(0);
 }
 
-static void print_help()
+static void print_help(void)
 {
 	fprintf(stderr, "\
 Usage: lxc-init --name=NAME -- COMMAND\n\

From 24d6fb8a271b604e6e4b98de79b1f9d80e5e8e28 Mon Sep 17 00:00:00 2001
From: "Tobin C. Harding" <me at tobin.cc>
Date: Fri, 17 Aug 2018 15:52:09 +1000
Subject: [PATCH 3/9] cmd: Do not use braces for single statement block

checkpatch emites warning:

    WARNING: braces {} are not necessary for single statement blocks

Do not use braces for single statement block.

Signed-off-by: Tobin C. Harding <me at tobin.cc>
---
 src/lxc/cmd/lxc_init.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/lxc/cmd/lxc_init.c b/src/lxc/cmd/lxc_init.c
index 175c41a83..fa813f354 100644
--- a/src/lxc/cmd/lxc_init.c
+++ b/src/lxc/cmd/lxc_init.c
@@ -550,9 +550,8 @@ static int arguments_parse(struct arguments *args, int argc,
 	args->argc = argc - optind;
 
 	/* If no lxcpath was given, use default */
-	if (!args->lxcpath) {
+	if (!args->lxcpath)
 		args->lxcpath = lxc_global_config_value("lxc.lxcpath");
-	}
 
 	/* Check the command options */
 	if (!args->name) {

From 32cf169fab6758812d31dcc218738a82dbfd9c76 Mon Sep 17 00:00:00 2001
From: "Tobin C. Harding" <me at tobin.cc>
Date: Fri, 17 Aug 2018 16:02:28 +1000
Subject: [PATCH 4/9] cmd: Fix whitespace issues

checkpatch warns about a bunch of whitespace issues.  Fix the
non-controversial ones.

Fix whitespace issues found by checkpatch.

Signed-off-by: Tobin C. Harding <me at tobin.cc>
---
 src/lxc/cmd/lxc_init.c     | 5 ++---
 src/lxc/cmd/lxc_monitord.c | 2 +-
 src/lxc/cmd/lxc_user_nic.c | 2 +-
 3 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/lxc/cmd/lxc_init.c b/src/lxc/cmd/lxc_init.c
index fa813f354..c845f6ae2 100644
--- a/src/lxc/cmd/lxc_init.c
+++ b/src/lxc/cmd/lxc_init.c
@@ -91,7 +91,7 @@ struct arguments {
 };
 
 static int arguments_parse(struct arguments *my_args, int argc,
-			       char *const argv[]);
+			   char *const argv[]);
 
 static struct arguments my_args = {
 	.options   = long_options,
@@ -500,11 +500,10 @@ Mandatory or optional arguments to long options are also mandatory or optional\n
 for any corresponding short options.\n\
 \n\
 See the lxc-init man page for further information.\n\n");
-
 }
 
 static int arguments_parse(struct arguments *args, int argc,
-			       char *const argv[])
+			   char *const argv[])
 {
 	while (true) {
 		int c;
diff --git a/src/lxc/cmd/lxc_monitord.c b/src/lxc/cmd/lxc_monitord.c
index 0b9d7fd01..4194bb638 100644
--- a/src/lxc/cmd/lxc_monitord.c
+++ b/src/lxc/cmd/lxc_monitord.c
@@ -89,7 +89,7 @@ static int lxc_monitord_fifo_create(struct lxc_monitor *mon)
 	if (ret < 0)
 		return ret;
 
-	ret = mknod(fifo_path, S_IFIFO|S_IRUSR|S_IWUSR, 0);
+	ret = mknod(fifo_path, S_IFIFO | S_IRUSR | S_IWUSR, 0);
 	if (ret < 0 && errno != EEXIST) {
 		SYSINFO("Failed to mknod monitor fifo %s", fifo_path);
 		return -1;
diff --git a/src/lxc/cmd/lxc_user_nic.c b/src/lxc/cmd/lxc_user_nic.c
index c5beb6c8d..3e0cce4ac 100644
--- a/src/lxc/cmd/lxc_user_nic.c
+++ b/src/lxc/cmd/lxc_user_nic.c
@@ -219,7 +219,7 @@ static char **get_groupnames(void)
 				usernic_error("%s", "Could not find matched group record\n");
 
 			usernic_error("Failed to get group name: %s(%u)\n",
-			      strerror(errno), group_ids[i]);
+				      strerror(errno), group_ids[i]);
 			free(buf);
 			free(group_ids);
 			free_groupnames(groupnames);

From 7f5700e6aaf8dc15dbf2efe2039eda17cfbe9708 Mon Sep 17 00:00:00 2001
From: "Tobin C. Harding" <me at tobin.cc>
Date: Fri, 17 Aug 2018 16:05:14 +1000
Subject: [PATCH 5/9] cmd: Use 'const' for static string constant.

checkpatch emits warning:

WARNING: static char array declaration should probably be static const char

Use 'const' for static string constant (array of chars).

Signed-off-by: Tobin C. Harding <me at tobin.cc>
---
 src/lxc/cmd/lxc_init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/lxc/cmd/lxc_init.c b/src/lxc/cmd/lxc_init.c
index c845f6ae2..c5e46a1cd 100644
--- a/src/lxc/cmd/lxc_init.c
+++ b/src/lxc/cmd/lxc_init.c
@@ -73,7 +73,7 @@ static struct option long_options[] = {
 	    { "lxcpath",     required_argument, 0, 'P'         },
 	    { 0,             0,                 0, 0           }
 	};
-static char short_options[] = "n:hqo:l:P:";
+static const char short_options[] = "n:hqo:l:P:";
 
 struct arguments {
 	const struct option *options;

From 1d9f2743b25eeb87d236ef9f935a6a3dcad189be Mon Sep 17 00:00:00 2001
From: "Tobin C. Harding" <me at tobin.cc>
Date: Fri, 17 Aug 2018 16:08:01 +1000
Subject: [PATCH 6/9] cmd: Remove unnecessary whitespace in string

checkpatch emits warning:

    WARNING: unnecessary whitespace before a quoted newline

Remove unnecessary whitespace before a quoted newline

Signed-off-by: Tobin C. Harding <me at tobin.cc>
---
 src/lxc/cmd/lxc_init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/lxc/cmd/lxc_init.c b/src/lxc/cmd/lxc_init.c
index c5e46a1cd..078bbe461 100644
--- a/src/lxc/cmd/lxc_init.c
+++ b/src/lxc/cmd/lxc_init.c
@@ -468,7 +468,7 @@ int main(int argc, char *argv[])
 static void print_usage(const struct option longopts[])
 
 {
-	fprintf(stderr, "Usage: lxc-init [-n|--name=NAME] [-h|--help] [--usage] [--version] \n\
+	fprintf(stderr, "Usage: lxc-init [-n|--name=NAME] [-h|--help] [--usage] [--version]\n\
 		[-q|--quiet] [-o|--logfile=LOGFILE] [-l|--logpriority=LOGPRIORITY] [-P|--lxcpath=LXCPATH]\n");
 	exit(0);
 }

From 75ca3dc6aa526c9b24dacb6107c7b1b43e756771 Mon Sep 17 00:00:00 2001
From: "Tobin C. Harding" <me at tobin.cc>
Date: Fri, 17 Aug 2018 16:13:29 +1000
Subject: [PATCH 7/9] cmd: Put trailing */ on a separate line

checkpatch emits warning:

    WARNING: Block comments use a trailing */ on a separate line

Put trailing */ on a separate line.

Signed-off-by: Tobin C. Harding <me at tobin.cc>
---
 src/lxc/cmd/lxc_user_nic.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/lxc/cmd/lxc_user_nic.c b/src/lxc/cmd/lxc_user_nic.c
index 3e0cce4ac..3f34142e3 100644
--- a/src/lxc/cmd/lxc_user_nic.c
+++ b/src/lxc/cmd/lxc_user_nic.c
@@ -512,7 +512,8 @@ static int instantiate_veth(char *veth1, char *veth2)
 
 	/* Changing the high byte of the mac address to 0xfe, the bridge
 	 * interface will always keep the host's mac address and not take the
-	 * mac address of a container. */
+	 * mac address of a container.
+	 */
 	ret = setup_private_host_hw_addr(veth1);
 	if (ret < 0)
 		usernic_error("Failed to change mac address of host interface "

From 2115d56671fb8574e9c513d3d0168d113a597394 Mon Sep 17 00:00:00 2001
From: "Tobin C. Harding" <me at tobin.cc>
Date: Fri, 17 Aug 2018 16:14:30 +1000
Subject: [PATCH 8/9] cmd: Remove typo'd semicolon

checkpatch emits warning:

    WARNING: Statements terminations use 1 semicolon

Remove typo'd semicolon.

Signed-off-by: Tobin C. Harding <me at tobin.cc>
---
 src/lxc/cmd/lxc_user_nic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/lxc/cmd/lxc_user_nic.c b/src/lxc/cmd/lxc_user_nic.c
index 3f34142e3..2f35d7a40 100644
--- a/src/lxc/cmd/lxc_user_nic.c
+++ b/src/lxc/cmd/lxc_user_nic.c
@@ -687,7 +687,7 @@ static bool cull_entries(int fd, char *name, char *net_type, char *net_link,
 static int count_entries(char *buf, off_t len, char *name, char *net_type, char *net_link)
 {
 	int count = 0;
-	bool owner = false;;
+	bool owner = false;
 	char *buf_end;
 
 	buf_end = &buf[len];

From 551865932ee6c5e70d310d56d89ddc5bee6b0348 Mon Sep 17 00:00:00 2001
From: "Tobin C. Harding" <me at tobin.cc>
Date: Fri, 17 Aug 2018 16:18:27 +1000
Subject: [PATCH 9/9] cmd: Do not use comparison to NULL

checkpatch emits two warnings of type:

    CHECK: Comparison to NULL could be written "!foo"

Prefer `(!foo)` instead of `(foo == NULL)`.

Do not use comparison to NULL, use !foo

Signed-off-by: Tobin C. Harding <me at tobin.cc>
---
 src/lxc/cmd/lxc_monitord.c | 2 +-
 src/lxc/cmd/lxc_user_nic.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/lxc/cmd/lxc_monitord.c b/src/lxc/cmd/lxc_monitord.c
index 4194bb638..e6cb77338 100644
--- a/src/lxc/cmd/lxc_monitord.c
+++ b/src/lxc/cmd/lxc_monitord.c
@@ -208,7 +208,7 @@ static int lxc_monitord_sock_accept(int fd, uint32_t events, void *data,
 
 		clientfds = realloc(mon->clientfds,
 				    (mon->clientfds_size + CLIENTFDS_CHUNK) * sizeof(mon->clientfds[0]));
-		if (clientfds == NULL) {
+		if (!clientfds) {
 			ERROR("Failed to realloc memory for %d client file descriptors",
 			      mon->clientfds_size + CLIENTFDS_CHUNK);
 			goto err1;
diff --git a/src/lxc/cmd/lxc_user_nic.c b/src/lxc/cmd/lxc_user_nic.c
index 2f35d7a40..09b158245 100644
--- a/src/lxc/cmd/lxc_user_nic.c
+++ b/src/lxc/cmd/lxc_user_nic.c
@@ -752,7 +752,7 @@ static char *get_nic_if_avail(int fd, struct alloted_s *names, int pid,
 		lxc_strmunmap(buf, sb.st_size);
 	}
 
-	if (owner == NULL)
+	if (!owner)
 		return NULL;
 
 	ret = snprintf(nicname, sizeof(nicname), "vethXXXXXX");


More information about the lxc-devel mailing list