39
log_to_stderr = FALSE, /* should log go to stderr? */
40
log_to_syslog = TRUE; /* should log go to syslog? */
37
log_to_stderr = FALSE, /* should log go to stderr? */
38
log_to_syslog = TRUE; /* should log go to syslog? */
43
41
init_log(const char *program)
48
openlog(program, LOG_CONS | LOG_NDELAY | LOG_PID, LOG_AUTHPRIV);
46
openlog(program, LOG_CONS | LOG_NDELAY | LOG_PID, LOG_AUTHPRIV);
59
57
plog(const char *message, ...)
62
char m[LOG_WIDTH]; /* longer messages will be truncated */
64
va_start(args, message);
65
vsnprintf(m, sizeof(m), message, args);
69
fprintf(stderr, "%s\n", m);
71
syslog(LOG_WARNING, "%s", m);
60
char m[LOG_WIDTH]; /* longer messages will be truncated */
62
va_start(args, message);
63
vsnprintf(m, sizeof(m), message, args);
67
fprintf(stderr, "%s\n", m);
69
syslog(LOG_WARNING, "%s", m);
75
73
loglog(int mess_no, const char *message, ...)
78
char m[LOG_WIDTH]; /* longer messages will be truncated */
80
va_start(args, message);
81
vsnprintf(m, sizeof(m), message, args);
85
fprintf(stderr, "%s\n", m);
87
syslog(LOG_WARNING, "%s", m);
76
char m[LOG_WIDTH]; /* longer messages will be truncated */
78
va_start(args, message);
79
vsnprintf(m, sizeof(m), message, args);
83
fprintf(stderr, "%s\n", m);
85
syslog(LOG_WARNING, "%s", m);
91
89
log_errno_routine(int e, const char *message, ...)
94
char m[LOG_WIDTH]; /* longer messages will be truncated */
96
va_start(args, message);
97
vsnprintf(m, sizeof(m), message, args);
101
fprintf(stderr, "ERROR: %s. Errno %d: %s\n", m, e, strerror(e));
103
syslog(LOG_ERR, "ERROR: %s. Errno %d: %s", m, e, strerror(e));
92
char m[LOG_WIDTH]; /* longer messages will be truncated */
94
va_start(args, message);
95
vsnprintf(m, sizeof(m), message, args);
99
fprintf(stderr, "ERROR: %s. Errno %d: %s\n", m, e, strerror(e));
101
syslog(LOG_ERR, "ERROR: %s. Errno %d: %s", m, e, strerror(e));
107
105
exit_log(const char *message, ...)
110
char m[LOG_WIDTH]; /* longer messages will be truncated */
112
va_start(args, message);
113
vsnprintf(m, sizeof(m), message, args);
117
fprintf(stderr, "FATAL ERROR: %s\n", m);
119
syslog(LOG_ERR, "FATAL ERROR: %s", m);
108
char m[LOG_WIDTH]; /* longer messages will be truncated */
110
va_start(args, message);
111
vsnprintf(m, sizeof(m), message, args);
115
fprintf(stderr, "FATAL ERROR: %s\n", m);
117
syslog(LOG_ERR, "FATAL ERROR: %s", m);
124
122
exit_log_errno_routine(int e, const char *message, ...)
127
char m[LOG_WIDTH]; /* longer messages will be truncated */
129
va_start(args, message);
130
vsnprintf(m, sizeof(m), message, args);
134
fprintf(stderr, "FATAL ERROR: %s. Errno %d: %s\n", m, e, strerror(e));
136
syslog(LOG_ERR, "FATAL ERROR: %s. Errno %d: %s", m, e, strerror(e));
125
char m[LOG_WIDTH]; /* longer messages will be truncated */
127
va_start(args, message);
128
vsnprintf(m, sizeof(m), message, args);
132
fprintf(stderr, "FATAL ERROR: %s. Errno %d: %s\n", m, e, strerror(e));
134
syslog(LOG_ERR, "FATAL ERROR: %s. Errno %d: %s", m, e, strerror(e));
141
139
whack_log(int mess_no, const char *message, ...)
144
char m[LOG_WIDTH]; /* longer messages will be truncated */
146
va_start(args, message);
147
vsnprintf(m, sizeof(m), message, args);
150
fprintf(stderr, "%s\n", m);
142
char m[LOG_WIDTH]; /* longer messages will be truncated */
144
va_start(args, message);
145
vsnprintf(m, sizeof(m), message, args);
148
fprintf(stderr, "%s\n", m);
153
151
/* Build up a diagnostic in a static buffer.
185
183
switch_fail(int n, const char *file_str, unsigned long line_no)
189
snprintf(buf, sizeof(buf), "case %d unexpected", n);
190
passert_fail(buf, file_str, line_no);
187
snprintf(buf, sizeof(buf), "case %d unexpected", n);
188
passert_fail(buf, file_str, line_no);
194
192
passert_fail(const char *pred_str, const char *file_str, unsigned long line_no)
196
/* we will get a possibly unplanned prefix. Hope it works */
197
loglog(RC_LOG_SERIOUS, "ASSERTION FAILED at %s:%lu: %s", file_str, line_no, pred_str);
198
abort(); /* exiting correctly doesn't always work */
194
/* we will get a possibly unplanned prefix. Hope it works */
195
loglog(RC_LOG_SERIOUS, "ASSERTION FAILED at %s:%lu: %s", file_str, line_no, pred_str);
196
abort(); /* exiting correctly doesn't always work */
202
base_debugging = DBG_NONE, /* default to reporting nothing */
203
cur_debugging = DBG_NONE;
200
base_debugging = DBG_NONE, /* default to reporting nothing */
201
cur_debugging = DBG_NONE;
206
204
pexpect_log(const char *pred_str, const char *file_str, unsigned long line_no)
208
/* we will get a possibly unplanned prefix. Hope it works */
209
loglog(RC_LOG_SERIOUS, "EXPECTATION FAILED at %s:%lu: %s", file_str, line_no, pred_str);
206
/* we will get a possibly unplanned prefix. Hope it works */
207
loglog(RC_LOG_SERIOUS, "EXPECTATION FAILED at %s:%lu: %s", file_str, line_no, pred_str);
212
210
/* log a debugging message (prefixed by "| ") */
233
231
DBG_dump(const char *label, const void *p, size_t len)
235
# define DUMP_LABEL_WIDTH 20 /* arbitrary modest boundary */
236
# define DUMP_WIDTH (4 * (1 + 4 * 3) + 1)
237
char buf[DUMP_LABEL_WIDTH + DUMP_WIDTH];
239
const unsigned char *cp = p;
243
if (label != NULL && label[0] != '\0')
245
/* Handle the label. Care must be taken to avoid buffer overrun. */
246
size_t llen = strlen(label);
248
if (llen + 1 > sizeof(buf))
250
DBG_log("%s", label);
255
if (buf[llen-1] == '\n')
257
buf[llen-1] = '\0'; /* get rid of newline */
260
else if (llen < DUMP_LABEL_WIDTH)
274
for (i = 0; len!=0 && i!=4; i++)
277
for (j = 0; len!=0 && j!=4; len--, j++)
279
static const char hexdig[] = "0123456789abcdef";
282
*bp++ = hexdig[(*cp >> 4) & 0xF];
283
*bp++ = hexdig[*cp & 0xF];
233
# define DUMP_LABEL_WIDTH 20 /* arbitrary modest boundary */
234
# define DUMP_WIDTH (4 * (1 + 4 * 3) + 1)
235
char buf[DUMP_LABEL_WIDTH + DUMP_WIDTH];
237
const unsigned char *cp = p;
241
if (label != NULL && label[0] != '\0')
243
/* Handle the label. Care must be taken to avoid buffer overrun. */
244
size_t llen = strlen(label);
246
if (llen + 1 > sizeof(buf))
248
DBG_log("%s", label);
253
if (buf[llen-1] == '\n')
255
buf[llen-1] = '\0'; /* get rid of newline */
258
else if (llen < DUMP_LABEL_WIDTH)
272
for (i = 0; len!=0 && i!=4; i++)
275
for (j = 0; len!=0 && j!=4; len--, j++)
277
static const char hexdig[] = "0123456789abcdef";
280
*bp++ = hexdig[(*cp >> 4) & 0xF];
281
*bp++ = hexdig[*cp & 0xF];
291
289
# undef DUMP_LABEL_WIDTH
292
290
# undef DUMP_WIDTH