1
0
Fork 0
mirror of https://passt.top/passt synced 2025-05-29 12:35:33 +02:00

treewide: Address cert-err33-c clang-tidy warnings for clock and timer functions

For clock_gettime(), we shouldn't ignore errors if they happen at
initialisation phase, because something is seriously wrong and it's
not helpful if we proceed as if nothing happened.

As we're up and running, though, it's probably better to report the
error and use a stale value than to terminate altogether. Make sure
we use a zero value if we don't have a stale one somewhere.

For timerfd_gettime() and timerfd_settime() failures, just report an
error, there isn't much else we can do.

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
Stefano Brivio 2024-10-25 00:29:50 +02:00
parent 59fe34ee36
commit 099ace64ce
3 changed files with 26 additions and 12 deletions

17
pcap.c
View file

@ -100,12 +100,14 @@ static void pcap_frame(const struct iovec *iov, size_t iovcnt,
void pcap(const char *pkt, size_t l2len)
{
struct iovec iov = { (char *)pkt, l2len };
struct timespec now;
struct timespec now = { 0 };
if (pcap_fd == -1)
return;
clock_gettime(CLOCK_REALTIME, &now);
if (clock_gettime(CLOCK_REALTIME, &now))
err_perror("Failed to get CLOCK_REALTIME time");
pcap_frame(&iov, 1, 0, &now);
}
@ -119,13 +121,14 @@ void pcap(const char *pkt, size_t l2len)
void pcap_multiple(const struct iovec *iov, size_t frame_parts, unsigned int n,
size_t offset)
{
struct timespec now;
struct timespec now = { 0 };
unsigned int i;
if (pcap_fd == -1)
return;
clock_gettime(CLOCK_REALTIME, &now);
if (clock_gettime(CLOCK_REALTIME, &now))
err_perror("Failed to get CLOCK_REALTIME time");
for (i = 0; i < n; i++)
pcap_frame(iov + i * frame_parts, frame_parts, offset, &now);
@ -143,12 +146,14 @@ void pcap_multiple(const struct iovec *iov, size_t frame_parts, unsigned int n,
/* cppcheck-suppress unusedFunction */
void pcap_iov(const struct iovec *iov, size_t iovcnt, size_t offset)
{
struct timespec now;
struct timespec now = { 0 };
if (pcap_fd == -1)
return;
clock_gettime(CLOCK_REALTIME, &now);
if (clock_gettime(CLOCK_REALTIME, &now))
err_perror("Failed to get CLOCK_REALTIME time");
pcap_frame(iov, iovcnt, offset, &now);
}