From: David Gibson <david@gibson.dropbear.id.au>
To: passt-dev@passt.top, Stefano Brivio <sbrivio@redhat.com>
Cc: David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH 12/13] passt-repair: Run static checkers
Date: Tue, 21 Apr 2026 12:43:43 +1000 [thread overview]
Message-ID: <20260421024344.1379633-13-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20260421024344.1379633-1-david@gibson.dropbear.id.au>
Run the static checkers, cppcheck and clang-tidy on passt-repair as well
as on passt proper. This shows up handful of remaining minor warnings,
which we correct.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
Makefile | 6 ++++--
linux_dep.h | 2 +-
passt-repair.c | 49 +++++++++++++++++++++++++------------------------
3 files changed, 30 insertions(+), 27 deletions(-)
diff --git a/Makefile b/Makefile
index b8a3cf9e..d29f46d2 100644
--- a/Makefile
+++ b/Makefile
@@ -183,13 +183,14 @@ docs: README.md
CLANG_TIDY = clang-tidy
CLANG_TIDY_FLAGS = -DCLANG_TIDY_58992
-clang-tidy: passt.clang-tidy
+clang-tidy: passt.clang-tidy passt-repair.clang-tidy
.PHONY: %.clang-tidy
%.clang-tidy:
$(CLANG_TIDY) $(filter %.c,$^) -- $(BASE_CPPFLAGS) $(CPPFLAGS) $(CLANG_TIDY_FLAGS)
passt.clang-tidy: $(PASST_SRCS) $(PASST_HEADERS) seccomp.h
+passt-repair.clang-tidy: $(PASST_REPAIR_SRCS) $(PASST_REPAIR_HEADERS) seccomp_repair.h
CPPCHECK = cppcheck
CPPCHECK_FLAGS = --std=c11 --error-exitcode=1 --enable=all --force \
@@ -204,10 +205,11 @@ CPPCHECK_FLAGS = --std=c11 --error-exitcode=1 --enable=all --force \
--suppress=unusedStructMember \
-D CPPCHECK_6936
-cppcheck: passt.cppcheck
+cppcheck: passt.cppcheck passt-repair.cppcheck
.PHONY: %.cppcheck
%.cppcheck:
$(CPPCHECK) $(CPPCHECK_FLAGS) $(BASE_CPPFLAGS) $^
passt.cppcheck: $(PASST_SRCS) $(PASST_HEADERS) seccomp.h
+passt-repair.cppcheck: $(PASST_REPAIR_SRCS) $(PASST_REPAIR_HEADERS) seccomp_repair.h
diff --git a/linux_dep.h b/linux_dep.h
index 3f8184bd..fa539ce4 100644
--- a/linux_dep.h
+++ b/linux_dep.h
@@ -145,7 +145,7 @@ struct tcp_info_linux {
#endif
__attribute__ ((weak))
-/* cppcheck-suppress [funcArgNamesDifferent,unmatchedSuppression] */
+/* cppcheck-suppress [funcArgNamesDifferent,unusedFunction,unmatchedSuppression] */
int close_range(unsigned int first, unsigned int last, int flags) {
return syscall(SYS_close_range, first, last, flags);
}
diff --git a/passt-repair.c b/passt-repair.c
index d4c8ce9a..80a39086 100644
--- a/passt-repair.c
+++ b/passt-repair.c
@@ -46,6 +46,9 @@
#define REPAIR_EXT ".repair"
#define REPAIR_EXT_LEN strlen(REPAIR_EXT)
+/* FPRINTF() intentionally silences cert-err33-c clang-tidy warnings */
+#define FPRINTF(f, ...) (void)fprintf(f, __VA_ARGS__)
+
/**
* wait_for_socket() - Wait for a Unix socket to appear in a directory
* @a: Unix domain address to update with socket's path
@@ -66,33 +69,33 @@ static int wait_for_socket(struct sockaddr_un *a, const char *dir,
const struct inotify_event *ev = NULL;
bool found = false;
int fd, ret;
- ssize_t n;
if ((fd = inotify_init1(IN_CLOEXEC)) < 0) {
- fprintf(stderr, "inotify_init1: %i\n", errno);
+ FPRINTF(stderr, "inotify_init1: %i\n", errno);
_exit(1);
}
if (inotify_add_watch(fd, dir, IN_CREATE) < 0) {
- fprintf(stderr, "inotify_add_watch: %i\n", errno);
+ FPRINTF(stderr, "inotify_add_watch: %i\n", errno);
_exit(1);
}
do {
+ ssize_t n;
char *p;
n = read(fd, buf, sizeof(buf));
if (n < 0) {
- fprintf(stderr, "inotify read: %i\n", errno);
+ FPRINTF(stderr, "inotify read: %i\n", errno);
_exit(1);
}
- buf[n - 1] = '\0';
if (n < (ssize_t)sizeof(*ev)) {
- fprintf(stderr, "Short inotify read: %zi\n", n);
+ FPRINTF(stderr, "Short inotify read: %zi\n", n);
continue;
}
+ buf[n - 1] = '\0';
for (p = buf; p < buf + n; p += sizeof(*ev) + ev->len) {
ev = (const struct inotify_event *)p;
@@ -108,7 +111,7 @@ static int wait_for_socket(struct sockaddr_un *a, const char *dir,
} while (!found);
if (ev->len > NAME_MAX + 1 || ev->name[ev->len - 1] != '\0') {
- fprintf(stderr, "Invalid filename from inotify\n");
+ FPRINTF(stderr, "Invalid filename from inotify\n");
_exit(1);
}
@@ -116,7 +119,7 @@ static int wait_for_socket(struct sockaddr_un *a, const char *dir,
dir, ev->name);
if ((stat(a->sun_path, sb))) {
- fprintf(stderr, "Can't stat() %s: %i\n", a->sun_path, errno);
+ FPRINTF(stderr, "Can't stat() %s: %i\n", a->sun_path, errno);
_exit(1);
}
@@ -160,7 +163,7 @@ int main(int argc, char **argv)
prog.filter = filter_repair;
if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) ||
prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog)) {
- fprintf(stderr, "Failed to apply seccomp filter\n");
+ FPRINTF(stderr, "Failed to apply seccomp filter\n");
_exit(1);
}
@@ -173,17 +176,17 @@ int main(int argc, char **argv)
cmsg = CMSG_FIRSTHDR(&msg);
if (argc != 2) {
- fprintf(stderr, "Usage: %s PATH\n", argv[0]);
+ FPRINTF(stderr, "Usage: %s PATH\n", argv[0]);
_exit(2);
}
if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
- fprintf(stderr, "Failed to create AF_UNIX socket: %i\n", errno);
+ FPRINTF(stderr, "Failed to create AF_UNIX socket: %i\n", errno);
_exit(1);
}
if ((stat(argv[1], &sb))) {
- fprintf(stderr, "Can't stat() %s: %i\n", argv[1], errno);
+ FPRINTF(stderr, "Can't stat() %s: %i\n", argv[1], errno);
_exit(1);
}
@@ -195,12 +198,12 @@ int main(int argc, char **argv)
}
if (ret <= 0 || ret >= (int)sizeof(a.sun_path)) {
- fprintf(stderr, "Invalid socket path\n");
+ FPRINTF(stderr, "Invalid socket path\n");
_exit(2);
}
if ((sb.st_mode & S_IFMT) != S_IFSOCK) {
- fprintf(stderr, "%s is not a socket\n", a.sun_path);
+ FPRINTF(stderr, "%s is not a socket\n", a.sun_path);
_exit(2);
}
@@ -208,7 +211,7 @@ int main(int argc, char **argv)
if (inotify_dir && errno == ECONNREFUSED)
continue;
- fprintf(stderr, "Failed to connect to %s: %s\n", a.sun_path,
+ FPRINTF(stderr, "Failed to connect to %s: %s\n", a.sun_path,
strerror(errno));
_exit(1);
}
@@ -219,7 +222,7 @@ loop:
if (errno == ECONNRESET) {
ret = 0;
} else {
- fprintf(stderr, "Failed to read message: %i\n", errno);
+ FPRINTF(stderr, "Failed to read message: %i\n", errno);
_exit(1);
}
}
@@ -231,7 +234,7 @@ loop:
cmsg->cmsg_len < CMSG_LEN(sizeof(int)) ||
cmsg->cmsg_len > CMSG_LEN(sizeof(int) * SCM_MAX_FD) ||
cmsg->cmsg_type != SCM_RIGHTS) {
- fprintf(stderr, "No/bad ancillary data from peer\n");
+ FPRINTF(stderr, "No/bad ancillary data from peer\n");
_exit(1);
}
@@ -246,7 +249,7 @@ loop:
}
if (!n) {
cmsg_len = cmsg->cmsg_len; /* socklen_t is 'unsigned' on musl */
- fprintf(stderr, "Invalid ancillary data length %zu from peer\n",
+ FPRINTF(stderr, "Invalid ancillary data length %zu from peer\n",
cmsg_len);
_exit(1);
}
@@ -255,15 +258,15 @@ loop:
if (cmd != TCP_REPAIR_ON && cmd != TCP_REPAIR_OFF &&
cmd != TCP_REPAIR_OFF_NO_WP) {
- fprintf(stderr, "Unsupported command 0x%04x\n", cmd);
+ FPRINTF(stderr, "Unsupported command 0x%04x\n", cmd);
_exit(1);
}
- op = cmd;
+ op = (int)cmd;
for (i = 0; i < n; i++) {
if (setsockopt(fds[i], SOL_TCP, TCP_REPAIR, &op, sizeof(op))) {
- fprintf(stderr,
+ FPRINTF(stderr,
"Setting TCP_REPAIR to %i on socket %i: %s\n",
op, fds[i], strerror(errno));
_exit(1);
@@ -275,11 +278,9 @@ loop:
/* Confirm setting by echoing the command back */
if (send(s, &cmd, sizeof(cmd), 0) < 0) {
- fprintf(stderr, "Reply to %i: %s\n", op, strerror(errno));
+ FPRINTF(stderr, "Reply to %i: %s\n", op, strerror(errno));
_exit(1);
}
goto loop;
-
- return 0;
}
--
2.53.0
next prev parent reply other threads:[~2026-04-21 2:43 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-21 2:43 [PATCH 00/13] Improvements to static checker invocation David Gibson
2026-04-21 2:43 ` [PATCH 01/13] Makefile: Use make variables for static checker configuration David Gibson
2026-04-21 2:43 ` [PATCH 02/13] cppcheck: Split out essential defines into a BASE_CPPFLAGS variable David Gibson
2026-04-21 2:43 ` [PATCH 03/13] Makefile: Remove preprocessor flags from $(FLAGS) David Gibson
2026-04-21 2:43 ` [PATCH 04/13] Makefile: Remove non-standard $(FLAGS) variable David Gibson
2026-04-21 2:43 ` [PATCH 05/13] Makefile: Make conditional definition of $(BIN) clearer David Gibson
2026-04-21 2:43 ` [PATCH 06/13] Makefile: Use common binary compilation rule David Gibson
2026-04-21 2:43 ` [PATCH 07/13] Makefile: Remove unhelpful $(HEADERS) variable David Gibson
2026-04-21 2:43 ` [PATCH 08/13] Makefile: Add header dependencies for secondary binaries David Gibson
2026-04-21 2:43 ` [PATCH 09/13] Makefile: Split static checker targets David Gibson
2026-04-21 2:43 ` [PATCH 10/13] passt-repair: Split out inotify handling to its own function David Gibson
2026-04-21 2:43 ` [PATCH 11/13] passt-repair: Simplify construction of Unix path from inotify David Gibson
2026-04-21 2:43 ` David Gibson [this message]
2026-04-21 2:43 ` [PATCH 13/13] qrap: Run static checkers David Gibson
2026-04-21 3:03 ` [PATCH 00/13] Improvements to static checker invocation David Gibson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260421024344.1379633-13-david@gibson.dropbear.id.au \
--to=david@gibson.dropbear.id.au \
--cc=passt-dev@passt.top \
--cc=sbrivio@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
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 IMAP folder(s).