2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2016 Kern Sibbald
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.
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 This notice must be preserved when any source code is
15 conveyed and/or propagated.
17 Bacula(R) is a registered trademark of Kern Sibbald.
20 * Bacula errno handler
22 * berrno is a simplistic errno handler that works for
23 * Unix, Win32, and Bacula bpipes.
25 * See berrno.h for how to use berrno.
27 * Kern Sibbald, July MMIV
35 extern const char *get_signal_name(int sig);
36 extern int num_execvp_errors;
37 extern int execvp_errors[];
40 const char *berrno::bstrerror()
44 if (m_berrno & (b_errno_win32 | b_errno_WSA)) {
45 format_win32_message();
46 return (const char *)m_buf;
51 if (m_berrno & b_errno_exit) {
52 stat = (m_berrno & ~b_errno_exit); /* remove bit */
54 return _("Child exited normally."); /* this really shouldn't happen */
56 /* Maybe an execvp failure */
58 if (stat < 200 + num_execvp_errors) {
59 m_berrno = execvp_errors[stat - 200];
61 return _("Unknown error during program execvp");
64 Mmsg(m_buf, _("Child exited with code %d"), stat);
67 /* If we drop out here, m_berrno is set to an execvp errno */
70 if (m_berrno & b_errno_signal) {
71 stat = (m_berrno & ~b_errno_signal); /* remove bit */
72 Mmsg(m_buf, _("Child died from signal %d: %s"), stat, get_signal_name(stat));
77 if (b_strerror(m_berrno, m_buf, sizeof_pool_memory(m_buf)) < 0) {
78 return _("Invalid errno. No error message possible.");
83 void berrno::format_win32_message()
87 FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
88 FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
90 m_berrno & b_errno_WSA ? WSAGetLastError() : GetLastError(),
91 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
95 pm_strcpy(&m_buf, (const char *)msg);