patches and low-level development discussion
 help / color / mirror / code / Atom feed
* [PATCH ucspi-vsock] Set up clang-format
@ 2021-03-21 19:39 Alyssa Ross
  2021-03-22  0:15 ` Cole Helbling
  0 siblings, 1 reply; 3+ messages in thread
From: Alyssa Ross @ 2021-03-21 19:39 UTC (permalink / raw)
  To: devel

---
I'm not entirely happy with the automatic formatting, but I think it's
worth it.

 .clang-format              | 10 ++++++++++
 num.c                      |  2 +-
 vsock.c                    |  4 ++--
 vsockclient.c              |  5 +++--
 vsockserver-socketbinder.c |  8 ++++----
 vsockserver.c              | 27 +++++++++++++++------------
 vsockserverd.c             |  9 +++++----
 7 files changed, 40 insertions(+), 25 deletions(-)
 create mode 100644 .clang-format

diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..89313b0
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# SPDX-FileCopyrightText: 2021 Alyssa Ross <hi@alyssa.is>
+
+AlignOperands: DontAlign
+BreakBeforeBinaryOperators: All
+BreakBeforeBraces: Linux
+ContinuationIndentWidth: 8
+Cpp11BracedListStyle: false
+IndentWidth: 8
+UseTab: AlignWithSpaces
diff --git a/num.c b/num.c
index ac7f0a4..cef71ae 100644
--- a/num.c
+++ b/num.c
@@ -21,7 +21,7 @@ int getu32(const char *s, uint32_t min, uint32_t max, uint32_t *out)
 }
 
 int getul(const char *s, unsigned long min, unsigned long max,
-	  unsigned long *out)
+          unsigned long *out)
 {
 	char *endptr;
 
diff --git a/vsock.c b/vsock.c
index 6f1f466..ab8c4bd 100644
--- a/vsock.c
+++ b/vsock.c
@@ -18,8 +18,8 @@ static void fill_sockaddr(struct sockaddr_vm *addr, uint32_t cid, uint32_t port)
 	addr->svm_port = port;
 }
 
-static int fill_cid_and_port(const struct sockaddr_vm *addr,
-			     uint32_t *cid, uint32_t *port)
+static int fill_cid_and_port(const struct sockaddr_vm *addr, uint32_t *cid,
+                             uint32_t *port)
 {
 	// Check that this sockaddr info is actually for the socket
 	// type we think it is, or we could get some very confusing
diff --git a/vsockclient.c b/vsockclient.c
index fbdd20e..d6cc778 100644
--- a/vsockclient.c
+++ b/vsockclient.c
@@ -23,7 +23,7 @@ noreturn static void ex_usage(void)
 {
 	if (verbosity)
 		fprintf(stderr, "Usage: %s [ -q | -Q | -v ] cid port prog...\n",
-			program_invocation_short_name);
+		        program_invocation_short_name);
 	exit(EX_USAGE);
 }
 
@@ -63,7 +63,8 @@ int main(int argc, char *argv[])
 	// the same host with no backlog, so retry a few times.
 	{
 		int i = 0;
-		do fd = vsock_open(rcid, rport);
+		do
+			fd = vsock_open(rcid, rport);
 		while (i++ < 3 && fd == -1 && errno == ETIMEDOUT);
 	}
 	if (fd == -1)
diff --git a/vsockserver-socketbinder.c b/vsockserver-socketbinder.c
index fdcdfa8..97c5442 100644
--- a/vsockserver-socketbinder.c
+++ b/vsockserver-socketbinder.c
@@ -5,13 +5,13 @@
 
 #include <errno.h>
 #include <fcntl.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <stdint.h>
 #include <stdnoreturn.h>
 #include <string.h>
-#include <sysexits.h>
 #include <sys/socket.h>
+#include <sysexits.h>
 #include <unistd.h>
 
 #include <linux/vm_sockets.h>
@@ -26,7 +26,7 @@ noreturn static void ex_usage(void)
 {
 	if (verbosity)
 		fprintf(stderr, "Usage: %s cid port prog...\n",
-			program_invocation_short_name);
+		        program_invocation_short_name);
 	exit(EX_USAGE);
 }
 
@@ -54,7 +54,7 @@ int main(int argc, char *argv[])
 	// Parse the `cid' argument.
 	if (!strcmp(argv[optind], "-1"))
 		cid = VMADDR_CID_ANY;
-	else if (getu32(argv[optind], 0,  UINT32_MAX, &cid))
+	else if (getu32(argv[optind], 0, UINT32_MAX, &cid))
 		ex_usage();
 	optind++;
 
diff --git a/vsockserver.c b/vsockserver.c
index b717eee..e45c2ea 100644
--- a/vsockserver.c
+++ b/vsockserver.c
@@ -19,8 +19,9 @@
 noreturn static void ex_usage(void)
 {
 	if (verbosity)
-		fprintf(stderr, "Usage: %s [ -1 ] [ -q | -Q | -v ] cid port prog...\n",
-			program_invocation_short_name);
+		fprintf(stderr,
+		        "Usage: %s [ -1 ] [ -q | -Q | -v ] cid port prog...\n",
+		        program_invocation_short_name);
 	exit(EX_USAGE);
 }
 
@@ -40,9 +41,10 @@ int main(int argc, char *argv[])
 	// we've parsed the arguments, so we know what our verbosity
 	// setting is, and consequently whether we should print an
 	// error message about the allocation failure.
-	alloc_failed |=
-		argz_add(&binder_opts, &binder_opts_len, BINDIR "/vsockserver-socketbinder") ||
-		argz_add(&daemon_opts, &daemon_opts_len, BINDIR "/vsockserverd");
+	alloc_failed |= argz_add(&binder_opts, &binder_opts_len,
+	                         BINDIR "/vsockserver-socketbinder")
+		|| argz_add(&daemon_opts, &daemon_opts_len,
+	                    BINDIR "/vsockserverd");
 
 	while ((opt = getopt(argc, argv, "+1qQv")) != -1) {
 		char *arg = NULL;
@@ -53,9 +55,9 @@ int main(int argc, char *argv[])
 		case 'Q':
 		case 'v':
 			set_verbosity(opt);
-			alloc_failed |=
-				asprintf(&arg, "-%c", opt) == -1 ||
-				argz_add(&daemon_opts, &daemon_opts_len, arg);
+			alloc_failed |= asprintf(&arg, "-%c", opt) == -1
+				|| argz_add(&daemon_opts, &daemon_opts_len,
+			                    arg);
 			free(arg);
 			break;
 		default:
@@ -78,15 +80,16 @@ int main(int argc, char *argv[])
 		ex_usage();
 
 	// Add `cid' and `port' arguments to binder options.
-	if (argz_add(&binder_opts, &binder_opts_len, "--") ||
-	    argz_add(&binder_opts, &binder_opts_len, argv[optind++]) ||
-	    argz_add(&binder_opts, &binder_opts_len, argv[optind++]))
+	if (argz_add(&binder_opts, &binder_opts_len, "--")
+	    || argz_add(&binder_opts, &binder_opts_len, argv[optind++])
+	    || argz_add(&binder_opts, &binder_opts_len, argv[optind++]))
 		diee(EX_OSERR, "malloc");
 
 	// Add all of daemon_opts onto the end of binder_opts.  It's
 	// okay to multiply to find the size because if it would
 	// overflow calloc would have failed earlier.
-	if (argz_append(&binder_opts, &binder_opts_len, daemon_opts, daemon_opts_len))
+	if (argz_append(&binder_opts, &binder_opts_len, daemon_opts,
+	                daemon_opts_len))
 		diee(EX_OSERR, "malloc");
 	free(daemon_opts);
 
diff --git a/vsockserverd.c b/vsockserverd.c
index 1abfff9..a056bf1 100644
--- a/vsockserverd.c
+++ b/vsockserverd.c
@@ -23,7 +23,7 @@ noreturn static void ex_usage(void)
 {
 	if (verbosity)
 		fprintf(stderr, "Usage: %s [ -1 ] [ -q | -Q | -v ] prog...\n",
-			program_invocation_short_name);
+		        program_invocation_short_name);
 	exit(EX_USAGE);
 }
 
@@ -33,8 +33,8 @@ int main(int argc, char *argv[])
 	int opt;
 	pid_t child;
 	uint32_t lcid, lport, rcid, rport;
-	struct pollfd poll_fd =
-		{ .fd = STDIN_FILENO, .events = POLLIN, .revents = 0 };
+	struct pollfd poll_fd
+		= { .fd = STDIN_FILENO, .events = POLLIN, .revents = 0 };
 
 	while ((opt = getopt(argc, argv, "+1qQv")) != -1) {
 		switch (opt) {
@@ -93,7 +93,8 @@ int main(int argc, char *argv[])
 		ilog("connection from %" PRIu32 " port %" PRIu32, rcid, rport);
 
 		switch (child = fork()) {
-		case -1: diee(EX_OSERR, "fork");
+		case -1:
+			diee(EX_OSERR, "fork");
 		case 0:
 			// Set up the connection socket on prog's
 			// stdin and stdout.  This has the happy side
-- 
2.30.0

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH ucspi-vsock] Set up clang-format
  2021-03-21 19:39 [PATCH ucspi-vsock] Set up clang-format Alyssa Ross
@ 2021-03-22  0:15 ` Cole Helbling
  2021-03-22 12:16   ` Alyssa Ross
  0 siblings, 1 reply; 3+ messages in thread
From: Cole Helbling @ 2021-03-22  0:15 UTC (permalink / raw)
  To: Alyssa Ross, devel

On Sun Mar 21, 2021 at 12:39 PM PDT, Alyssa Ross wrote:
> ---
> I'm not entirely happy with the automatic formatting, but I think it's
> worth it.
>
>  .clang-format              | 10 ++++++++++
>  num.c                      |  2 +-
>  vsock.c                    |  4 ++--
>  vsockclient.c              |  5 +++--
>  vsockserver-socketbinder.c |  8 ++++----
>  vsockserver.c              | 27 +++++++++++++++------------
>  vsockserverd.c             |  9 +++++----
>  7 files changed, 40 insertions(+), 25 deletions(-)
>  create mode 100644 .clang-format

I wish every C / C++ repo used (something like) this, so I wouldn't have
to guess on the code style. Major +1.

Reviewed-by: Cole Helbling <cole.e.helbling@outlook.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH ucspi-vsock] Set up clang-format
  2021-03-22  0:15 ` Cole Helbling
@ 2021-03-22 12:16   ` Alyssa Ross
  0 siblings, 0 replies; 3+ messages in thread
From: Alyssa Ross @ 2021-03-22 12:16 UTC (permalink / raw)
  To: Cole Helbling; +Cc: devel

[-- Attachment #1: Type: text/plain, Size: 851 bytes --]

On Sun, Mar 21, 2021 at 05:15:19PM -0700, Cole Helbling wrote:
> On Sun Mar 21, 2021 at 12:39 PM PDT, Alyssa Ross wrote:
> > ---
> > I'm not entirely happy with the automatic formatting, but I think it's
> > worth it.
> >
> >  .clang-format              | 10 ++++++++++
> >  num.c                      |  2 +-
> >  vsock.c                    |  4 ++--
> >  vsockclient.c              |  5 +++--
> >  vsockserver-socketbinder.c |  8 ++++----
> >  vsockserver.c              | 27 +++++++++++++++------------
> >  vsockserverd.c             |  9 +++++----
> >  7 files changed, 40 insertions(+), 25 deletions(-)
> >  create mode 100644 .clang-format
>
> I wish every C / C++ repo used (something like) this, so I wouldn't have
> to guess on the code style. Major +1.
>
> Reviewed-by: Cole Helbling <cole.e.helbling@outlook.com>

Committed as d9e8ea9. :)

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-03-22 12:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-21 19:39 [PATCH ucspi-vsock] Set up clang-format Alyssa Ross
2021-03-22  0:15 ` Cole Helbling
2021-03-22 12:16   ` Alyssa Ross

Code repositories for project(s) associated with this public inbox

	https://spectrum-os.org/git/crosvm
	https://spectrum-os.org/git/doc
	https://spectrum-os.org/git/mktuntap
	https://spectrum-os.org/git/nixpkgs
	https://spectrum-os.org/git/spectrum
	https://spectrum-os.org/git/ucspi-vsock
	https://spectrum-os.org/git/www

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).