]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/message.h
Backport from Bacula Enterprise
[bacula/bacula] / bacula / src / lib / message.h
1 /*
2    Bacula(R) - The Network Backup Solution
3
4    Copyright (C) 2000-2015 Kern Sibbald
5    Copyright (C) 2000-2014 Free Software Foundation Europe e.V.
6
7    The original author of Bacula is Kern Sibbald, with contributions
8    from many others, a complete list can be found in the file AUTHORS.
9
10    You may use this file and others of this release according to the
11    license defined in the LICENSE file, which includes the Affero General
12    Public License, v3.0 ("AGPLv3") and some additional permissions and
13    terms pursuant to its AGPLv3 Section 7.
14
15    This notice must be preserved when any source code is 
16    conveyed and/or propagated.
17
18    Bacula(R) is a registered trademark of Kern Sibbald.
19 */
20 /*
21  * Define Message Types for Bacula
22  *    Kern Sibbald, 2000
23  *
24  */
25
26
27 #include "bits.h"
28
29 #undef  M_DEBUG
30 #undef  M_ABORT
31 #undef  M_FATAL
32 #undef  M_ERROR
33 #undef  M_WARNING
34 #undef  M_INFO
35 #undef  M_MOUNT
36 #undef  M_ERROR_TERM
37 #undef  M_TERM
38 #undef  M_RESTORED
39 #undef  M_SECURITY
40 #undef  M_ALERT
41 #undef  M_VOLMGMT
42
43 /*
44  * Most of these message levels are more or less obvious.
45  * They have evolved somewhat during the development of Bacula,
46  * and here are some of the details of where I am trying to
47  * head (in the process of changing the code) as of 15 June 2002.
48  *
49  *  M_ABORT       Bacula immediately aborts and tries to produce a traceback
50  *                  This is for really serious errors like segmentation fault.
51  *  M_ERROR_TERM  Bacula immediately terminates but no dump. This is for
52  *                  "obvious" serious errors like daemon already running or
53  *                   cannot open critical file, ... where a dump is not wanted.
54  *  M_TERM        Bacula daemon shutting down because of request (SIGTERM).
55  *
56  * The remaining apply to Jobs rather than the daemon.
57  *
58  *  M_FATAL       Bacula detected a fatal Job error. The Job will be killed,
59  *                  but Bacula continues running.
60  *  M_ERROR       Bacula detected a Job error. The Job will continue running
61  *                  but the termination status will be error.
62  *  M_WARNING     Job warning message.
63  *  M_INFO        Job information message.
64  *
65  *  M_RESTORED    An ls -l of each restored file.
66  *
67  *  M_SECURITY    For security viloations. This is equivalent to FATAL.
68  *                (note, this is currently being implemented in 1.33).
69  *
70  *  M_ALERT       For Tape Alert messages.
71  *
72  *  M_VOLMGMT     Volume Management message
73  */
74
75 enum {
76    /* Keep M_ABORT=1 for dlist.h */
77    M_ABORT = 1,                       /* MUST abort immediately */
78    M_DEBUG,                           /* debug message */
79    M_FATAL,                           /* Fatal error, stopping job */
80    M_ERROR,                           /* Error, but recoverable */
81    M_WARNING,                         /* Warning message */
82    M_INFO,                            /* Informational message */
83    M_SAVED,                           /* Info on saved file */
84    M_NOTSAVED,                        /* Info on notsaved file */
85    M_SKIPPED,                         /* File skipped during backup by option setting */
86    M_MOUNT,                           /* Mount requests */
87    M_ERROR_TERM,                      /* Error termination request (no dump) */
88    M_TERM,                            /* Terminating daemon normally */
89    M_RESTORED,                        /* ls -l of restored files */
90    M_SECURITY,                        /* security violation */
91    M_ALERT,                           /* tape alert messages */
92    M_VOLMGMT                          /* Volume management messages */
93 };
94
95 #define M_MAX      M_VOLMGMT          /* keep this updated ! */
96
97 /* Define message destination structure */
98 /* *** FIXME **** where should be extended to handle multiple values */
99 typedef struct s_dest {
100    struct s_dest *next;
101    int dest_code;                     /* destination (one of the MD_ codes) */
102    int max_len;                       /* max mail line length */
103    FILE *fd;                          /* file descriptor */
104    char msg_types[nbytes_for_bits(M_MAX+1)]; /* message type mask */
105    char *where;                       /* filename/program name */
106    char *mail_cmd;                    /* mail command */
107    POOLMEM *mail_filename;            /* unique mail filename */
108 } DEST;
109
110 /* Message Destination values for dest field of DEST */
111 enum {
112    MD_SYSLOG = 1,                     /* send msg to syslog */
113    MD_MAIL,                           /* email group of messages */
114    MD_FILE,                           /* write messages to a file */
115    MD_APPEND,                         /* append messages to a file */
116    MD_STDOUT,                         /* print messages */
117    MD_STDERR,                         /* print messages to stderr */
118    MD_DIRECTOR,                       /* send message to the Director */
119    MD_OPERATOR,                       /* email a single message to the operator */
120    MD_CONSOLE,                        /* send msg to UserAgent or console */
121    MD_MAIL_ON_ERROR,                  /* email messages if job errors */
122    MD_MAIL_ON_SUCCESS,                /* email messages if job succeeds */
123    MD_CATALOG                         /* sent to catalog Log table */
124 };
125
126 /* Queued message item */
127 struct MQUEUE_ITEM {
128    dlink link;
129    int type;
130    utime_t mtime;
131    char msg[1];
132 };
133
134 /* Debug options */
135 #define DEBUG_CLEAR_FLAGS           /* 0    clear debug_flags */
136 #define DEBUG_NO_WIN32_WRITE_ERROR  /* i    continue even after win32 errors */
137 #define DEBUG_WIN32DECOMP           /* d */
138 #define DEBUG_DBG_TIMESTAMP         /* t    turn on timestamp in trace file */
139 #define DEBUG_DBG_NO_TIMESTAMP      /* T    turn off timestamp in trace file */
140 #define DEBUG_TRUNCATE_TRACE        /* c    clear trace file if opened */
141
142 /* Bits (1, 2, 4, ...) for debug_flags used by set_debug_flags() */
143 #define DEBUG_MUTEX_EVENT           (1 << 0)    /* l */
144 #define DEBUG_PRINT_EVENT           (1 << 1)    /* p */
145
146 /* Tags that can be used with the setdebug command
147  * We can extend this list to use 64bit
148  * When adding new ones, keep existing one
149  * Corresponding strings are defined in messages.c (debugtags)
150  */
151 #define    DT_LOCK       (1<<30)                /* lock    */
152 #define    DT_NETWORK    (1<<29)                /* network */
153 #define    DT_PLUGIN     (1<<28)                /* plugin  */
154 #define    DT_VOLUME     (1<<27)                /* volume  */
155 #define    DT_SQL        (1<<26)                /* sql     */
156 #define    DT_BVFS       (1<<25)                /* bvfs    */
157 #define    DT_MEMORY     (1<<24)                /* memory  */
158 #define    DT_SCHEDULER  (1<<23)                /* scheduler */
159 #define    DT_PROTOCOL   (1<<22)                /* protocol */
160 #define    DT_SNAPSHOT   (1<<19)                /* Snapshot */
161 #define    DT_ASX        (1<<16)                /* used by Alain for personal debugging */
162 #define    DT_ALL        (0x7FFF0000)           /* all (up to debug_level 65635, 15 flags available) */
163
164 const char *debug_get_tag(uint32_t pos, const char **desc);
165 bool debug_find_tag(const char *tagname, bool add, int64_t *current_level);
166 bool debug_parse_tags(const char *options, int64_t *current_level);
167
168
169 void d_msg(const char *file, int line, int64_t level, const char *fmt,...) CHECK_FORMAT(printf, 4, 5);
170 void e_msg(const char *file, int line, int type, int level, const char *fmt,...) CHECK_FORMAT(printf, 5, 6);;
171 void Jmsg(JCR *jcr, int type, utime_t mtime, const char *fmt,...) CHECK_FORMAT(printf, 4, 5);
172 void Qmsg(JCR *jcr, int type, utime_t mtime, const char *fmt,...) CHECK_FORMAT(printf, 4, 5);
173 bool get_trace(void);
174 void set_debug_flags(char *options);
175 const char *get_basename(const char *pathname);
176
177 class BDB;                                              /* define forward reference */
178 typedef bool (*sql_query_call)(JCR *jcr, const char *cmd);
179 typedef bool (*sql_escape_call)(JCR *jcr, BDB *db, char *snew, char *sold, int len);
180
181 extern DLL_IMP_EXP sql_query_call  p_sql_query;
182 extern DLL_IMP_EXP sql_escape_call p_sql_escape;
183
184 extern DLL_IMP_EXP int64_t       debug_level;
185 extern DLL_IMP_EXP int64_t       debug_level_tags;
186 extern DLL_IMP_EXP int32_t       debug_flags;
187 extern DLL_IMP_EXP bool          dbg_timestamp;          /* print timestamp in debug output */
188 extern DLL_IMP_EXP bool          prt_kaboom;             /* Print kaboom output */
189 extern DLL_IMP_EXP int           verbose;
190 extern DLL_IMP_EXP char          my_name[];
191 extern DLL_IMP_EXP const char *  working_directory;
192 extern DLL_IMP_EXP utime_t       daemon_start_time;
193
194 extern DLL_IMP_EXP int           console_msg_pending;
195 extern DLL_IMP_EXP FILE *        con_fd;                 /* Console file descriptor */
196 extern DLL_IMP_EXP brwlock_t     con_lock;               /* Console lock structure */