---
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