[lxc-devel] [lxc/master] Checkpatch

tcharding on Github lxc-bot at linuxcontainers.org
Thu Aug 16 07:12:07 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 821 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180816/321640f2/attachment.bin>
-------------- next part --------------
From 27fdb6bec5303a24e2f02693e7bd65dcf732ff6f Mon Sep 17 00:00:00 2001
From: "Tobin C. Harding" <me at tobin.cc>
Date: Thu, 16 Aug 2018 16:55:09 +1000
Subject: [PATCH 1/4] cmd: Correctly indent switch statement

checkpatch.pl emits error

    ERROR: do not use assignment in if condition

Correctly indent switch statement.

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

diff --git a/src/lxc/cmd/lxc_usernsexec.c b/src/lxc/cmd/lxc_usernsexec.c
index c342a90a0..07e6c9e41 100644
--- a/src/lxc/cmd/lxc_usernsexec.c
+++ b/src/lxc/cmd/lxc_usernsexec.c
@@ -333,18 +333,18 @@ int main(int argc, char *argv[])
 
 	while ((c = getopt(argc, argv, "m:h")) != EOF) {
 		switch (c) {
-			case 'm':
-				if (parse_map(optarg)) {
-					usage(argv[0]);
-					exit(EXIT_FAILURE);
-				}
-				break;
-			case 'h':
-				  usage(argv[0]);
-				  exit(EXIT_SUCCESS);
-			default:
-				  usage(argv[0]);
-				  exit(EXIT_FAILURE);
+		case 'm':
+			if (parse_map(optarg)) {
+				usage(argv[0]);
+				exit(EXIT_FAILURE);
+			}
+			break;
+		case 'h':
+			usage(argv[0]);
+			exit(EXIT_SUCCESS);
+		default:
+			usage(argv[0]);
+			exit(EXIT_FAILURE);
 		}
 	};
 

From 3c84faa377c3f9b1c7aab781b132f63d7ae40263 Mon Sep 17 00:00:00 2001
From: "Tobin C. Harding" <me at tobin.cc>
Date: Thu, 16 Aug 2018 16:57:36 +1000
Subject: [PATCH 2/4] cmd: Do not initialise statics to 0

checkpatch.pl emits error

    ERROR: do not initialise statics to 0

Do not initialise statics to 0.

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 651e9cb16..b800389d3 100644
--- a/src/lxc/cmd/lxc_init.c
+++ b/src/lxc/cmd/lxc_init.c
@@ -54,7 +54,7 @@
 
 lxc_log_define(lxc_init, lxc);
 
-static sig_atomic_t was_interrupted = 0;
+static sig_atomic_t was_interrupted;
 
 static void interrupt_handler(int sig)
 {

From 2db65c2187bd82f036034ded2cadaba92fbd9e1d Mon Sep 17 00:00:00 2001
From: "Tobin C. Harding" <me at tobin.cc>
Date: Thu, 16 Aug 2018 17:01:30 +1000
Subject: [PATCH 3/4] cmd: Fix whitespace ERRORS

checkpatch.pl emits a bunch of warnings about various whitespace
issues.  Fix all these as a single patch since they are all whitespace
only changes.

Fix whitespace issues found by checkpatch.pl

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

diff --git a/src/lxc/cmd/lxc_init.c b/src/lxc/cmd/lxc_init.c
index b800389d3..7f47cbddb 100644
--- a/src/lxc/cmd/lxc_init.c
+++ b/src/lxc/cmd/lxc_init.c
@@ -336,7 +336,7 @@ int main(int argc, char *argv[])
 			sigerr = signal(i, SIG_DFL);
 			if (sigerr == SIG_ERR) {
 				SYSDEBUG("Failed to reset to default action "
-				         "for signal \"%d\": %d", i, pid);
+					 "for signal \"%d\": %d", i, pid);
 			}
 		}
 
@@ -350,8 +350,8 @@ int main(int argc, char *argv[])
 		if (sid < 0)
 			DEBUG("Failed to make child session leader");
 
-                if (ioctl(STDIN_FILENO, TIOCSCTTY, 0) < 0)
-                        DEBUG("Failed to set controlling terminal");
+		if (ioctl(STDIN_FILENO, TIOCSCTTY, 0) < 0)
+			DEBUG("Failed to set controlling terminal");
 
 		NOTICE("Exec'ing \"%s\"", my_args.argv[0]);
 
@@ -556,7 +556,7 @@ static int arguments_parse(struct arguments *args, int argc,
 
 	/* Check the command options */
 	if (!args->name) {
-		if(!args->quiet)
+		if (!args->quiet)
 			fprintf(stderr, "lxc-init: missing container name, use --name option\n");
 		return -1;
 	}
diff --git a/src/lxc/cmd/lxc_monitord.c b/src/lxc/cmd/lxc_monitord.c
index 77be14def..0b9d7fd01 100644
--- a/src/lxc/cmd/lxc_monitord.c
+++ b/src/lxc/cmd/lxc_monitord.c
@@ -130,7 +130,8 @@ static int lxc_monitord_fifo_delete(struct lxc_monitor *mon)
 	return 0;
 }
 
-static void lxc_monitord_sockfd_remove(struct lxc_monitor *mon, int fd) {
+static void lxc_monitord_sockfd_remove(struct lxc_monitor *mon, int fd)
+{
 	int i;
 
 	if (lxc_mainloop_del_handler(&mon->descr, fd))
@@ -175,7 +176,7 @@ static int lxc_monitord_sock_handler(int fd, uint32_t events, void *data,
 static int lxc_monitord_sock_accept(int fd, uint32_t events, void *data,
 				    struct lxc_epoll_descr *descr)
 {
-	int ret,clientfd;
+	int ret, clientfd;
 	struct lxc_monitor *mon = data;
 	struct ucred cred;
 	socklen_t credsz = sizeof(cred);
@@ -301,7 +302,7 @@ static void lxc_monitord_delete(struct lxc_monitor *mon)
 static int lxc_monitord_fifo_handler(int fd, uint32_t events, void *data,
 				     struct lxc_epoll_descr *descr)
 {
-	int ret,i;
+	int ret, i;
 	struct lxc_msg msglxc;
 	struct lxc_monitor *mon = data;
 
@@ -315,7 +316,7 @@ static int lxc_monitord_fifo_handler(int fd, uint32_t events, void *data,
 		ret = lxc_write_nointr(mon->clientfds[i], &msglxc, sizeof(msglxc));
 		if (ret < 0)
 			SYSERROR("Failed to send message to client file descriptor %d",
-			         mon->clientfds[i]);
+				 mon->clientfds[i]);
 	}
 
 	return LXC_MAINLOOP_CONTINUE;
@@ -371,7 +372,7 @@ int main(int argc, char *argv[])
 	}
 
 	ret = snprintf(logpath, sizeof(logpath), "%s/lxc-monitord.log",
-		       (strcmp(LXCPATH, lxcpath) ? lxcpath : LOGPATH ));
+		       (strcmp(LXCPATH, lxcpath) ? lxcpath : LOGPATH));
 	if (ret < 0 || ret >= sizeof(logpath))
 		exit(EXIT_FAILURE);
 
diff --git a/src/lxc/cmd/lxc_usernsexec.c b/src/lxc/cmd/lxc_usernsexec.c
index 07e6c9e41..268ec9341 100644
--- a/src/lxc/cmd/lxc_usernsexec.c
+++ b/src/lxc/cmd/lxc_usernsexec.c
@@ -394,7 +394,7 @@ int main(int argc, char *argv[])
 
 		close(pipe_fds1[1]);
 		close(pipe_fds2[0]);
-		return do_child((void*)argv);
+		return do_child((void *)argv);
 	}
 
 	close(pipe_fds1[1]);

From f0a86c6d1c8288870a5e1c05cc12459ef356c3df Mon Sep 17 00:00:00 2001
From: "Tobin C. Harding" <me at tobin.cc>
Date: Thu, 16 Aug 2018 17:04:58 +1000
Subject: [PATCH 4/4] cmd: Move assignment out of if statement

checkpatch.pl emits error

    ERROR: do not use assignment in if condition

Move assignment out of if statement.

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

diff --git a/src/lxc/cmd/lxc_usernsexec.c b/src/lxc/cmd/lxc_usernsexec.c
index 268ec9341..69ba7a41e 100644
--- a/src/lxc/cmd/lxc_usernsexec.c
+++ b/src/lxc/cmd/lxc_usernsexec.c
@@ -364,9 +364,8 @@ int main(int argc, char *argv[])
 		perror("pipe");
 		exit(EXIT_FAILURE);
 	}
-	if ((pid = fork()) == 0) {
-		/* Child. */
-
+	pid = fork();
+	if (pid == 0) { /* Child. */
 		close(pipe_fds1[0]);
 		close(pipe_fds2[1]);
 		opentty(ttyname0, 0);
@@ -413,8 +412,8 @@ int main(int argc, char *argv[])
 		perror("write to pipe");
 		exit(EXIT_FAILURE);
 	}
-
-	if ((ret = waitpid(pid, &status, __WALL)) < 0) {
+	ret = waitpid(pid, &status, __WALL);
+	if (ret < 0) {
 		printf("waitpid() returns %d, errno %d\n", ret, errno);
 		exit(EXIT_FAILURE);
 	}


More information about the lxc-devel mailing list