]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/message.h
Backport new lock calls + debug for SD
[bacula/bacula] / bacula / src / lib / message.h
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2000-2011 Free Software Foundation Europe e.V.
5
6    The main author of Bacula is Kern Sibbald, with contributions from
7    many others, a complete list can be found in the file AUTHORS.
8    This program is Free Software; you can redistribute it and/or
9    modify it under the terms of version three of the GNU Affero General Public
10    License as published by the Free Software Foundation and included
11    in the file LICENSE.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU Affero General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23    Bacula® is a registered trademark of Kern Sibbald.
24    The licensor of Bacula is the Free Software Foundation Europe
25    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26    Switzerland, email:ftf@fsfeurope.org.
27 */
28 /*
29  * Define Message Types for Bacula
30  *    Kern Sibbald, 2000
31  *
32  */
33
34
35 #include "bits.h"
36
37 #undef  M_DEBUG
38 #undef  M_ABORT
39 #undef  M_FATAL
40 #undef  M_ERROR
41 #undef  M_WARNING
42 #undef  M_INFO
43 #undef  M_MOUNT
44 #undef  M_ERROR_TERM
45 #undef  M_TERM
46 #undef  M_RESTORED
47 #undef  M_SECURITY
48 #undef  M_ALERT
49 #undef  M_VOLMGMT
50
51 /*
52  * Most of these message levels are more or less obvious.
53  * They have evolved somewhat during the development of Bacula,
54  * and here are some of the details of where I am trying to
55  * head (in the process of changing the code) as of 15 June 2002.
56  *
57  *  M_ABORT       Bacula immediately aborts and tries to produce a traceback
58  *                  This is for really serious errors like segmentation fault.
59  *  M_ERROR_TERM  Bacula immediately terminates but no dump. This is for
60  *                  "obvious" serious errors like daemon already running or
61  *                   cannot open critical file, ... where a dump is not wanted.
62  *  M_TERM        Bacula daemon shutting down because of request (SIGTERM).
63  *
64  * The remaining apply to Jobs rather than the daemon.
65  *
66  *  M_FATAL       Bacula detected a fatal Job error. The Job will be killed,
67  *                  but Bacula continues running.
68  *  M_ERROR       Bacula detected a Job error. The Job will continue running
69  *                  but the termination status will be error.
70  *  M_WARNING     Job warning message.
71  *  M_INFO        Job information message.
72  *
73  *  M_RESTORED    An ls -l of each restored file.
74  *
75  *  M_SECURITY    For security viloations. This is equivalent to FATAL.
76  *                (note, this is currently being implemented in 1.33).
77  *
78  *  M_ALERT       For Tape Alert messages.
79  *
80  *  M_VOLMGMT     Volume Management message
81  */
82
83 enum {
84    /* Keep M_ABORT=1 for dlist.h */
85    M_ABORT = 1,                       /* MUST abort immediately */
86    M_DEBUG,                           /* debug message */
87    M_FATAL,                           /* Fatal error, stopping job */
88    M_ERROR,                           /* Error, but recoverable */
89    M_WARNING,                         /* Warning message */
90    M_INFO,                            /* Informational message */
91    M_SAVED,                           /* Info on saved file */
92    M_NOTSAVED,                        /* Info on notsaved file */
93    M_SKIPPED,                         /* File skipped during backup by option setting */
94    M_MOUNT,                           /* Mount requests */
95    M_ERROR_TERM,                      /* Error termination request (no dump) */
96    M_TERM,                            /* Terminating daemon normally */
97    M_RESTORED,                        /* ls -l of restored files */
98    M_SECURITY,                        /* security violation */
99    M_ALERT,                           /* tape alert messages */
100    M_VOLMGMT                          /* Volume management messages */
101 };
102
103 #define M_MAX      M_VOLMGMT          /* keep this updated ! */
104
105 /* Define message destination structure */
106 /* *** FIXME **** where should be extended to handle multiple values */
107 typedef struct s_dest {
108    struct s_dest *next;
109    int dest_code;                     /* destination (one of the MD_ codes) */
110    int max_len;                       /* max mail line length */
111    FILE *fd;                          /* file descriptor */
112    char msg_types[nbytes_for_bits(M_MAX+1)]; /* message type mask */
113    char *where;                       /* filename/program name */
114    char *mail_cmd;                    /* mail command */
115    POOLMEM *mail_filename;            /* unique mail filename */
116 } DEST;
117
118 /* Message Destination values for dest field of DEST */
119 enum {
120    MD_SYSLOG = 1,                     /* send msg to syslog */
121    MD_MAIL,                           /* email group of messages */
122    MD_FILE,                           /* write messages to a file */
123    MD_APPEND,                         /* append messages to a file */
124    MD_STDOUT,                         /* print messages */
125    MD_STDERR,                         /* print messages to stderr */
126    MD_DIRECTOR,                       /* send message to the Director */
127    MD_OPERATOR,                       /* email a single message to the operator */
128    MD_CONSOLE,                        /* send msg to UserAgent or console */
129    MD_MAIL_ON_ERROR,                  /* email messages if job errors */
130    MD_MAIL_ON_SUCCESS,                /* email messages if job succeeds */
131    MD_CATALOG                         /* sent to catalog Log table */
132 };
133
134 /* Queued message item */
135 struct MQUEUE_ITEM {
136    dlink link;
137    int type;
138    utime_t mtime;
139    char msg[1];
140 };
141
142  
143 void d_msg(const char *file, int line, int level, const char *fmt,...);
144 void e_msg(const char *file, int line, int type, int level, const char *fmt,...);
145 void Jmsg(JCR *jcr, int type, utime_t mtime, const char *fmt,...);
146 void Qmsg(JCR *jcr, int type, utime_t mtime, const char *fmt,...);
147 bool get_trace(void);
148 const char *get_basename(const char *pathname);
149
150 class B_DB;
151 typedef bool (*sql_query_func)(JCR *jcr, const char *cmd);
152 typedef bool (*sql_escape_func)(JCR *jcr, B_DB *db, char *snew, char *old, int len);
153
154 extern DLL_IMP_EXP sql_query_func     p_sql_query;
155 extern DLL_IMP_EXP sql_escape_func    p_sql_escape;
156
157 extern DLL_IMP_EXP int           debug_level;
158 extern DLL_IMP_EXP bool          dbg_timestamp;          /* print timestamp in debug output */
159 extern DLL_IMP_EXP bool          prt_kaboom;             /* Print kaboom output */
160 extern DLL_IMP_EXP int           verbose;
161 extern DLL_IMP_EXP char          my_name[];
162 extern DLL_IMP_EXP const char   *assert_msg;             /* Assert error message */
163 extern DLL_IMP_EXP const char *  working_directory;
164 extern DLL_IMP_EXP utime_t       daemon_start_time;
165
166 extern DLL_IMP_EXP int           console_msg_pending;
167 extern DLL_IMP_EXP FILE *        con_fd;                 /* Console file descriptor */
168 extern DLL_IMP_EXP brwlock_t     con_lock;               /* Console lock structure */