2 Bacula® - The Network Backup Solution
4 Copyright (C) 2004-2014 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from many
7 others, a complete list can be found in the file AUTHORS.
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.
14 Bacula® is a registered trademark of Kern Sibbald.
17 * Bacula errno handler
19 * berrno is a simplistic errno handler that works for
20 * Unix, Win32, and Bacula bpipes.
22 * See berrno.h for how to use berrno.
24 * Written by Kern Sibbald, July MMIV
32 extern const char *get_signal_name(int sig);
33 extern int num_execvp_errors;
34 extern int execvp_errors[];
37 const char *berrno::bstrerror()
41 if (m_berrno & (b_errno_win32)) {
42 format_win32_message();
43 return (const char *)m_buf;
48 if (m_berrno & b_errno_exit) {
49 stat = (m_berrno & ~b_errno_exit); /* remove bit */
51 return _("Child exited normally."); /* this really shouldn't happen */
53 /* Maybe an execvp failure */
55 if (stat < 200 + num_execvp_errors) {
56 m_berrno = execvp_errors[stat - 200];
58 return _("Unknown error during program execvp");
61 Mmsg(m_buf, _("Child exited with code %d"), stat);
64 /* If we drop out here, m_berrno is set to an execvp errno */
67 if (m_berrno & b_errno_signal) {
68 stat = (m_berrno & ~b_errno_signal); /* remove bit */
69 Mmsg(m_buf, _("Child died from signal %d: %s"), stat, get_signal_name(stat));
74 if (b_strerror(m_berrno, m_buf, sizeof_pool_memory(m_buf)) < 0) {
75 return _("Invalid errno. No error message possible.");
80 void berrno::format_win32_message()
84 FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
85 FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
88 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
92 pm_strcpy(&m_buf, (const char *)msg);