1 /*
2 BAREOS® - Backup Archiving REcovery Open Sourced
3
4 Copyright (C) 2000-2010 Free Software Foundation Europe e.V.
5 Copyright (C) 2011-2012 Planets Communications B.V.
6 Copyright (C) 2013-2019 Bareos GmbH & Co. KG
7
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 Affero 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 /**
24 * @file
25 * General header file configurations that apply to
26 * all daemons. System dependent stuff goes here.
27 *
28 */
29
30
31 #ifndef BAREOS_INCLUDE_BACONFIG_H_
32 #define BAREOS_INCLUDE_BACONFIG_H_ 1
33
34 #include "lib/message.h"
35
36 /* Bareos common configuration defines */
37
38 #undef TRUE
39 #undef FALSE
40 #define TRUE 1
41 #define FALSE 0
42
43 #ifdef HAVE_TLS
44 #define have_tls 1
45 #else
46 #define have_tls 0
47 #endif
48
49 #ifndef ETIME
50 #define ETIME ETIMEDOUT
51 #endif
52
53 #ifdef HAVE_IOCTL_ULINT_REQUEST
54 #define ioctl_req_t unsigned long int
55 #else
56 #define ioctl_req_t int
57 #endif
58
59
60 #ifdef PROTOTYPES
61 #define __PROTO(p) p
62 #else
63 #define __PROTO(p) ()
64 #endif
65
66 /**
67 * In DEBUG mode an assert that is triggered generates a segmentation
68 * fault so we can capture the debug info using btraceback.
69 */
70 #define ASSERT(x) \
71 if (!(x)) { \
72 char* fatal = NULL; \
73 Emsg1(M_ERROR, 0, _("Failed ASSERT: %s\n"), #x); \
74 Pmsg1(000, _("Failed ASSERT: %s\n"), #x); \
75 fatal[0] = 0; \
76 }
77 #define ASSERT2(x, y) \
78 if (!(x)) { \
79 assert_msg = y; \
80 Emsg1(M_ERROR, 0, _("Failed ASSERT: %s\n"), #x); \
81 Pmsg1(000, _("Failed ASSERT: %s\n"), #x); \
82 char* fatal = NULL; \
83 fatal[0] = 0; \
84 }
85
86 /**
87 * Allow printing of NULL pointers
88 */
89 #define NPRT(x) (x) ? (x) : _("*None*")
90 #define NSTDPRNT(x) x.empty() ? "*None*" : x.c_str()
91 #define NPRTB(x) (x) ? (x) : ""
92
93 #if defined(HAVE_WIN32)
94 /**
95 * Reduce compiler warnings from Windows vss code
96 */
97 #define uuid(x)
98
99 void InitWinAPIWrapper();
100
101 #define OSDependentInit() InitWinAPIWrapper()
102
103 #define ClearThreadId(x) memset(&(x), 0, sizeof(x))
104
105 #else /* HAVE_WIN32 */
106
107 #define ClearThreadId(x) x = 0
108 #define OSDependentInit()
109
110 #endif /* HAVE_WIN32 */
111
112 #ifdef ENABLE_NLS
113 #include <libintl.h>
114 #include <locale.h>
115 #ifndef _
116 #define _(s) gettext((s))
117 #endif /* _ */
118 #ifndef N_
119 #define N_(s) (s)
120 #endif /* N_ */
121 #else /* !ENABLE_NLS */
122 #include <locale.h>
123 #undef _
124 #undef N_
125 #undef textdomain
126 #undef bindtextdomain
127
128 #ifndef _
129 #define _(s) (s)
130 #endif
131 #ifndef N_
132 #define N_(s) (s)
133 #endif
134 #ifndef textdomain
135 #define textdomain(d)
136 #endif
137 #ifndef bindtextdomain
138 #define bindtextdomain(p, d)
139 #endif
140 #endif /* ENABLE_NLS */
141
142
143 /* Use the following for strings not to be translated */
144 #define NT_(s) (s)
145
146 /* Maximum length to edit time/date */
147 #define MAX_TIME_LENGTH 50
148
149 /* Maximum Name length including EOS */
150 #define MAX_NAME_LENGTH 128
151
152 /* Maximum escaped Name length including EOS 2*MAX_NAME_LENGTH+1 */
153 #define MAX_ESCAPE_NAME_LENGTH 257
154
155 /* Maximum number of user entered command args */
156 #define MAX_CMD_ARGS 30
157
158 /* All tape operations MUST be a multiple of this */
159 #define TAPE_BSIZE 1024
160
161 /* Maximum length of a hostname */
162 #ifndef MAXHOSTNAMELEN
163 #define MAXHOSTNAMELEN 256
164 #endif
165
166 /* Default length of passphrases used */
167 #define DEFAULT_PASSPHRASE_LENGTH 32
168
169 #ifdef DEV_BSIZE
170 #define B_DEV_BSIZE DEV_BSIZE
171 #endif
172
173 #if !defined(B_DEV_BSIZE) & defined(BSIZE)
174 #define B_DEV_BSIZE BSIZE
175 #endif
176
177 #ifndef B_DEV_BSIZE
178 #define B_DEV_BSIZE 512
179 #endif
180
181 /**
182 * Set to time limit for other end to respond to
183 * authentication. Normally 10 minutes is *way*
184 * more than enough. The idea is to keep the Director
185 * from hanging because there is a dead connection on
186 * the other end.
187 */
188 #define AUTH_TIMEOUT 60 * 10
189
190 /**
191 * Default network buffer size
192 */
193 #define DEFAULT_NETWORK_BUFFER_SIZE (64 * 1024)
194
195 /**
196 * Tape label types -- stored in catalog
197 */
198 #define B_BAREOS_LABEL 0
199 #define B_ANSI_LABEL 1
200 #define B_IBM_LABEL 2
201
202 /**
203 * Actions on purge (bit mask)
204 */
205 #define ON_PURGE_NONE 0
206 #define ON_PURGE_TRUNCATE 1
207
208 /* Size of File Address stored in STREAM_SPARSE_DATA. Do NOT change! */
209 #define OFFSET_FADDR_SIZE (sizeof(uint64_t))
210
211 /* Size of crypto length stored at head of crypto buffer. Do NOT change! */
212 #define CRYPTO_LEN_SIZE ((int)sizeof(uint32_t))
213
214
215 /**
216 * This is for dumb compilers/libraries like Solaris. Linux GCC
217 * does it correctly, so it might be worthwhile
218 * to remove the isascii(c) with ifdefs on such
219 * "smart" systems.
220 */
221 #define B_ISSPACE(c) (isascii((int)(c)) && isspace((int)(c)))
222 #define B_ISALPHA(c) (isascii((int)(c)) && isalpha((int)(c)))
223 #define B_ISUPPER(c) (isascii((int)(c)) && isupper((int)(c)))
224 #define B_ISDIGIT(c) (isascii((int)(c)) && isdigit((int)(c)))
225
226 /** For multiplying by 10 with shift and addition */
227 #define B_TIMES10(d) ((d << 3) + (d << 1))
228
229
230 typedef void(HANDLER)();
231 typedef int(INTHANDLER)();
232
233 #ifdef SETPGRP_VOID
234 #define SETPGRP_ARGS(x, y) /* No arguments */
235 #else
236 #define SETPGRP_ARGS(x, y) (x, y)
237 #endif
238
239 #ifndef S_ISLNK
240 #define S_ISLNK(m) (((m)&S_IFM) == S_IFLNK)
241 #endif
242
243 /** Added by KES to deal with Win32 systems */
244 #ifndef S_ISWIN32
245 #define S_ISWIN32 020000
246 #endif
247
248 #ifndef INADDR_NONE
249 #define INADDR_NONE ((unsigned long)-1)
250 #endif
251
252 #ifdef TIME_WITH_SYS_TIME
253 #include <sys/time.h>
254 #include <time.h>
255 #else
256 #ifdef HAVE_SYS_TIME_H
257 #include <sys/time.h>
258 #else
259 #include <time.h>
260 #endif
261 #endif
262
263 #ifndef O_BINARY
264 #define O_BINARY 0
265 #endif
266
267 #ifndef O_NOFOLLOW
268 #define O_NOFOLLOW 0
269 #endif
270
271 #ifndef MODE_RW
272 #define MODE_RW 0666
273 #endif
274
275 #if defined(HAVE_WIN32)
276 typedef int64_t boffset_t;
277 #define caddr_t char*
278 #else
279 typedef off_t boffset_t;
280 #endif
281
282 typedef uint16_t slot_number_t;
283 typedef uint16_t drive_number_t;
284 typedef uint16_t slot_flags_t;
285
286 #include <limits>
287
288 constexpr slot_number_t kInvalidSlotNumber =
289 std::numeric_limits<slot_number_t>::max();
290 constexpr slot_number_t kInvalidDriveNumber =
291 std::numeric_limits<drive_number_t>::max();
292
IsSlotNumberValid(slot_number_t slot)293 inline bool IsSlotNumberValid(slot_number_t slot)
294 {
295 return slot && slot != kInvalidSlotNumber;
296 }
297
298 /* These probably should be subroutines */
299 #define Pw(x) \
300 do { \
301 int errstat; \
302 if ((errstat = RwlWritelock(&(x)))) \
303 e_msg(__FILE__, __LINE__, M_ABORT, 0, \
304 "Write lock lock failure. ERR=%s\n", strerror(errstat)); \
305 } while (0)
306
307 #define Vw(x) \
308 do { \
309 int errstat; \
310 if ((errstat = RwlWriteunlock(&(x)))) \
311 e_msg(__FILE__, __LINE__, M_ABORT, 0, \
312 "Write lock unlock failure. ERR=%s\n", strerror(errstat)); \
313 } while (0)
314
315 /**
316 * As of C++11 varargs macros are part of the standard.
317 * We keep the kludgy versions for backwards compatability for now
318 * but they're going to go away soon.
319 */
320 /** Debug Messages that are printed */
321 #define Dmsg0(lvl, ...) \
322 if ((lvl) <= debug_level) d_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
323 #define Dmsg1(lvl, ...) \
324 if ((lvl) <= debug_level) d_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
325 #define Dmsg2(lvl, ...) \
326 if ((lvl) <= debug_level) d_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
327 #define Dmsg3(lvl, ...) \
328 if ((lvl) <= debug_level) d_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
329 #define Dmsg4(lvl, ...) \
330 if ((lvl) <= debug_level) d_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
331 #define Dmsg5(lvl, ...) \
332 if ((lvl) <= debug_level) d_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
333 #define Dmsg6(lvl, ...) \
334 if ((lvl) <= debug_level) d_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
335 #define Dmsg7(lvl, ...) \
336 if ((lvl) <= debug_level) d_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
337 #define Dmsg8(lvl, ...) \
338 if ((lvl) <= debug_level) d_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
339 #define Dmsg9(lvl, ...) \
340 if ((lvl) <= debug_level) d_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
341 #define Dmsg10(lvl, ...) \
342 if ((lvl) <= debug_level) d_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
343 #define Dmsg11(lvl, ...) \
344 if ((lvl) <= debug_level) d_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
345 #define Dmsg12(lvl, ...) \
346 if ((lvl) <= debug_level) d_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
347 #define Dmsg13(lvl, ...) \
348 if ((lvl) <= debug_level) d_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
349
350 /** Messages that are printed (uses p_msg) */
351 #define Pmsg0(lvl, ...) p_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
352 #define Pmsg1(lvl, ...) p_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
353 #define Pmsg2(lvl, ...) p_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
354 #define Pmsg3(lvl, ...) p_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
355 #define Pmsg4(lvl, ...) p_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
356 #define Pmsg5(lvl, ...) p_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
357 #define Pmsg6(lvl, ...) p_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
358 #define Pmsg7(lvl, ...) p_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
359 #define Pmsg8(lvl, ...) p_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
360 #define Pmsg9(lvl, ...) p_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
361 #define Pmsg10(lvl, ...) p_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
362 #define Pmsg11(lvl, ...) p_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
363 #define Pmsg12(lvl, ...) p_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
364 #define Pmsg13(lvl, ...) p_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
365 #define Pmsg14(lvl, ...) p_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
366 #define Pmsg15(lvl, ...) p_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
367
368 /** Messages that are printed using fixed size buffers (uses p_msg_fb) */
369 #define FPmsg0(lvl, ...) p_msg_fb(__FILE__, __LINE__, lvl, __VA_ARGS__)
370 #define FPmsg1(lvl, ...) p_msg_fb(__FILE__, __LINE__, lvl, __VA_ARGS__)
371 #define FPmsg2(lvl, ...) p_msg_fb(__FILE__, __LINE__, lvl, __VA_ARGS__)
372 #define FPmsg3(lvl, ...) p_msg_fb(__FILE__, __LINE__, lvl, __VA_ARGS__)
373 #define FPmsg4(lvl, ...) p_msg_fb(__FILE__, __LINE__, lvl, __VA_ARGS__)
374 #define FPmsg5(lvl, ...) p_msg_fb(__FILE__, __LINE__, lvl, __VA_ARGS__)
375 #define FPmsg6(lvl, ...) p_msg_fb(__FILE__, __LINE__, lvl, __VA_ARGS__)
376
377 /** Daemon Error Messages that are delivered according to the message resource
378 */
379 #define Emsg0(typ, lvl, ...) e_msg(__FILE__, __LINE__, typ, lvl, __VA_ARGS__)
380 #define Emsg1(typ, lvl, ...) e_msg(__FILE__, __LINE__, typ, lvl, __VA_ARGS__)
381 #define Emsg2(typ, lvl, ...) e_msg(__FILE__, __LINE__, typ, lvl, __VA_ARGS__)
382 #define Emsg3(typ, lvl, ...) e_msg(__FILE__, __LINE__, typ, lvl, __VA_ARGS__)
383 #define Emsg4(typ, lvl, ...) e_msg(__FILE__, __LINE__, typ, lvl, __VA_ARGS__)
384 #define Emsg5(typ, lvl, ...) e_msg(__FILE__, __LINE__, typ, lvl, __VA_ARGS__)
385 #define Emsg6(typ, lvl, ...) e_msg(__FILE__, __LINE__, typ, lvl, __VA_ARGS__)
386
387 /** Job Error Messages that are delivered according to the message resource */
388 #define Jmsg0(jcr, typ, lvl, ...) \
389 j_msg(__FILE__, __LINE__, jcr, typ, lvl, __VA_ARGS__)
390 #define Jmsg1(jcr, typ, lvl, ...) \
391 j_msg(__FILE__, __LINE__, jcr, typ, lvl, __VA_ARGS__)
392 #define Jmsg2(jcr, typ, lvl, ...) \
393 j_msg(__FILE__, __LINE__, jcr, typ, lvl, __VA_ARGS__)
394 #define Jmsg3(jcr, typ, lvl, ...) \
395 j_msg(__FILE__, __LINE__, jcr, typ, lvl, __VA_ARGS__)
396 #define Jmsg4(jcr, typ, lvl, ...) \
397 j_msg(__FILE__, __LINE__, jcr, typ, lvl, __VA_ARGS__)
398 #define Jmsg5(jcr, typ, lvl, ...) \
399 j_msg(__FILE__, __LINE__, jcr, typ, lvl, __VA_ARGS__)
400 #define Jmsg6(jcr, typ, lvl, ...) \
401 j_msg(__FILE__, __LINE__, jcr, typ, lvl, __VA_ARGS__)
402 #define Jmsg7(jcr, typ, lvl, ...) \
403 j_msg(__FILE__, __LINE__, jcr, typ, lvl, __VA_ARGS__)
404 #define Jmsg8(jcr, typ, lvl, ...) \
405 j_msg(__FILE__, __LINE__, jcr, typ, lvl, __VA_ARGS__)
406
407 /** Queued Job Error Messages that are delivered according to the message
408 * resource */
409 #define Qmsg0(jcr, typ, lvl, ...) \
410 q_msg(__FILE__, __LINE__, jcr, typ, lvl, __VA_ARGS__)
411 #define Qmsg1(jcr, typ, lvl, ...) \
412 q_msg(__FILE__, __LINE__, jcr, typ, lvl, __VA_ARGS__)
413 #define Qmsg2(jcr, typ, lvl, ...) \
414 q_msg(__FILE__, __LINE__, jcr, typ, lvl, __VA_ARGS__)
415 #define Qmsg3(jcr, typ, lvl, ...) \
416 q_msg(__FILE__, __LINE__, jcr, typ, lvl, __VA_ARGS__)
417 #define Qmsg4(jcr, typ, lvl, ...) \
418 q_msg(__FILE__, __LINE__, jcr, typ, lvl, __VA_ARGS__)
419 #define Qmsg5(jcr, typ, lvl, ...) \
420 q_msg(__FILE__, __LINE__, jcr, typ, lvl, __VA_ARGS__)
421 #define Qmsg6(jcr, typ, lvl, ...) \
422 q_msg(__FILE__, __LINE__, jcr, typ, lvl, __VA_ARGS__)
423
424 /** Memory Messages that are edited into a Pool Memory buffer */
425 #define Mmsg0(buf, ...) msg_(__FILE__, __LINE__, buf, __VA_ARGS__)
426 #define Mmsg1(buf, ...) msg_(__FILE__, __LINE__, buf, __VA_ARGS__)
427 #define Mmsg2(buf, ...) msg_(__FILE__, __LINE__, buf, __VA_ARGS__)
428 #define Mmsg3(buf, ...) msg_(__FILE__, __LINE__, buf, __VA_ARGS__)
429 #define Mmsg4(buf, ...) msg_(__FILE__, __LINE__, buf, __VA_ARGS__)
430 #define Mmsg5(buf, ...) msg_(__FILE__, __LINE__, buf, __VA_ARGS__)
431 #define Mmsg6(buf, ...) msg_(__FILE__, __LINE__, buf, __VA_ARGS__)
432 #define Mmsg7(buf, ...) msg_(__FILE__, __LINE__, buf, __VA_ARGS__)
433 #define Mmsg8(buf, ...) msg_(__FILE__, __LINE__, buf, __VA_ARGS__)
434 #define Mmsg9(buf, ...) msg_(__FILE__, __LINE__, buf, __VA_ARGS__)
435 #define Mmsg10(buf, ...) msg_(__FILE__, __LINE__, buf, __VA_ARGS__)
436 #define Mmsg11(buf, ...) msg_(__FILE__, __LINE__, buf, __VA_ARGS__)
437 #define Mmsg12(buf, ...) msg_(__FILE__, __LINE__, buf, __VA_ARGS__)
438 #define Mmsg13(buf, ...) msg_(__FILE__, __LINE__, buf, __VA_ARGS__)
439 #define Mmsg14(buf, ...) msg_(__FILE__, __LINE__, buf, __VA_ARGS__)
440 #define Mmsg15(buf, ...) msg_(__FILE__, __LINE__, buf, __VA_ARGS__)
441
442 class PoolMem;
443
444 /* Edit message into Pool Memory buffer -- no __FILE__ and __LINE__ */
445 int Mmsg(POOLMEM*& msgbuf, const char* fmt, ...);
446 int Mmsg(PoolMem& msgbuf, const char* fmt, ...);
447 int Mmsg(PoolMem*& msgbuf, const char* fmt, ...);
448 int Mmsg(std::vector<char>& msgbuf, const char* fmt, ...);
449
450 class JobControlRecord;
451 void d_msg(const char* file, int line, int level, const char* fmt, ...);
452 void p_msg(const char* file, int line, int level, const char* fmt, ...);
453 void p_msg_fb(const char* file, int line, int level, const char* fmt, ...);
454 void e_msg(const char* file,
455 int line,
456 int type,
457 int level,
458 const char* fmt,
459 ...);
460 void j_msg(const char* file,
461 int line,
462 JobControlRecord* jcr,
463 int type,
464 utime_t mtime,
465 const char* fmt,
466 ...);
467 void q_msg(const char* file,
468 int line,
469 JobControlRecord* jcr,
470 int type,
471 utime_t mtime,
472 const char* fmt,
473 ...);
474 int msg_(const char* file, int line, POOLMEM*& pool_buf, const char* fmt, ...);
475
476 #include "lib/bsys.h"
477 #include "lib/scan.h"
478
479 /** Use our fgets which handles interrupts */
480 #undef fgets
481 #define fgets(x, y, z) bfgets((x), (y), (z))
482
483 /** Use our sscanf, which is safer and works with known sizes */
484 #define sscanf bsscanf
485
486 /** Macro to simplify free/reset pointers */
487 #define BfreeAndNull(a) \
488 do { \
489 if (a) { \
490 free(a); \
491 (a) = NULL; \
492 } \
493 } while (0)
494
495 /**
496 * Replace codes needed in both file routines and non-file routines
497 * Job replace codes -- in "replace"
498 */
499 #define REPLACE_ALWAYS 'a'
500 #define REPLACE_IFNEWER 'w'
501 #define REPLACE_NEVER 'n'
502 #define REPLACE_IFOLDER 'o'
503
504 /** This probably should be done on a machine by machine basis, but it works */
505 /** This is critical for the memory allocation routines to properly align memory
506 */
507 #define ALIGN_SIZE (sizeof(double))
508 #define BALIGN(x) (((x) + ALIGN_SIZE - 1) & ~(ALIGN_SIZE - 1))
509
510
511 /* =============================================================
512 * OS Dependent defines
513 * =============================================================
514 */
515 #ifndef HAVE_WIN32
516 #if defined(__digital__) && defined(__unix__)
517 /* Tru64 - it does have fseeko and ftello , but since ftell/fseek are also 64
518 * bit */
519 /* take this 'shortcut' */
520 #define fseeko fseek
521 #define ftello ftell
522 #else
523 #ifndef HAVE_FSEEKO
524 /* Bad news. This OS cannot handle 64 bit fseeks and ftells */
525 #define fseeko fseek
526 #define ftello ftell
527 #endif
528 #endif /* __digital__ && __unix__ */
529 #endif /* HAVE_WIN32 */
530
531 #ifdef HAVE_SUN_OS
532 /**
533 * On Solaris 2.5/2.6/7 and 8, threads are not timesliced by default,
534 * so we need to explictly increase the concurrency level.
535 */
536 #ifdef USE_THR_SETCONCURRENCY
537 #include <thread.h>
538 #define SetThreadConcurrency(x) ThrSetconcurrency(x)
539 extern int ThrSetconcurrency(int);
540 #define SunOS 1
541 #else
542 #define SetThreadConcurrency(x)
543 #endif
544
545 #else
546 /**
547 * Not needed on most systems
548 */
549 #define SetThreadConcurrency(x)
550
551 #endif
552
553 #ifdef HAVE_DARWIN_OS
554 /* Apparently someone forgot to wrap Getdomainname as a C function */
555 #ifdef __cplusplus
556 extern "C" {
557 #endif /* __cplusplus */
558 int Getdomainname(char* name, int len);
559 #ifdef __cplusplus
560 }
561 #endif /* __cplusplus */
562 #endif /* HAVE_DARWIN_OS */
563
564 #define TRACEFILEDIRECTORY working_directory ? working_directory : "c:"
565
566 #if defined(HAVE_WIN32)
567 /**
568 * Windows
569 */
570 #define DEFAULT_CONFIGDIR \
571 "C:\\Documents and Settings\\All Users\\Application Data\\Bareos"
572 #define PathSeparator '\\'
573
IsPathSeparator(int ch)574 inline bool IsPathSeparator(int ch) { return ch == '/' || ch == '\\'; }
first_path_separator(char * path)575 inline char* first_path_separator(char* path) { return strpbrk(path, "/\\"); }
first_path_separator(const char * path)576 inline const char* first_path_separator(const char* path)
577 {
578 return strpbrk(path, "/\\");
579 }
580
581 extern void PauseMsg(const char* file,
582 const char* func,
583 int line,
584 const char* msg);
585 #define pause(msg) \
586 if (debug_level) PauseMsg(__FILE__, __func__, __LINE__, (msg))
587
588 #else
589 /**
590 * Unix/Linux
591 */
592 #define PathSeparator '/'
593
594 /* Define Winsock functions if we aren't on Windows */
WSA_Init()595 inline int WSA_Init() { return (0); } /* 0 = success */
WSACleanup()596 inline int WSACleanup() { return (0); } /* 0 = success */
597
IsPathSeparator(int ch)598 inline bool IsPathSeparator(int ch) { return ch == '/'; }
first_path_separator(char * path)599 inline char* first_path_separator(char* path) { return strchr(path, '/'); }
first_path_separator(const char * path)600 inline const char* first_path_separator(const char* path)
601 {
602 return strchr(path, '/');
603 }
604 #define pause(msg)
605 #endif
606
607
608 /** HP-UX 11 specific workarounds */
609
610 #ifdef HAVE_HPUX_OS
611 #undef h_errno
612 extern int h_errno;
613 /** the {get,set}domainname() functions exist in HPUX's libc.
614 * the configure script detects that correctly.
615 * the problem is no system headers declares the prototypes for these functions
616 * this is done below
617 */
618 #ifdef __cplusplus
619 extern "C" {
620 #endif /* __cplusplus */
621 int Getdomainname(char* name, int namelen);
622 int Setdomainname(char* name, int namelen);
623 #ifdef __cplusplus
624 }
625 #endif /* __cplusplus */
626 #endif /* HAVE_HPUX_OS */
627
628
629 #ifdef HAVE_OSF1_OS
630 #ifdef __cplusplus
631 extern "C" {
632 #endif /* __cplusplus */
633 int fchdir(int filedes);
634 long gethostid(void);
635 int Getdomainname(char* name, int len);
636 #ifdef __cplusplus
637 }
638 #endif /* __cplusplus */
639 #endif /* HAVE_OSF1_OS */
640
641
642 /** Disabled because it breaks internationalisation...
643 #undef HAVE_SETLOCALE
644 #ifdef HAVE_SETLOCALE
645 #include <locale.h>
646 #else
647 #define setlocale(x, y) ("ANSI_X3.4-1968")
648 #endif
649 #ifdef HAVE_NL_LANGINFO
650 #include <langinfo.h>
651 #else
652 #define nl_langinfo(x) ("ANSI_X3.4-1968")
653 #endif
654 */
655
656 /** Determine endianes */
bigendian()657 static inline bool bigendian() { return htonl(1) == 1L; }
658
659 #ifndef __GNUC__
660 #define __PRETTY_FUNCTION__ __func__
661 #endif
662 #ifdef ENTER_LEAVE
663 #define Enter(lvl) Dmsg1(lvl, "Enter: %s\n", __PRETTY_FUNCTION__)
664 #define Leave(lvl) Dmsg1(lvl, "Leave: %s\n", __PRETTY_FUNCTION__)
665 #else
666 #define Enter(lvl)
667 #define Leave(lvl)
668 #endif
669
670 #endif /* BAREOS_INCLUDE_BACONFIG_H_ */
671