-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathccndc-log.c
72 lines (66 loc) · 1.98 KB
/
ccndc-log.c
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
/**
* @file ccndc-log.c
* @brief Logging utilities for ccndc.
*
* Copyright (C) 2009-2012 Palo Alto Research Center, Inc.
*
* This work is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 2 as published by the
* Free Software Foundation.
* This work 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 General Public License
* for more details. You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
int verbose = 0;
void
ccndc_note(int lineno, const char *format, ...)
{
struct timeval t;
va_list ap;
if (verbose) {
va_start(ap, format);
gettimeofday(&t, NULL);
fprintf(stderr, "%d.%06d ccndc[%d]:%d: ", (int)t.tv_sec, (unsigned)t.tv_usec, (int)getpid(), lineno);
vfprintf(stderr, format, ap);
va_end(ap);
}
}
void
ccndc_warn(int lineno, const char *format, ...)
{
struct timeval t;
va_list ap;
va_start(ap, format);
gettimeofday(&t, NULL);
fprintf(stderr, "%d.%06d ccndc[%d]:%d: ", (int)t.tv_sec, (unsigned)t.tv_usec, (int)getpid(), lineno);
vfprintf(stderr, format, ap);
va_end(ap);
}
void
ccndc_fatal(int lineno, const char *format, ...)
{
struct timeval t;
va_list ap;
va_start(ap, format);
gettimeofday(&t, NULL);
fprintf(stderr, "%d.%06d ccndc[%d]:%d: ", (int)t.tv_sec, (unsigned)t.tv_usec, (int)getpid(), lineno);
vfprintf(stderr, format, ap);
va_end(ap);
exit(1);
}
void
on_error_exit(int res, int lineno, const char *msg)
{
if (res >= 0)
return;
ccndc_fatal(lineno, "fatal error, res = %d, %s\n", res, msg);
}