~ubuntu-branches/ubuntu/oneiric/gnupg2/oneiric-updates

« back to all changes in this revision

Viewing changes to util/logging.c

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Viehmann
  • Date: 2008-10-04 10:25:53 UTC
  • mfrom: (5.1.15 intrepid)
  • Revision ID: james.westby@ubuntu.com-20081004102553-fv62pp8dsitxli47
Tags: 2.0.9-3.1
* Non-maintainer upload.
* agent/gpg-agent.c: Deinit the threading library before exec'ing
  the command to run in --daemon mode. And because that still doesn't
  restore the sigprocmask, do that manually. Closes: #499569

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* logging.c -  useful logging functions
2
 
 *      Copyright (C) 1998, 1999 Free Software Foundation, Inc.
3
 
 *
4
 
 * This file is part of GnuPG.
5
 
 *
6
 
 * GnuPG is free software; you can redistribute it and/or modify
7
 
 * it under the terms of the GNU General Public License as published by
8
 
 * the Free Software Foundation; either version 2 of the License, or
9
 
 * (at your option) any later version.
10
 
 *
11
 
 * GnuPG is distributed in the hope that it will be useful,
12
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 * GNU General Public License for more details.
15
 
 *
16
 
 * You should have received a copy of the GNU General Public License
17
 
 * along with this program; if not, write to the Free Software
18
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19
 
 */
20
 
 
21
 
 
22
 
/* This file should replace logger.c in the future - for now it is not
23
 
 * used GnuPG.
24
 
 * It is a quite simple implemenation but sufficient for most purposes.
25
 
 */
26
 
 
27
 
#include <config.h>
28
 
#include <stdlib.h>
29
 
#include <stdio.h>
30
 
#include <string.h>
31
 
#include <stdarg.h>
32
 
 
33
 
#include "libutil-config.h"
34
 
#include "logging.h"
35
 
 
36
 
enum my_log_levels {
37
 
    MY_LOG_CONT,
38
 
    MY_LOG_INFO,
39
 
    MY_LOG_WARN,
40
 
    MY_LOG_ERROR,
41
 
    MY_LOG_FATAL,
42
 
    MY_LOG_BUG,
43
 
    MY_LOG_DEBUG
44
 
};
45
 
 
46
 
 
47
 
#if 0
48
 
static void
49
 
write2stderr( const char *s )
50
 
{
51
 
    write( 2, s, strlen(s) );
52
 
}
53
 
 
54
 
 
55
 
static void
56
 
do_die(int rc, const char *text )
57
 
{
58
 
    write2stderr("\nFatal error: ");
59
 
    write2stderr(text);
60
 
    write2stderr("\n");
61
 
    abort();
62
 
}
63
 
#endif
64
 
 
65
 
 
66
 
static void
67
 
do_logv( int level, const char *fmt, va_list arg_ptr )
68
 
{
69
 
    switch ( level ) {
70
 
      case MY_LOG_CONT: break;
71
 
      case MY_LOG_INFO: break;
72
 
      case MY_LOG_WARN: break;
73
 
      case MY_LOG_ERROR: break;
74
 
      case MY_LOG_FATAL: fputs("Fatal: ",stderr ); break;
75
 
      case MY_LOG_BUG: fputs("Ohhhh jeeee: ", stderr); break;
76
 
      case MY_LOG_DEBUG: fputs("DBG: ", stderr ); break;
77
 
      default: fprintf(stderr,"[Unknown log level %d]: ", level ); break;
78
 
    }
79
 
    vfprintf(stderr,fmt,arg_ptr) ;
80
 
 
81
 
    if( level == MY_LOG_FATAL )
82
 
        exit(2);
83
 
    if( level == MY_LOG_BUG )
84
 
        abort();
85
 
}
86
 
 
87
 
static void
88
 
do_log( int level, const char *fmt, ... )
89
 
{
90
 
    va_list arg_ptr ;
91
 
 
92
 
    va_start( arg_ptr, fmt ) ;
93
 
    do_logv( level, fmt, arg_ptr );
94
 
    va_end(arg_ptr);
95
 
}
96
 
 
97
 
 
98
 
 
99
 
void
100
 
log_info( const char *fmt, ... )
101
 
{
102
 
    va_list arg_ptr ;
103
 
 
104
 
    va_start( arg_ptr, fmt ) ;
105
 
    do_logv( MY_LOG_INFO, fmt, arg_ptr );
106
 
    va_end(arg_ptr);
107
 
}
108
 
 
109
 
void
110
 
log_error( const char *fmt, ... )
111
 
{
112
 
    va_list arg_ptr ;
113
 
 
114
 
    va_start( arg_ptr, fmt ) ;
115
 
    do_logv( MY_LOG_ERROR, fmt, arg_ptr );
116
 
    va_end(arg_ptr);
117
 
}
118
 
 
119
 
 
120
 
void
121
 
log_fatal( const char *fmt, ... )
122
 
{
123
 
    va_list arg_ptr ;
124
 
 
125
 
    va_start( arg_ptr, fmt ) ;
126
 
    do_logv( MY_LOG_FATAL, fmt, arg_ptr );
127
 
    va_end(arg_ptr);
128
 
    abort(); /* never called, bugs it makes the compiler happy */
129
 
}
130
 
 
131
 
void
132
 
log_bug( const char *fmt, ... )
133
 
{
134
 
    va_list arg_ptr ;
135
 
 
136
 
    va_start( arg_ptr, fmt ) ;
137
 
    do_logv( MY_LOG_BUG, fmt, arg_ptr );
138
 
    va_end(arg_ptr);
139
 
    abort(); /* never called, bugs it makes the compiler happy */
140
 
}
141
 
 
142
 
void
143
 
log_debug( const char *fmt, ... )
144
 
{
145
 
    va_list arg_ptr ;
146
 
 
147
 
    va_start( arg_ptr, fmt ) ;
148
 
    do_logv( MY_LOG_DEBUG, fmt, arg_ptr );
149
 
    va_end(arg_ptr);
150
 
}
151
 
 
152
 
 
153
 
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 )
154
 
void
155
 
bug_at( const char *file, int line, const char *func )
156
 
{
157
 
    do_log( MY_LOG_BUG,
158
 
             ("... this is a bug (%s:%d:%s)\n"), file, line, func );
159
 
    abort(); /* never called, but it makes the compiler happy */
160
 
}
161
 
#else
162
 
void
163
 
bug_at( const char *file, int line )
164
 
{
165
 
    do_log( MY_LOG_BUG,
166
 
             _("you found a bug ... (%s:%d)\n"), file, line);
167
 
    abort(); /* never called, but it makes the compiler happy */
168
 
}
169
 
#endif
170