treewide: Standardise on 'now' for current timestamp variables
In a number of places we pass around a struct timespec representing the (more or less) current time. Sometimes we call it 'now', and sometimes we call it 'ts'. Standardise on the more informative 'now'. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
parent
17bbab1c97
commit
8563e7c870
7 changed files with 37 additions and 37 deletions
12
icmp.c
12
icmp.c
|
@ -275,14 +275,14 @@ fail_sock:
|
||||||
* @c: Execution context
|
* @c: Execution context
|
||||||
* @v6: Set for IPv6 echo identifier bindings
|
* @v6: Set for IPv6 echo identifier bindings
|
||||||
* @id: Echo identifier, host order
|
* @id: Echo identifier, host order
|
||||||
* @ts: Timestamp from caller
|
* @now: Current timestamp
|
||||||
*/
|
*/
|
||||||
static void icmp_timer_one(const struct ctx *c, int v6, uint16_t id,
|
static void icmp_timer_one(const struct ctx *c, int v6, uint16_t id,
|
||||||
const struct timespec *ts)
|
const struct timespec *now)
|
||||||
{
|
{
|
||||||
struct icmp_id_sock *id_map = &icmp_id_map[v6 ? V6 : V4][id];
|
struct icmp_id_sock *id_map = &icmp_id_map[v6 ? V6 : V4][id];
|
||||||
|
|
||||||
if (ts->tv_sec - id_map->ts <= ICMP_ECHO_TIMEOUT)
|
if (now->tv_sec - id_map->ts <= ICMP_ECHO_TIMEOUT)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bitmap_clear(icmp_act[v6 ? V6 : V4], id);
|
bitmap_clear(icmp_act[v6 ? V6 : V4], id);
|
||||||
|
@ -296,9 +296,9 @@ static void icmp_timer_one(const struct ctx *c, int v6, uint16_t id,
|
||||||
/**
|
/**
|
||||||
* icmp_timer() - Scan activity bitmap for identifiers with timed events
|
* icmp_timer() - Scan activity bitmap for identifiers with timed events
|
||||||
* @c: Execution context
|
* @c: Execution context
|
||||||
* @ts: Timestamp from caller
|
* @now: Current timestamp
|
||||||
*/
|
*/
|
||||||
void icmp_timer(const struct ctx *c, const struct timespec *ts)
|
void icmp_timer(const struct ctx *c, const struct timespec *now)
|
||||||
{
|
{
|
||||||
long *word, tmp;
|
long *word, tmp;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
@ -310,7 +310,7 @@ v6:
|
||||||
tmp = *word;
|
tmp = *word;
|
||||||
while ((n = ffsl(tmp))) {
|
while ((n = ffsl(tmp))) {
|
||||||
tmp &= ~(1UL << (n - 1));
|
tmp &= ~(1UL << (n - 1));
|
||||||
icmp_timer_one(c, v6, i * 8 + n - 1, ts);
|
icmp_timer_one(c, v6, i * 8 + n - 1, now);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
icmp.h
2
icmp.h
|
@ -15,7 +15,7 @@ void icmpv6_sock_handler(const struct ctx *c, union epoll_ref ref);
|
||||||
int icmp_tap_handler(const struct ctx *c, uint8_t pif, int af,
|
int icmp_tap_handler(const struct ctx *c, uint8_t pif, int af,
|
||||||
const void *saddr, const void *daddr,
|
const void *saddr, const void *daddr,
|
||||||
const struct pool *p, const struct timespec *now);
|
const struct pool *p, const struct timespec *now);
|
||||||
void icmp_timer(const struct ctx *c, const struct timespec *ts);
|
void icmp_timer(const struct ctx *c, const struct timespec *now);
|
||||||
void icmp_init(void);
|
void icmp_init(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
34
log.c
34
log.c
|
@ -216,11 +216,11 @@ void logfile_init(const char *name, const char *path, size_t size)
|
||||||
/**
|
/**
|
||||||
* logfile_rotate_fallocate() - Write header, set log_written after fallocate()
|
* logfile_rotate_fallocate() - Write header, set log_written after fallocate()
|
||||||
* @fd: Log file descriptor
|
* @fd: Log file descriptor
|
||||||
* @ts: Current timestamp
|
* @now: Current timestamp
|
||||||
*
|
*
|
||||||
* #syscalls lseek ppc64le:_llseek ppc64:_llseek armv6l:_llseek armv7l:_llseek
|
* #syscalls lseek ppc64le:_llseek ppc64:_llseek armv6l:_llseek armv7l:_llseek
|
||||||
*/
|
*/
|
||||||
static void logfile_rotate_fallocate(int fd, const struct timespec *ts)
|
static void logfile_rotate_fallocate(int fd, const struct timespec *now)
|
||||||
{
|
{
|
||||||
char buf[BUFSIZ];
|
char buf[BUFSIZ];
|
||||||
const char *nl;
|
const char *nl;
|
||||||
|
@ -233,8 +233,8 @@ static void logfile_rotate_fallocate(int fd, const struct timespec *ts)
|
||||||
|
|
||||||
n = snprintf(buf, BUFSIZ,
|
n = snprintf(buf, BUFSIZ,
|
||||||
"%s - log truncated at %lli.%04lli", log_header,
|
"%s - log truncated at %lli.%04lli", log_header,
|
||||||
(long long int)(ts->tv_sec - log_start),
|
(long long int)(now->tv_sec - log_start),
|
||||||
(long long int)(ts->tv_nsec / (100L * 1000)));
|
(long long int)(now->tv_nsec / (100L * 1000)));
|
||||||
|
|
||||||
/* Avoid partial lines by padding the header with spaces */
|
/* Avoid partial lines by padding the header with spaces */
|
||||||
nl = memchr(buf + n + 1, '\n', BUFSIZ - n - 1);
|
nl = memchr(buf + n + 1, '\n', BUFSIZ - n - 1);
|
||||||
|
@ -253,12 +253,12 @@ static void logfile_rotate_fallocate(int fd, const struct timespec *ts)
|
||||||
/**
|
/**
|
||||||
* logfile_rotate_move() - Fallback: move recent entries toward start, then cut
|
* logfile_rotate_move() - Fallback: move recent entries toward start, then cut
|
||||||
* @fd: Log file descriptor
|
* @fd: Log file descriptor
|
||||||
* @ts: Current timestamp
|
* @now: Current timestamp
|
||||||
*
|
*
|
||||||
* #syscalls lseek ppc64le:_llseek ppc64:_llseek armv6l:_llseek armv7l:_llseek
|
* #syscalls lseek ppc64le:_llseek ppc64:_llseek armv6l:_llseek armv7l:_llseek
|
||||||
* #syscalls ftruncate
|
* #syscalls ftruncate
|
||||||
*/
|
*/
|
||||||
static void logfile_rotate_move(int fd, const struct timespec *ts)
|
static void logfile_rotate_move(int fd, const struct timespec *now)
|
||||||
{
|
{
|
||||||
int header_len, write_offset, end, discard, n;
|
int header_len, write_offset, end, discard, n;
|
||||||
char buf[BUFSIZ];
|
char buf[BUFSIZ];
|
||||||
|
@ -266,8 +266,8 @@ static void logfile_rotate_move(int fd, const struct timespec *ts)
|
||||||
|
|
||||||
header_len = snprintf(buf, BUFSIZ,
|
header_len = snprintf(buf, BUFSIZ,
|
||||||
"%s - log truncated at %lli.%04lli\n", log_header,
|
"%s - log truncated at %lli.%04lli\n", log_header,
|
||||||
(long long int)(ts->tv_sec - log_start),
|
(long long int)(now->tv_sec - log_start),
|
||||||
(long long int)(ts->tv_nsec / (100L * 1000)));
|
(long long int)(now->tv_nsec / (100L * 1000)));
|
||||||
if (lseek(fd, 0, SEEK_SET) == -1)
|
if (lseek(fd, 0, SEEK_SET) == -1)
|
||||||
return;
|
return;
|
||||||
if (write(fd, buf, header_len) == -1)
|
if (write(fd, buf, header_len) == -1)
|
||||||
|
@ -316,7 +316,7 @@ out:
|
||||||
/**
|
/**
|
||||||
* logfile_rotate() - "Rotate" log file once it's full
|
* logfile_rotate() - "Rotate" log file once it's full
|
||||||
* @fd: Log file descriptor
|
* @fd: Log file descriptor
|
||||||
* @ts: Current timestamp
|
* @now: Current timestamp
|
||||||
*
|
*
|
||||||
* Return: 0 on success, negative error code on failure
|
* Return: 0 on success, negative error code on failure
|
||||||
*
|
*
|
||||||
|
@ -324,7 +324,7 @@ out:
|
||||||
*
|
*
|
||||||
* fallocate() passed as EXTRA_SYSCALL only if FALLOC_FL_COLLAPSE_RANGE is there
|
* fallocate() passed as EXTRA_SYSCALL only if FALLOC_FL_COLLAPSE_RANGE is there
|
||||||
*/
|
*/
|
||||||
static int logfile_rotate(int fd, const struct timespec *ts)
|
static int logfile_rotate(int fd, const struct timespec *now)
|
||||||
{
|
{
|
||||||
if (fcntl(fd, F_SETFL, O_RDWR /* Drop O_APPEND: explicit lseek() */))
|
if (fcntl(fd, F_SETFL, O_RDWR /* Drop O_APPEND: explicit lseek() */))
|
||||||
return -errno;
|
return -errno;
|
||||||
|
@ -332,10 +332,10 @@ static int logfile_rotate(int fd, const struct timespec *ts)
|
||||||
#ifdef FALLOC_FL_COLLAPSE_RANGE
|
#ifdef FALLOC_FL_COLLAPSE_RANGE
|
||||||
/* Only for Linux >= 3.15, extent-based ext4 or XFS, glibc >= 2.18 */
|
/* Only for Linux >= 3.15, extent-based ext4 or XFS, glibc >= 2.18 */
|
||||||
if (!fallocate(fd, FALLOC_FL_COLLAPSE_RANGE, 0, log_cut_size))
|
if (!fallocate(fd, FALLOC_FL_COLLAPSE_RANGE, 0, log_cut_size))
|
||||||
logfile_rotate_fallocate(fd, ts);
|
logfile_rotate_fallocate(fd, now);
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
logfile_rotate_move(fd, ts);
|
logfile_rotate_move(fd, now);
|
||||||
|
|
||||||
if (fcntl(fd, F_SETFL, O_RDWR | O_APPEND))
|
if (fcntl(fd, F_SETFL, O_RDWR | O_APPEND))
|
||||||
return -errno;
|
return -errno;
|
||||||
|
@ -351,16 +351,16 @@ static int logfile_rotate(int fd, const struct timespec *ts)
|
||||||
*/
|
*/
|
||||||
void logfile_write(int pri, const char *format, va_list ap)
|
void logfile_write(int pri, const char *format, va_list ap)
|
||||||
{
|
{
|
||||||
struct timespec ts;
|
struct timespec now;
|
||||||
char buf[BUFSIZ];
|
char buf[BUFSIZ];
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
if (clock_gettime(CLOCK_REALTIME, &ts))
|
if (clock_gettime(CLOCK_REALTIME, &now))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
n = snprintf(buf, BUFSIZ, "%lli.%04lli: %s",
|
n = snprintf(buf, BUFSIZ, "%lli.%04lli: %s",
|
||||||
(long long int)(ts.tv_sec - log_start),
|
(long long int)(now.tv_sec - log_start),
|
||||||
(long long int)(ts.tv_nsec / (100L * 1000)),
|
(long long int)(now.tv_nsec / (100L * 1000)),
|
||||||
logfile_prefix[pri]);
|
logfile_prefix[pri]);
|
||||||
|
|
||||||
n += vsnprintf(buf + n, BUFSIZ - n, format, ap);
|
n += vsnprintf(buf + n, BUFSIZ - n, format, ap);
|
||||||
|
@ -368,7 +368,7 @@ void logfile_write(int pri, const char *format, va_list ap)
|
||||||
if (format[strlen(format)] != '\n')
|
if (format[strlen(format)] != '\n')
|
||||||
n += snprintf(buf + n, BUFSIZ - n, "\n");
|
n += snprintf(buf + n, BUFSIZ - n, "\n");
|
||||||
|
|
||||||
if ((log_written + n >= log_size) && logfile_rotate(log_file, &ts))
|
if ((log_written + n >= log_size) && logfile_rotate(log_file, &now))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ((n = write(log_file, buf, n)) >= 0)
|
if ((n = write(log_file, buf, n)) >= 0)
|
||||||
|
|
6
tcp.c
6
tcp.c
|
@ -3181,13 +3181,13 @@ static int tcp_port_rebind_outbound(void *arg)
|
||||||
/**
|
/**
|
||||||
* tcp_timer() - Periodic tasks: port detection, closed connections, pool refill
|
* tcp_timer() - Periodic tasks: port detection, closed connections, pool refill
|
||||||
* @c: Execution context
|
* @c: Execution context
|
||||||
* @ts: Unused
|
* @now: Current timestamp
|
||||||
*/
|
*/
|
||||||
void tcp_timer(struct ctx *c, const struct timespec *ts)
|
void tcp_timer(struct ctx *c, const struct timespec *now)
|
||||||
{
|
{
|
||||||
union flow *flow;
|
union flow *flow;
|
||||||
|
|
||||||
(void)ts;
|
(void)now;
|
||||||
|
|
||||||
if (c->mode == MODE_PASTA) {
|
if (c->mode == MODE_PASTA) {
|
||||||
if (c->tcp.fwd_out.mode == FWD_AUTO) {
|
if (c->tcp.fwd_out.mode == FWD_AUTO) {
|
||||||
|
|
2
tcp.h
2
tcp.h
|
@ -20,7 +20,7 @@ int tcp_tap_handler(struct ctx *c, uint8_t pif, int af,
|
||||||
int tcp_sock_init(const struct ctx *c, sa_family_t af, const void *addr,
|
int tcp_sock_init(const struct ctx *c, sa_family_t af, const void *addr,
|
||||||
const char *ifname, in_port_t port);
|
const char *ifname, in_port_t port);
|
||||||
int tcp_init(struct ctx *c);
|
int tcp_init(struct ctx *c);
|
||||||
void tcp_timer(struct ctx *c, const struct timespec *ts);
|
void tcp_timer(struct ctx *c, const struct timespec *now);
|
||||||
void tcp_defer_handler(struct ctx *c);
|
void tcp_defer_handler(struct ctx *c);
|
||||||
|
|
||||||
void tcp_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s);
|
void tcp_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s);
|
||||||
|
|
16
udp.c
16
udp.c
|
@ -1138,10 +1138,10 @@ int udp_init(struct ctx *c)
|
||||||
* @v6: Set for IPv6 connections
|
* @v6: Set for IPv6 connections
|
||||||
* @type: Socket type
|
* @type: Socket type
|
||||||
* @port: Port number, host order
|
* @port: Port number, host order
|
||||||
* @ts: Timestamp from caller
|
* @now: Current timestamp
|
||||||
*/
|
*/
|
||||||
static void udp_timer_one(struct ctx *c, int v6, enum udp_act_type type,
|
static void udp_timer_one(struct ctx *c, int v6, enum udp_act_type type,
|
||||||
in_port_t port, const struct timespec *ts)
|
in_port_t port, const struct timespec *now)
|
||||||
{
|
{
|
||||||
struct udp_splice_port *sp;
|
struct udp_splice_port *sp;
|
||||||
struct udp_tap_port *tp;
|
struct udp_tap_port *tp;
|
||||||
|
@ -1151,7 +1151,7 @@ static void udp_timer_one(struct ctx *c, int v6, enum udp_act_type type,
|
||||||
case UDP_ACT_TAP:
|
case UDP_ACT_TAP:
|
||||||
tp = &udp_tap_map[v6 ? V6 : V4][port];
|
tp = &udp_tap_map[v6 ? V6 : V4][port];
|
||||||
|
|
||||||
if (ts->tv_sec - tp->ts > UDP_CONN_TIMEOUT) {
|
if (now->tv_sec - tp->ts > UDP_CONN_TIMEOUT) {
|
||||||
sockp = &tp->sock;
|
sockp = &tp->sock;
|
||||||
tp->flags = 0;
|
tp->flags = 0;
|
||||||
}
|
}
|
||||||
|
@ -1160,14 +1160,14 @@ static void udp_timer_one(struct ctx *c, int v6, enum udp_act_type type,
|
||||||
case UDP_ACT_SPLICE_INIT:
|
case UDP_ACT_SPLICE_INIT:
|
||||||
sp = &udp_splice_init[v6 ? V6 : V4][port];
|
sp = &udp_splice_init[v6 ? V6 : V4][port];
|
||||||
|
|
||||||
if (ts->tv_sec - sp->ts > UDP_CONN_TIMEOUT)
|
if (now->tv_sec - sp->ts > UDP_CONN_TIMEOUT)
|
||||||
sockp = &sp->sock;
|
sockp = &sp->sock;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case UDP_ACT_SPLICE_NS:
|
case UDP_ACT_SPLICE_NS:
|
||||||
sp = &udp_splice_ns[v6 ? V6 : V4][port];
|
sp = &udp_splice_ns[v6 ? V6 : V4][port];
|
||||||
|
|
||||||
if (ts->tv_sec - sp->ts > UDP_CONN_TIMEOUT)
|
if (now->tv_sec - sp->ts > UDP_CONN_TIMEOUT)
|
||||||
sockp = &sp->sock;
|
sockp = &sp->sock;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -1247,9 +1247,9 @@ static int udp_port_rebind_outbound(void *arg)
|
||||||
/**
|
/**
|
||||||
* udp_timer() - Scan activity bitmaps for ports with associated timed events
|
* udp_timer() - Scan activity bitmaps for ports with associated timed events
|
||||||
* @c: Execution context
|
* @c: Execution context
|
||||||
* @ts: Timestamp from caller
|
* @now: Current timestamp
|
||||||
*/
|
*/
|
||||||
void udp_timer(struct ctx *c, const struct timespec *ts)
|
void udp_timer(struct ctx *c, const struct timespec *now)
|
||||||
{
|
{
|
||||||
int n, t, v6 = 0;
|
int n, t, v6 = 0;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
@ -1279,7 +1279,7 @@ v6:
|
||||||
tmp = *word;
|
tmp = *word;
|
||||||
while ((n = ffsl(tmp))) {
|
while ((n = ffsl(tmp))) {
|
||||||
tmp &= ~(1UL << (n - 1));
|
tmp &= ~(1UL << (n - 1));
|
||||||
udp_timer_one(c, v6, t, i * 8 + n - 1, ts);
|
udp_timer_one(c, v6, t, i * 8 + n - 1, now);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
2
udp.h
2
udp.h
|
@ -17,7 +17,7 @@ int udp_tap_handler(struct ctx *c, uint8_t pif, int af,
|
||||||
int udp_sock_init(const struct ctx *c, int ns, sa_family_t af,
|
int udp_sock_init(const struct ctx *c, int ns, sa_family_t af,
|
||||||
const void *addr, const char *ifname, in_port_t port);
|
const void *addr, const char *ifname, in_port_t port);
|
||||||
int udp_init(struct ctx *c);
|
int udp_init(struct ctx *c);
|
||||||
void udp_timer(struct ctx *c, const struct timespec *ts);
|
void udp_timer(struct ctx *c, const struct timespec *now);
|
||||||
void udp_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s);
|
void udp_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue