summaryrefslogtreecommitdiffstats
path: root/include/haproxy/errors.h
blob: c102fedb8eb70d02552db2941a65ba7f22a888d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
 * include/haproxy/errors.h
 * Global error macros and constants
 *
 * Copyright (C) 2000-2020 Willy Tarreau - w@1wt.eu
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation, version 2.1
 * exclusively.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#ifndef _HAPROXY_ERRORS_H
#define _HAPROXY_ERRORS_H

#include <stdarg.h>
#include <stdio.h>

#include <haproxy/buf-t.h>
#include <haproxy/obj_type-t.h>

/* These flags may be used in various functions which are called from within
 * loops (eg: to start all listeners from all proxies). They provide enough
 * information to let the caller decide what to do. ERR_WARN and ERR_ALERT
 * do not indicate any error, just that a message has been put in a shared
 * buffer in order to be displayed by the caller.
 */
#define ERR_NONE	0x00	/* no error, no message returned */
#define ERR_RETRYABLE	0x01	/* retryable error, may be cumulated */
#define ERR_FATAL	0x02	/* fatal error, may be cumulated */
#define ERR_ABORT	0x04	/* it's preferable to end any possible loop */
#define ERR_WARN	0x08	/* a warning message has been returned */
#define ERR_ALERT	0x10	/* an alert message has been returned */

#define ERR_CODE	(ERR_RETRYABLE|ERR_FATAL|ERR_ABORT)	/* mask */

extern struct ring *startup_logs;

/* These codes may be used by config parsing functions which detect errors and
 * which need to inform the upper layer about them. They are all prefixed with
 * "PE_" for "Parse Error". These codes will probably be extended, and functions
 * making use of them should be documented as such. Only code PE_NONE (zero) may
 * indicate a valid condition, all other ones must be caught as errors, event if
 * unknown by the caller. This must not be used to forward warnings.
 */
enum {
	PE_NONE = 0,      /* no error */
	PE_ENUM_OOR,      /* enum data out of allowed range */
	PE_EXIST,         /* trying to create something which already exists */
	PE_ARG_MISSING,   /* mandatory argument not provided */
	PE_ARG_NOT_USED,  /* argument provided cannot be used */
	PE_ARG_INVC,      /* invalid char in argument (pointer not provided) */
	PE_ARG_INVC_PTR,  /* invalid char in argument (pointer provided) */
	PE_ARG_NOT_FOUND, /* argument references something not found */
	PE_ARG_VALUE_OOR, /* argument value is out of range */
};


void usermsgs_clr(const char *prefix);
int usermsgs_empty(void);
const char *usermsgs_str(void);
extern uint tot_warnings;

/************ Error reporting functions ***********/

struct usermsgs_ctx {
	struct buffer str;

	const char *prefix;  /* prefix of every output */
	const char *file;    /* related filename for config parsing */
	int line;            /* related line number for config parsing */
	enum obj_type *obj;  /* related proxy, server, ... */
};
void set_usermsgs_ctx(const char *file, int line, enum obj_type *obj);
void register_parsing_obj(enum obj_type *obj);
void reset_usermsgs_ctx(void);

/*
 * Displays the message on stderr with the date and pid. Overrides the quiet
 * mode during startup.
 */
void ha_alert(const char *fmt, ...)
	__attribute__ ((format(printf, 1, 2)));

/*
 * Displays the message on stderr with the date and pid.
 */
void ha_warning(const char *fmt, ...)
	__attribute__ ((format(printf, 1, 2)));

/*
 * These functions are reserved to output diagnostics on MODE_DIAG.
 * Use the underscore variants only if MODE_DIAG has already been checked.
 */
void _ha_vdiag_warning(const char *fmt, va_list argp);
void _ha_diag_warning(const char *fmt, ...);
void ha_diag_warning(const char *fmt, ...)
	__attribute__ ((format(printf, 1 ,2)));

/* Check for both MODE_DIAG and <cond> before outputting a diagnostic warning */
#define HA_DIAG_WARNING_COND(cond, fmt, ...)                  \
	do {                                                  \
		if ((global.mode & MODE_DIAG) && (cond))      \
			_ha_diag_warning((fmt), ##__VA_ARGS__); \
	} while (0)

/*
 * Displays the message on stderr with the date and pid.
 */
void ha_notice(const char *fmt, ...)
	__attribute__ ((format(printf, 1, 2)));

/*
 * Displays the message on <out> only if quiet mode is not set.
 */
void qfprintf(FILE *out, const char *fmt, ...)
	__attribute__ ((format(printf, 2, 3)));

void startup_logs_init();
struct ring *startup_logs_dup(struct ring *src);
void startup_logs_free(struct ring *r);

#endif /* _HAPROXY_ERRORS_H */

/*
 * Local variables:
 *  c-indent-level: 8
 *  c-basic-offset: 8
 * End:
 */