Avoid segfault if verify header appears longer than io_u
[fio.git] / log.c
CommitLineData
ac9b9101
JA
1#include <unistd.h>
2#include <fcntl.h>
3#include <string.h>
4#include <stdarg.h>
e46d8091 5#include <syslog.h>
3c39a379 6
ac9b9101 7#include "fio.h"
3c39a379 8
e46d8091
JA
9int log_valist(const char *str, va_list args)
10{
734f38cb
JA
11 char buffer[1024];
12 size_t len;
13
14 len = vsnprintf(buffer, sizeof(buffer), str, args);
15
16 if (log_syslog)
17 syslog(LOG_INFO, "%s", buffer);
18 else
19 len = fwrite(buffer, len, 1, f_out);
20
21 return len;
e46d8091
JA
22}
23
13755d94
JA
24int log_local_buf(const char *buf, size_t len)
25{
26 if (log_syslog)
27 syslog(LOG_INFO, "%s", buf);
28 else
29 len = fwrite(buf, len, 1, f_out);
30
31 return len;
32}
33
ac9b9101 34int log_local(const char *format, ...)
3c39a379 35{
ac9b9101
JA
36 char buffer[1024];
37 va_list args;
38 size_t len;
8de8f047 39
ac9b9101 40 va_start(args, format);
734f38cb
JA
41 len = vsnprintf(buffer, sizeof(buffer), format, args);
42 va_end(args);
3c39a379 43
734f38cb
JA
44 if (log_syslog)
45 syslog(LOG_INFO, "%s", buffer);
46 else
47 len = fwrite(buffer, len, 1, f_out);
48
49 return len;
3c39a379
JA
50}
51
ac9b9101 52int log_info(const char *format, ...)
3c39a379 53{
ac9b9101
JA
54 char buffer[1024];
55 va_list args;
56 size_t len;
3c39a379 57
ac9b9101
JA
58 va_start(args, format);
59 len = vsnprintf(buffer, sizeof(buffer), format, args);
60 va_end(args);
f29b25a3 61
ac9b9101
JA
62 if (is_backend)
63 return fio_server_text_output(buffer, len);
13755d94
JA
64 else if (log_syslog) {
65 syslog(LOG_INFO, "%s", buffer);
66 return len;
67 } else
ac9b9101 68 return fwrite(buffer, len, 1, f_out);
f29b25a3
JA
69}
70
ac9b9101 71int log_err(const char *format, ...)
fb71fbd7 72{
ac9b9101
JA
73 char buffer[1024];
74 va_list args;
75 size_t len;
f29b25a3 76
ac9b9101
JA
77 va_start(args, format);
78 len = vsnprintf(buffer, sizeof(buffer), format, args);
79 va_end(args);
fb71fbd7 80
ac9b9101
JA
81 if (is_backend)
82 return fio_server_text_output(buffer, len);
13755d94
JA
83 else if (log_syslog) {
84 syslog(LOG_INFO, "%s", buffer);
85 return len;
86 } else {
1f39e555
JA
87 if (f_err != stderr) {
88 int fio_unused ret;
89
90 ret = fwrite(buffer, len, 1, stderr);
91 }
fb71fbd7 92
ac9b9101 93 return fwrite(buffer, len, 1, f_err);
f29b25a3 94 }
e3cedca7 95}