1
0
Fork 0
mirror of https://passt.top/passt synced 2025-05-23 01:35:35 +02:00

treewide: Suppress clang-tidy warning if we already use O_CLOEXEC

In pcap_init(), we should always open the packet capture file with
O_CLOEXEC, even if we're not running in foreground: O_CLOEXEC means
close-on-exec, not close-on-fork.

In logfile_init() and pidfile_open(), the fact that we pass a third
'mode' argument to open() seems to confuse the android-cloexec-open
checker in LLVM versions from 16 to 19 (at least).

The checker is suggesting to add O_CLOEXEC to 'mode', and not in
'flags', where we already have it.

Add a suppression for clang-tidy and a comment, and avoid repeating
those three times by adding a new helper, output_file_open().

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
Stefano Brivio 2024-10-25 00:10:36 +02:00
parent 134b4d58b4
commit 59fe34ee36
5 changed files with 20 additions and 25 deletions

7
pcap.c
View file

@ -158,18 +158,15 @@ void pcap_iov(const struct iovec *iov, size_t iovcnt, size_t offset)
*/
void pcap_init(struct ctx *c)
{
int flags = O_WRONLY | O_CREAT | O_TRUNC;
if (pcap_fd != -1)
return;
if (!*c->pcap)
return;
flags |= c->foreground ? O_CLOEXEC : 0;
pcap_fd = open(c->pcap, flags, S_IRUSR | S_IWUSR);
pcap_fd = output_file_open(c->pcap, O_WRONLY);
if (pcap_fd == -1) {
perror("open");
err_perror("Couldn't open pcap file %s", c->pcap);
return;
}