1
0
Fork 0
mirror of https://passt.top/passt synced 2025-06-11 10:05:34 +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

27
util.c
View file

@ -407,25 +407,20 @@ void pidfile_write(int fd, pid_t pid)
}
/**
* pidfile_open() - Open PID file if needed
* @path: Path for PID file, empty string if no PID file is requested
* output_file_open() - Open file for output, if needed
* @path: Path for output file
* @flags: Flags for open() other than O_CREAT, O_TRUNC, O_CLOEXEC
*
* Return: descriptor for PID file, -1 if path is NULL, won't return on failure
* Return: file descriptor on success, -1 on failure with errno set by open()
*/
int pidfile_open(const char *path)
int output_file_open(const char *path, int flags)
{
int fd;
if (!*path)
return -1;
if ((fd = open(path, O_CREAT | O_TRUNC | O_WRONLY | O_CLOEXEC,
S_IRUSR | S_IWUSR)) < 0) {
perror("PID file open");
exit(EXIT_FAILURE);
}
return fd;
/* We use O_CLOEXEC here, but clang-tidy as of LLVM 16 to 19 looks for
* it in the 'mode' argument if we have one
*/
return open(path, O_CREAT | O_TRUNC | O_CLOEXEC | flags,
/* NOLINTNEXTLINE(android-cloexec-open) */
S_IRUSR | S_IWUSR);
}
/**