Coverage Report

Created: 2025-12-27 06:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/haproxy/include/haproxy/sink.h
Line
Count
Source
1
/*
2
 * include/haproxy/sink.h
3
 * This file provides declarations for event sinks management
4
 *
5
 * Copyright (C) 2000-2019 Willy Tarreau - w@1wt.eu
6
 *
7
 * This library is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation, version 2.1
10
 * exclusively.
11
 *
12
 * This library is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with this library; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
20
 */
21
22
#ifndef _HAPROXY_SINK_H
23
#define _HAPROXY_SINK_H
24
25
#include <sys/types.h>
26
#include <haproxy/sink-t.h>
27
#include <haproxy/thread.h>
28
29
extern struct list sink_list;
30
31
extern struct proxy *sink_proxies_list;
32
33
struct sink *sink_find(const char *name);
34
struct sink *sink_find_early(const char *name, const char *from, const char *file, int line);
35
struct sink *sink_new_fd(const char *name, const char *desc, enum log_fmt, int fd);
36
ssize_t __sink_write(struct sink *sink, struct log_header hdr, size_t maxlen,
37
                     const struct ist msg[], size_t nmsg);
38
int sink_announce_dropped(struct sink *sink, struct log_header hdr);
39
40
41
/* tries to send <nmsg> message parts from message array <msg> to sink <sink>.
42
 * Formatting according to the sink's preference is done here, unless sink->fmt
43
 * is unspecified, in which case the caller formatting will be used instead.
44
 *
45
 * It will stop writing at <maxlen> instead of sink->maxlen if <maxlen> is
46
 * positive and inferior to sink->maxlen.
47
 *
48
 * Lost messages are accounted for in the sink's counter. If there
49
 * were lost messages, an attempt is first made to indicate it.
50
 * The function returns the number of Bytes effectively sent or announced.
51
 * or <= 0 in other cases.
52
 */
53
static inline ssize_t sink_write(struct sink *sink, struct log_header hdr,
54
                                 size_t maxlen, const struct ist msg[], size_t nmsg)
55
0
{
56
0
  ssize_t sent = 0;
57
0
  uint dropped = HA_ATOMIC_LOAD(&sink->ctx.dropped);
58
59
0
  if (unlikely(dropped > 0)) {
60
0
    if (dropped & 1) // another thread on it.
61
0
      goto fail;
62
0
    sent = sink_announce_dropped(sink, hdr);
63
64
0
    if (!sent) {
65
      /* we failed, we don't try to send our log as if it
66
       * would pass by chance, we'd get disordered events.
67
       */
68
0
      goto fail;
69
0
    }
70
0
  }
71
72
0
  sent = __sink_write(sink, hdr, maxlen, msg, nmsg);
73
74
0
 fail:
75
0
  if (unlikely(sent <= 0))
76
0
    HA_ATOMIC_ADD(&sink->ctx.dropped, 2);
77
78
0
  return sent;
79
0
}
Unexecuted instantiation: cfgparse.c:sink_write
Unexecuted instantiation: log.c:sink_write
Unexecuted instantiation: sample.c:sink_write
Unexecuted instantiation: sink.c:sink_write
Unexecuted instantiation: trace.c:sink_write
Unexecuted instantiation: fcgi-app.c:sink_write
Unexecuted instantiation: flt_spoe.c:sink_write
80
81
struct sink *sink_new_from_srv(struct server *srv, const char *from);
82
int sink_resolve_logger_buffer(struct logger *logger, char **msg);
83
84
#endif /* _HAPROXY_SINK_H */
85
86
/*
87
 * Local variables:
88
 *  c-indent-level: 8
89
 *  c-basic-offset: 8
90
 * End:
91
 */