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