~ubuntu-branches/debian/sid/rlinetd/sid

« back to all changes in this revision

Viewing changes to src/error.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Luberda
  • Date: 2010-03-20 18:03:45 UTC
  • mfrom: (2.3.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100320180345-x1srfbe2tg00ezsf
Tags: 0.7-1
* New upstream version.
* Recommend rsyslog instead of sysklogd (closes: #526922).
* update-inetd:
  + add support for enabling, disabling and removing entries;
  + use ucf for managing generated files;
  + ignore ucf files in rlinetd.conf;
  + make appropriate changes in  postinst and postrm scripts.
* Set debhelper compat level to 7
* Standards-Version: 3.8.4 (no changes). 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <syslog.h>
 
2
#include <stdio.h>
 
3
#include <stdarg.h>
 
4
#include <stdlib.h>
 
5
#include "error.h"
 
6
 
 
7
extern int rl_debug;
 
8
static void rl_log(int, const char *, int, const char *, va_list);
 
9
 
 
10
void rl_note(const char * fmt, ...) {
 
11
        va_list argp;
 
12
 
 
13
        va_start(argp, fmt);
 
14
        rl_log(LOG_INFO, NULL, 0, fmt, argp);
 
15
        va_end(argp);
 
16
}
 
17
 
 
18
void rl_warn(const char * fmt, ...) {
 
19
        va_list argp;
 
20
 
 
21
        va_start(argp, fmt);
 
22
        rl_log(LOG_WARNING, NULL, 0, fmt, argp);
 
23
        va_end(argp);
 
24
}
 
25
 
 
26
void rl_pwarn(const char * file, int line, const char * fmt, ...) {
 
27
        va_list argp;
 
28
 
 
29
        va_start(argp, fmt);
 
30
        rl_log(LOG_WARNING, file, line, fmt, argp);
 
31
        va_end(argp);
 
32
}
 
33
 
 
34
 
 
35
void rl_fatal(int ex, const char * fmt, ...) {
 
36
        va_list argp;
 
37
 
 
38
        va_start(argp, fmt);
 
39
        rl_log(LOG_ERR, NULL, 0, fmt, argp);
 
40
        va_end(argp);
 
41
 
 
42
        exit(ex);
 
43
}
 
44
 
 
45
void rl_pfatal(int ex, const char * file, int line, const char * fmt, ...) {
 
46
        va_list argp;
 
47
 
 
48
        va_start(argp, fmt);
 
49
        rl_log(LOG_ERR, file, line, fmt, argp);
 
50
        va_end(argp);
 
51
 
 
52
        exit(ex);
 
53
}
 
54
 
 
55
 
 
56
 
 
57
static void rl_log(int level, const char * file, int line, const char * fmt, va_list argp) {
 
58
        char message[1024];
 
59
        int cur_len;
 
60
        int max_len;
 
61
 
 
62
 
 
63
        max_len         = sizeof(message) - 1;
 
64
        cur_len         = 0;
 
65
        
 
66
        memset(message, 0, max_len);
 
67
 
 
68
        if (file) {
 
69
                snprintf(message, max_len, "(%.255s:%d) ", 
 
70
                                file, line);
 
71
                cur_len = strlen(message);
 
72
                max_len -= (cur_len + 1);
 
73
        }
 
74
 
 
75
        vsnprintf(message + cur_len, max_len, fmt, argp);
 
76
        
 
77
        if (rl_debug)
 
78
        {
 
79
                fprintf(stderr, "%s\n", message);
 
80
                fflush(stderr);
 
81
        }       
 
82
        else
 
83
                syslog(level, "%s", message);
 
84
}
 
85
 
 
86
 
 
87
/* vim: set ts=2: */