if ((errstat=rwl_writelock(&mdb->lock)) != 0) {
berrno be;
e_msg(file, line, M_FATAL, 0, "rwl_writelock failure. stat=%d: ERR=%s\n",
- errstat, be.strerror(errstat));
+ errstat, be.bstrerror(errstat));
}
}
if ((errstat=rwl_writeunlock(&mdb->lock)) != 0) {
berrno be;
e_msg(file, line, M_FATAL, 0, "rwl_writeunlock failure. stat=%d: ERR=%s\n",
- errstat, be.strerror(errstat));
+ errstat, be.bstrerror(errstat));
}
}
for (i=0; my_glob.gl_pathv[i]; i++) {
fname = my_glob.gl_pathv[i];
if (lstat(fname, &statp) < 0) {
- printf("Cannot stat %s: %s\n", fname, strerror(errno));
+ berrno be;
+ printf("Cannot stat %s: %s\n", fname, be.bstrerror(errno));
continue;
}
encode_stat(where, &statp);
const char *berrno::bstrerror()
{
#ifdef HAVE_WIN32
- if (berrno_ & b_errno_win32) {
- return (const char *)buf_;
+ if (m_berrno & b_errno_win32) {
+ return (const char *)m_buf;
}
#else
int stat = 0;
- if (berrno_ & b_errno_exit) {
- stat = (berrno_ & ~b_errno_exit); /* remove bit */
+ if (m_berrno & b_errno_exit) {
+ stat = (m_berrno & ~b_errno_exit); /* remove bit */
if (stat == 0) {
return _("Child exited normally."); /* this really shouldn't happen */
} else {
/* Maybe an execvp failure */
if (stat >= 200) {
if (stat < 200 + num_execvp_errors) {
- berrno_ = execvp_errors[stat - 200];
+ m_berrno = execvp_errors[stat - 200];
} else {
return _("Unknown error during program execvp");
}
} else {
- Mmsg(buf_, _("Child exited with code %d"), stat);
- return buf_;
+ Mmsg(m_buf, _("Child exited with code %d"), stat);
+ return m_buf;
}
- /* If we drop out here, berrno_ is set to an execvp errno */
+ /* If we drop out here, m_berrno is set to an execvp errno */
}
}
- if (berrno_ & b_errno_signal) {
- stat = (berrno_ & ~b_errno_signal); /* remove bit */
- Mmsg(buf_, _("Child died from signal %d: %s"), stat, get_signal_name(stat));
- return buf_;
+ if (m_berrno & b_errno_signal) {
+ stat = (m_berrno & ~b_errno_signal); /* remove bit */
+ Mmsg(m_buf, _("Child died from signal %d: %s"), stat, get_signal_name(stat));
+ return m_buf;
}
#endif
/* Normal errno */
- if (b_strerror(berrno_, buf_, 1024) < 0) {
+ if (b_strerror(m_berrno, m_buf, 1024) < 0) {
return _("Invalid errno. No error message possible.");
}
- return buf_;
+ return m_buf;
}
void berrno::format_win32_message()
{
#ifdef HAVE_WIN32
LPVOID msg;
- if (berrno_ & b_errno_win32) {
+ if (m_berrno & b_errno_win32) {
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
0,
NULL);
- pm_strcpy(&buf_, (const char *)msg);
+ pm_strcpy(&m_buf, (const char *)msg);
LocalFree(msg);
}
#endif
* for editing the message. strerror() does the actual editing, and
* it is thread safe.
*
- * If bit 29 in berrno_ is set then it is a Win32 error, and we
+ * If bit 29 in m_berrno is set then it is a Win32 error, and we
* must do a GetLastError() to get the error code for formatting.
- * If bit 29 in berrno_ is not set, then it is a Unix errno.
+ * If bit 29 in m_berrno is not set, then it is a Unix errno.
*
*/
class berrno : public SMARTALLOC {
- POOLMEM *buf_;
- int berrno_;
+ POOLMEM *m_buf;
+ int m_berrno;
void format_win32_message();
public:
berrno(int pool=PM_EMSG);
~berrno();
- const char *strerror() { return bstrerror(); };
const char *bstrerror();
- const char *strerror(int errnum) { return bstrerror(errnum); };
const char *bstrerror(int errnum);
void set_errno(int errnum);
- int code() { return berrno_ & ~(b_errno_exit|b_errno_signal); }
+ int code() { return m_berrno & ~(b_errno_exit|b_errno_signal); }
int code(int stat) { return stat & ~(b_errno_exit|b_errno_signal); }
};
/* Constructor */
inline berrno::berrno(int pool)
{
- berrno_ = errno;
- buf_ = get_pool_memory(pool);
+ m_berrno = errno;
+ m_buf = get_pool_memory(pool);
#ifdef HAVE_WIN32
format_win32_message();
#endif
inline berrno::~berrno()
{
- free_pool_memory(buf_);
+ free_pool_memory(m_buf);
}
inline const char *berrno::bstrerror(int errnum)
{
- berrno_ = errnum;
+ m_berrno = errnum;
return berrno::bstrerror();
}
inline void berrno::set_errno(int errnum)
{
- berrno_ = errnum;
+ m_berrno = errnum;
}
berrno be;
bsock->b_errno = errno;
Qmsg1(bsock->jcr(), M_FATAL, 0, _("Attr spool write error. ERR=%s\n"),
- be.strerror());
+ be.bstrerror());
Dmsg2(400, "nwritten=%d nbytes=%d.\n", nwritten, nbytes);
errno = bsock->b_errno;
return -1;
berrno be;
switch (h_errno) {
case NETDB_INTERNAL:
- msg = be.strerror();
+ msg = be.bstrerror();
break;
case NETDB_SUCCESS:
msg = _("No problem.");
save_errno = errno;
*fatal = 1;
Pmsg3(000, _("Socket open error. proto=%d port=%d. ERR=%s\n"),
- ipaddr->get_family(), ipaddr->get_port_host_order(), be.strerror());
+ ipaddr->get_family(), ipaddr->get_port_host_order(), be.bstrerror());
continue;
}
/*
if (setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, (sockopt_val_t)&turnon, sizeof(turnon)) < 0) {
berrno be;
Qmsg1(jcr, M_WARNING, 0, _("Cannot set SO_KEEPALIVE on socket: %s\n"),
- be.strerror());
+ be.bstrerror());
}
#if defined(TCP_KEEPIDLE)
if (heart_beat) {
if (setsockopt(sockfd, IPPROTO_IP, TCP_KEEPIDLE, (sockopt_val_t)&opt, sizeof(opt)) < 0) {
berrno be;
Qmsg1(jcr, M_WARNING, 0, _("Cannot set SO_KEEPIDLE on socket: %s\n"),
- be.strerror());
+ be.bstrerror());
}
}
#endif
if (setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, (sockopt_val_t)&turnon, sizeof(turnon)) < 0) {
berrno be;
Qmsg1(jcr, M_WARNING, 0, _("Cannot set SO_KEEPALIVE on socket: %s\n"),
- be.strerror());
+ be.bstrerror());
}
BSOCK* ret = init_bsock(jcr, sockfd, name, host, port, ipaddr->get_sockaddr());
free_addresses(addr_list);
btimer_t *tid = NULL;
/* Try to trap out of OS call when time expires */
- tid = start_thread_timer(pthread_self(), (uint32_t)max_retry_time);
+ if (max_retry_time) {
+ tid = start_thread_timer(pthread_self(), (uint32_t)max_retry_time);
+ }
for (i = 0; (bsock = bnet_open(jcr, name, host, service, port, heart_beat, &fatal)) == NULL;
i -= retry_interval) {
goto bail_out;
}
Dmsg4(100, "Unable to connect to %s on %s:%d. ERR=%s\n",
- name, host, port, be.strerror());
+ name, host, port, be.bstrerror());
if (i < 0) {
i = 60 * 5; /* complain again in 5 minutes */
if (verbose)
Qmsg4(jcr, M_WARNING, 0, _(
"Could not connect to %s on %s:%d. ERR=%s\n"
- "Retrying ...\n"), name, host, port, be.strerror());
+ "Retrying ...\n"), name, host, port, be.bstrerror());
}
bmicrosleep(retry_interval, 0);
now = time(NULL);
if (begin_time + max_retry_time <= now) {
Qmsg4(jcr, M_FATAL, 0, _("Unable to connect to %s on %s:%d. ERR=%s\n"),
- name, host, port, be.strerror());
+ name, host, port, be.bstrerror());
bsock = NULL;
goto bail_out;
}
if (bsock->errmsg == NULL) {
bsock->errmsg = get_pool_memory(PM_MESSAGE);
}
- pm_strcpy(bsock->errmsg, be.strerror(bsock->b_errno));
+ pm_strcpy(bsock->errmsg, be.bstrerror(bsock->b_errno));
return bsock->errmsg;
}
while ((dbuf_size > TAPE_BSIZE) && (setsockopt(bs->fd, SOL_SOCKET,
SO_RCVBUF, (sockopt_val_t) & dbuf_size, sizeof(dbuf_size)) < 0)) {
berrno be;
- Qmsg1(bs->jcr(), M_ERROR, 0, _("sockopt error: %s\n"), be.strerror());
+ Qmsg1(bs->jcr(), M_ERROR, 0, _("sockopt error: %s\n"), be.bstrerror());
dbuf_size -= TAPE_BSIZE;
}
Dmsg1(200, "set network buffer size=%d\n", dbuf_size);
while ((dbuf_size > TAPE_BSIZE) && (setsockopt(bs->fd, SOL_SOCKET,
SO_SNDBUF, (sockopt_val_t) & dbuf_size, sizeof(dbuf_size)) < 0)) {
berrno be;
- Qmsg1(bs->jcr(), M_ERROR, 0, _("sockopt error: %s\n"), be.strerror());
+ Qmsg1(bs->jcr(), M_ERROR, 0, _("sockopt error: %s\n"), be.bstrerror());
dbuf_size -= TAPE_BSIZE;
}
Dmsg1(900, "set network buffer size=%d\n", dbuf_size);
/* Get current flags */
if ((oflags = fcntl(bsock->fd, F_GETFL, 0)) < 0) {
berrno be;
- Jmsg1(bsock->jcr(), M_ABORT, 0, _("fcntl F_GETFL error. ERR=%s\n"), be.strerror());
+ Jmsg1(bsock->jcr(), M_ABORT, 0, _("fcntl F_GETFL error. ERR=%s\n"), be.bstrerror());
}
/* Set O_NONBLOCK flag */
if ((fcntl(bsock->fd, F_SETFL, oflags|O_NONBLOCK)) < 0) {
berrno be;
- Jmsg1(bsock->jcr(), M_ABORT, 0, _("fcntl F_SETFL error. ERR=%s\n"), be.strerror());
+ Jmsg1(bsock->jcr(), M_ABORT, 0, _("fcntl F_SETFL error. ERR=%s\n"), be.bstrerror());
}
bsock->blocking = 0;
/* Get current flags */
if ((oflags = fcntl(bsock->fd, F_GETFL, 0)) < 0) {
berrno be;
- Jmsg1(bsock->jcr(), M_ABORT, 0, _("fcntl F_GETFL error. ERR=%s\n"), be.strerror());
+ Jmsg1(bsock->jcr(), M_ABORT, 0, _("fcntl F_GETFL error. ERR=%s\n"), be.bstrerror());
}
/* Set O_NONBLOCK flag */
if ((fcntl(bsock->fd, F_SETFL, oflags & ~O_NONBLOCK)) < 0) {
berrno be;
- Jmsg1(bsock->jcr(), M_ABORT, 0, _("fcntl F_SETFL error. ERR=%s\n"), be.strerror());
+ Jmsg1(bsock->jcr(), M_ABORT, 0, _("fcntl F_SETFL error. ERR=%s\n"), be.bstrerror());
}
bsock->blocking = 1;
#ifndef HAVE_WIN32
if ((fcntl(bsock->fd, F_SETFL, flags)) < 0) {
berrno be;
- Jmsg1(bsock->jcr(), M_ABORT, 0, _("fcntl F_SETFL error. ERR=%s\n"), be.strerror());
+ Jmsg1(bsock->jcr(), M_ABORT, 0, _("fcntl F_SETFL error. ERR=%s\n"), be.bstrerror());
}
bsock->blocking = (flags & O_NONBLOCK);
- /*
- * Originally written by Kern Sibbald for inclusion in apcupsd,
- * but heavily modified for Bacula
- *
- * Version $Id$
- */
-
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
+ Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
The main author of Bacula is Kern Sibbald, with contributions from
many others, a complete list can be found in the file AUTHORS.
(FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
Switzerland, email:ftf@fsfeurope.org.
*/
-
+ /*
+ * Originally written by Kern Sibbald for inclusion in apcupsd,
+ * but heavily modified for Bacula
+ *
+ * Version $Id$
+ */
#include "bacula.h"
#include <netinet/in.h>
berrno be;
char curbuf[256];
Emsg3(M_ABORT, 0, _("Cannot open stream socket. ERR=%s. Current %s All %s\n"),
- be.strerror(),
+ be.bstrerror(),
p->build_address_str(curbuf, sizeof(curbuf)),
build_addresses_str(addrs, allbuf, sizeof(allbuf)));
}
sizeof(turnon)) < 0) {
berrno be;
Emsg1(M_WARNING, 0, _("Cannot set SO_REUSEADDR on socket: %s\n"),
- be.strerror());
+ be.bstrerror());
}
int tmax = 30 * (60 / 5); /* wait 30 minutes max */
if (tlog <= 0) {
tlog = 2 * 60; /* Complain every 2 minutes */
Emsg2(M_WARNING, 0, _("Cannot bind port %d: ERR=%s: Retrying ...\n"),
- ntohs(fd_ptr->port), be.strerror());
+ ntohs(fd_ptr->port), be.bstrerror());
}
bmicrosleep(5, 0);
if (--tmax <= 0) {
Emsg2(M_ABORT, 0, _("Cannot bind port %d: ERR=%s.\n"), ntohs(fd_ptr->port),
- be.strerror());
+ be.bstrerror());
}
}
listen(fd_ptr->fd, 5); /* tell system we are ready */
if ((stat = workq_init(client_wq, max_clients, handle_client_request)) != 0) {
berrno be;
be.set_errno(stat);
- Emsg1(M_ABORT, 0, _("Could not init client queue: ERR=%s\n"), be.strerror());
+ Emsg1(M_ABORT, 0, _("Could not init client queue: ERR=%s\n"), be.bstrerror());
}
/*
* Wait for a connection from the client process.
foreach_dlist(fd_ptr, &sockfds) {
close(fd_ptr->fd);
}
- Emsg1(M_FATAL, 0, _("Error in select: %s\n"), be.strerror());
+ Emsg1(M_FATAL, 0, _("Error in select: %s\n"), be.bstrerror());
break;
}
sizeof(turnon)) < 0) {
berrno be;
Emsg1(M_WARNING, 0, _("Cannot set SO_KEEPALIVE on socket: %s\n"),
- be.strerror());
+ be.bstrerror());
}
/* see who client is. i.e. who connected to us. */
berrno be;
be.set_errno(stat);
Jmsg1(NULL, M_ABORT, 0, _("Could not add job to client queue: ERR=%s\n"),
- be.strerror());
+ be.bstrerror());
}
}
}
berrno be;
be.set_errno(stat);
Emsg1(M_FATAL, 0, _("Could not destroy client queue: ERR=%s\n"),
- be.strerror());
+ be.bstrerror());
}
}
* Open a TCP socket
*/
for (tlog = 0; (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0; tlog -= 10) {
+ berrno be;
if (errno == EINTR || errno == EAGAIN) {
continue;
}
if (tlog <= 0) {
tlog = 2 * 60;
- Emsg1(M_ERROR, 0, _("Cannot open stream socket: %s\n"), strerror(errno));
+ Emsg1(M_ERROR, 0, _("Cannot open stream socket: %s\n"), be.bstrerror());
}
bmicrosleep(60, 0);
}
* Reuse old sockets
*/
if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (sockopt_val_t)&turnon, sizeof(turnon)) < 0) {
+ berrno be;
Emsg1(M_WARNING, 0, _("Cannot set SO_REUSEADDR on socket: %s\n"),
- strerror(errno));
+ be.bstrerror());
}
/*
if (tlog <= 0) {
tlog = 2 * 60;
Emsg2(M_WARNING, 0, _("Cannot bind port %d: ERR=%s: retrying ...\n"), port,
- be.strerror());
+ be.bstrerror());
}
bmicrosleep(5, 0);
}
*/
ready = sockset;
if ((stat = select(bsock->fd + 1, &ready, NULL, NULL, NULL)) < 0) {
+ berrno be;
if (errno == EINTR || errno = EAGAIN) {
errno = 0;
continue;
}
- Emsg1(M_FATAL, 0, _("Error in select: %s\n"), strerror(errno));
+ Emsg1(M_FATAL, 0, _("Error in select: %s\n"), be.bstrerror());
newsockfd = -1;
break;
}
* Receive notification when connection dies.
*/
if (setsockopt(newsockfd, SOL_SOCKET, SO_KEEPALIVE, (sockopt_val_t)&turnon, sizeof(turnon)) < 0) {
+ berrno be;
Emsg1(M_WARNING, 0, _("Cannot set SO_KEEPALIVE on socket: %s\n"),
- strerror(errno));
+ be.bstrerror());
}
/* see who client is. I.e. who connected to us.
bsock->msglen = strlen(bsock->msg);
if (newsockfd < 0) {
+ berrno be;
Emsg2(M_FATAL, 0, _("Socket accept error for %s. ERR=%s\n"), who,
- strerror(errno));
+ be.bstrerror());
return NULL;
} else {
if (caller == NULL) {
wpid = waitpid(bpipe->worker_pid, &chldstatus, wait_option);
} while (wpid == -1 && (errno == EINTR || errno == EAGAIN));
if (wpid == bpipe->worker_pid || wpid == -1) {
+ berrno be;
stat = errno;
Dmsg3(800, "Got break wpid=%d status=%d ERR=%s\n", wpid, chldstatus,
- wpid==-1?strerror(errno):"none");
+ wpid==-1?be.bstrerror():"none");
break;
}
Dmsg3(800, "Got wpid=%d status=%d ERR=%s\n", wpid, chldstatus,
stat1 = ferror(bpipe->rfd);
}
if (stat1 < 0) {
- Dmsg2(150, "Run program fgets stat=%d ERR=%s\n", stat1, strerror(errno));
+ berrno be;
+ Dmsg2(150, "Run program fgets stat=%d ERR=%s\n", stat1, be.bstrerror(errno));
} else if (stat1 != 0) {
Dmsg1(150, "Run program fgets stat=%d\n", stat1);
if (bpipe->timer_id) {
}
if (stat1 < 0) {
berrno be;
- Dmsg2(200, "Run program fgets stat=%d ERR=%s\n", stat1, be.strerror());
+ Dmsg2(200, "Run program fgets stat=%d ERR=%s\n", stat1, be.bstrerror());
break;
} else if (stat1 != 0) {
Dmsg1(900, "Run program fgets stat=%d\n", stat1);
berrno be;
Dmsg2(400, "nbytes=%d msglen=%d\n", nbytes, msglen);
Qmsg1(jcr(), M_FATAL, 0, _("fread attr spool error. ERR=%s\n"),
- be.strerror());
+ be.bstrerror());
update_attr_spool_size(tsize - last);
return false;
}
if (ferror(spool_fd)) {
berrno be;
Qmsg1(jcr(), M_FATAL, 0, _("fread attr spool error. ERR=%s\n"),
- be.strerror());
+ be.bstrerror());
return false;
}
return true;
if (stat != 0) {
berrno be;
Dmsg2(200, "pthread_cond_timedwait stat=%d ERR=%s\n", stat,
- be.strerror(stat));
+ be.bstrerror(stat));
}
V(timer_mutex);
return stat;
#endif
if (buf == NULL) {
berrno be;
- Emsg1(M_ABORT, 0, _("Out of memory: ERR=%s\n"), be.strerror());
+ Emsg1(M_ABORT, 0, _("Out of memory: ERR=%s\n"), be.bstrerror());
}
return buf;
}
#endif
if (buf == NULL) {
berrno be;
- e_msg(file, line, M_ABORT, 0, _("Out of memory: ERR=%s\n"), be.strerror());
+ e_msg(file, line, M_ABORT, 0, _("Out of memory: ERR=%s\n"), be.bstrerror());
}
return buf;
}
buf = realloc(buf, size);
if (buf == NULL) {
berrno be;
- Emsg1(M_ABORT, 0, _("Out of memory: ERR=%s\n"), be.strerror());
+ Emsg1(M_ABORT, 0, _("Out of memory: ERR=%s\n"), be.bstrerror());
}
return buf;
}
buf = calloc(size1, size2);
if (buf == NULL) {
berrno be;
- Emsg1(M_ABORT, 0, _("Out of memory: ERR=%s\n"), be.strerror());
+ Emsg1(M_ABORT, 0, _("Out of memory: ERR=%s\n"), be.bstrerror());
}
return buf;
}
if ((errstat=pthread_mutex_lock(m))) {
berrno be;
e_msg(file, line, M_ABORT, 0, _("Mutex lock failure. ERR=%s\n"),
- be.strerror(errstat));
+ be.bstrerror(errstat));
} else {
e_msg(file, line, M_ERROR, 0, _("Possible mutex deadlock resolved.\n"));
}
if ((errstat=pthread_mutex_trylock(m)) == 0) {
berrno be;
e_msg(file, line, M_ERROR, 0, _("Mutex unlock not locked. ERR=%s\n"),
- be.strerror(errstat));
+ be.bstrerror(errstat));
}
if ((errstat=pthread_mutex_unlock(m))) {
berrno be;
e_msg(file, line, M_ABORT, 0, _("Mutex unlock failure. ERR=%s\n"),
- be.strerror(errstat));
+ be.bstrerror(errstat));
}
}
if ((errstat=pthread_mutex_lock(m))) {
berrno be;
e_msg(__FILE__, __LINE__, M_ABORT, 0, _("Mutex lock failure. ERR=%s\n"),
- be.strerror(errstat));
+ be.bstrerror(errstat));
}
}
if ((errstat=pthread_mutex_unlock(m))) {
berrno be;
e_msg(__FILE__, __LINE__, M_ABORT, 0, _("Mutex unlock failure. ERR=%s\n"),
- be.strerror(errstat));
+ be.bstrerror(errstat));
}
}
unlink(fname);
if ((sfd = open(fname, O_CREAT|O_WRONLY|O_BINARY, 0640)) < 0) {
berrno be;
- Dmsg2(000, "Could not create state file. %s ERR=%s\n", fname, be.strerror());
- Emsg2(M_ERROR, 0, _("Could not create state file. %s ERR=%s\n"), fname, be.strerror());
+ Dmsg2(000, "Could not create state file. %s ERR=%s\n", fname, be.bstrerror());
+ Emsg2(M_ERROR, 0, _("Could not create state file. %s ERR=%s\n"), fname, be.bstrerror());
goto bail_out;
}
if (write(sfd, &state_hdr, sizeof(state_hdr)) != sizeof(state_hdr)) {
berrno be;
- Dmsg1(000, "Write hdr error: ERR=%s\n", be.strerror());
+ Dmsg1(000, "Write hdr error: ERR=%s\n", be.bstrerror());
goto bail_out;
}
// Dmsg1(010, "Wrote header of %d bytes\n", sizeof(state_hdr));
// Dmsg1(010, "write last job end = %d\n", (int)state_hdr.reserved[0]);
if (lseek(sfd, 0, SEEK_SET) < 0) {
berrno be;
- Dmsg1(000, "lseek error: ERR=%s\n", be.strerror());
+ Dmsg1(000, "lseek error: ERR=%s\n", be.bstrerror());
goto bail_out;
}
if (write(sfd, &state_hdr, sizeof(state_hdr)) != sizeof(state_hdr)) {
berrno be;
- Pmsg1(000, _("Write final hdr error: ERR=%s\n"), be.strerror());
+ Pmsg1(000, _("Write final hdr error: ERR=%s\n"), be.bstrerror());
goto bail_out;
}
ok = true;
if ((passw = getpwnam(uname)) == NULL) {
berrno be;
Emsg2(M_ERROR_TERM, 0, _("Could not find userid=%s: ERR=%s\n"), uname,
- be.strerror());
+ be.bstrerror());
}
} else {
if ((passw = getpwuid(getuid())) == NULL) {
berrno be;
Emsg1(M_ERROR_TERM, 0, _("Could not find password entry. ERR=%s\n"),
- be.strerror());
+ be.bstrerror());
} else {
uname = passw->pw_name;
}
if ((group = getgrnam(gname)) == NULL) {
berrno be;
Emsg2(M_ERROR_TERM, 0, _("Could not find group=%s: ERR=%s\n"), gname,
- be.strerror());
+ be.bstrerror());
}
gid = group->gr_gid;
}
berrno be;
if (gname) {
Emsg3(M_ERROR_TERM, 0, _("Could not initgroups for group=%s, userid=%s: ERR=%s\n"),
- gname, username, be.strerror());
+ gname, username, be.bstrerror());
} else {
Emsg2(M_ERROR_TERM, 0, _("Could not initgroups for userid=%s: ERR=%s\n"),
- username, be.strerror());
+ username, be.bstrerror());
}
}
if (gname) {
if (setgid(gid)) {
berrno be;
Emsg2(M_ERROR_TERM, 0, _("Could not set group=%s: ERR=%s\n"), gname,
- be.strerror());
+ be.bstrerror());
}
}
if (setuid(uid)) {
-/*
- * daemon.c by Kern Sibbald
- *
- * Version $Id$
- *
- * this code is inspired by the Prentice Hall book
- * "Unix Network Programming" by W. Richard Stevens
- * and later updated from his book "Advanced Programming
- * in the UNIX Environment"
- *
- * Initialize a daemon process completely detaching us from
- * any terminal processes.
- *
- */
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
+ Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
The main author of Bacula is Kern Sibbald, with contributions from
many others, a complete list can be found in the file AUTHORS.
(FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
Switzerland, email:ftf@fsfeurope.org.
*/
+/*
+ * daemon.c by Kern Sibbald
+ *
+ * Version $Id$
+ *
+ * this code is inspired by the Prentice Hall book
+ * "Unix Network Programming" by W. Richard Stevens
+ * and later updated from his book "Advanced Programming
+ * in the UNIX Environment"
+ *
+ * Initialize a daemon process completely detaching us from
+ * any terminal processes.
+ *
+ */
#include "bacula.h"
Dmsg0(900, "Enter daemon_start\n");
if ( (cpid = fork() ) < 0) {
berrno be;
- Emsg1(M_ABORT, 0, _("Cannot fork to become daemon: %s\n"), be.strerror());
+ Emsg1(M_ABORT, 0, _("Cannot fork to become daemon: %s\n"), be.bstrerror());
} else if (cpid > 0) {
exit(0); /* parent exits */
}
}
for ( ; num; num--) {
if (read(fd, &job, sizeof(job)) != sizeof(job)) {
- Dmsg1(000, "Read job entry. ERR=%s\n", strerror(errno));
+ berrno be;
+ Pmsg1(000, "Read job entry. ERR=%s\n", be.bstrerror());
return false;
}
if (job.JobId > 0) {
/* First record is number of entires */
num = last_jobs->size();
if (write(fd, &num, sizeof(num)) != sizeof(num)) {
- Dmsg1(000, "Error writing num_items: ERR=%s\n", strerror(errno));
+ berrno be;
+ Pmsg1(000, "Error writing num_items: ERR=%s\n", be.bstrerror());
return 0;
}
foreach_dlist(je, last_jobs) {
if (write(fd, je, sizeof(struct s_last_job)) != sizeof(struct s_last_job)) {
- Dmsg1(000, "Error writing job: ERR=%s\n", strerror(errno));
+ berrno be;
+ Pmsg1(000, "Error writing job: ERR=%s\n", be.bstrerror());
return 0;
}
}
#endif
{
#ifdef TRACE_JCR_CHAIN
- Dmsg3(3400, "Lock jcr chain %d from %s:%d\n", ++lock_count,
- fname, line);
+ Dmsg3(3400, "Lock jcr chain %d from %s:%d\n", ++lock_count, fname, line);
#endif
P(jcr_lock);
}
#endif
{
#ifdef TRACE_JCR_CHAIN
- Dmsg3(3400, "Unlock jcr chain %d from %s:%d\n", lock_count--,
- fname, line);
+ Dmsg3(3400, "Unlock jcr chain %d from %s:%d\n", lock_count--, fname, line);
#endif
V(jcr_lock);
}
jcr = (JCR *)jcrs->first();
if (jcr) {
jcr->inc_use_count();
- Dmsg3(3400, "Inc jcr_walk_start 0x%x job=%d use_count=%d\n", jcr,
- jcr->JobId, jcr->use_count());
+ Dmsg3(3400, "Inc jcr_walk_start 0x%x job=%d use_count=%d\n", jcr, jcr->JobId, jcr->use_count());
}
unlock_jcr_chain();
return jcr;
jcr = (JCR *)jcrs->next(prev_jcr);
if (jcr) {
jcr->inc_use_count();
- Dmsg3(3400, "Inc jcr_walk_next 0x%x job=%d use_count=%d\n", jcr,
- jcr->JobId, jcr->use_count());
+ Dmsg3(3400, "Inc jcr_walk_next 0x%x job=%d use_count=%d\n", jcr, jcr->JobId, jcr->use_count());
}
unlock_jcr_chain();
if (prev_jcr) {
if (lf == NULL) {
berrno be;
scan_err2(lfori, _("Cannot open included config file %s: %s\n"),
- lfori->str, be.strerror());
+ lfori->str, be.bstrerror());
return T_ERROR;
}
break;
if (fd == -1) {
berrno be;
Emsg2(M_ERROR_TERM, 0, _("Could not open console message file %s: ERR=%s\n"),
- con_fname, be.strerror());
+ con_fname, be.bstrerror());
}
if (lseek(fd, 0, SEEK_END) > 0) {
console_msg_pending = 1;
if (!con_fd) {
berrno be;
Emsg2(M_ERROR, 0, _("Could not open console message file %s: ERR=%s\n"),
- con_fname, be.strerror());
+ con_fname, be.bstrerror());
}
if (rwl_init(&con_lock) != 0) {
berrno be;
Emsg1(M_ERROR_TERM, 0, _("Could not get con mutex: ERR=%s\n"),
- be.strerror());
+ be.bstrerror());
}
}
if (!(bpipe = open_bpipe(cmd, 120, "rw"))) {
berrno be;
Jmsg(jcr, M_ERROR, 0, _("open mail pipe %s failed: ERR=%s\n"),
- cmd, be.strerror());
+ cmd, be.bstrerror());
}
/* If we had to use sendmail, add subject */
}
if (!close_wpipe(bpipe)) { /* close write pipe sending mail */
berrno be;
- Pmsg1(000, _("close error: ERR=%s\n"), be.strerror());
+ Pmsg1(000, _("close error: ERR=%s\n"), be.bstrerror());
}
/*
Dmsg1(850, "Calling emsg. CMD=%s\n", cmd);
Jmsg2(jcr, M_ERROR, 0, _("Mail program terminated in error.\n"
"CMD=%s\n"
- "ERR=%s\n"), cmd, be.strerror());
+ "ERR=%s\n"), cmd, be.bstrerror());
}
free_memory(line);
rem_temp_file:
berrno be;
d->fd = stdout;
Qmsg2(jcr, M_ERROR, 0, _("fopen %s failed: ERR=%s\n"), d->where,
- be.strerror());
+ be.bstrerror());
d->fd = NULL;
return false;
}
be.set_errno(stat);
Qmsg2(jcr, M_ERROR, 0, _("Operator mail program terminated in error.\n"
"CMD=%s\n"
- "ERR=%s\n"), mcmd, be.strerror());
+ "ERR=%s\n"), mcmd, be.bstrerror());
}
}
free_pool_memory(mcmd);
berrno be;
d->fd = stdout;
Qmsg2(jcr, M_ERROR, 0, _("fopen %s failed: ERR=%s\n"), name,
- be.strerror());
+ be.bstrerror());
d->fd = NULL;
free_pool_memory(name);
break;
dynlock = (struct CRYPTO_dynlock_value *) malloc(sizeof(struct CRYPTO_dynlock_value));
if ((stat = pthread_mutex_init(&dynlock->mutex, NULL)) != 0) {
- Emsg1(M_ABORT, 0, _("Unable to init mutex: ERR=%s\n"), strerror(stat));
+ berrno be;
+ Emsg1(M_ABORT, 0, _("Unable to init mutex: ERR=%s\n"), be.bstrerror(stat));
}
return dynlock;
int stat;
if ((stat = pthread_mutex_destroy(&dynlock->mutex)) != 0) {
- Emsg1(M_ABORT, 0, _("Unable to destroy mutex: ERR=%s\n"), strerror(stat));
+ berrno be;
+ Emsg1(M_ABORT, 0, _("Unable to destroy mutex: ERR=%s\n"), be.bstrerror(stat));
}
free(dynlock);
mutexes = (pthread_mutex_t *) malloc(numlocks * sizeof(pthread_mutex_t));
for (i = 0; i < numlocks; i++) {
if ((stat = pthread_mutex_init(&mutexes[i], NULL)) != 0) {
- Emsg1(M_ERROR, 0, _("Unable to init mutex: ERR=%s\n"), strerror(stat));
+ berrno be;
+ Emsg1(M_ERROR, 0, _("Unable to init mutex: ERR=%s\n"), be.bstrerror(stat));
return stat;
}
}
/*
* Clean up OpenSSL threading support
*/
-void openssl_cleanup_threads (void)
+void openssl_cleanup_threads(void)
{
int i, numlocks;
int stat;
numlocks = CRYPTO_num_locks();
for (i = 0; i < numlocks; i++) {
if ((stat = pthread_mutex_destroy(&mutexes[i])) != 0) {
+ berrno be;
/* We don't halt execution, reporting the error should be sufficient */
- Emsg1(M_ERROR, 0, _("Unable to destroy mutex: ERR=%s\n"), strerror(stat));
+ Emsg1(M_ERROR, 0, _("Unable to destroy mutex: ERR=%s\n"), be.bstrerror(stat));
}
}
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2000-20076 Free Software Foundation Europe e.V.
+ Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
The main author of Bacula is Kern Sibbald, with contributions from
many others, a complete list can be found in the file AUTHORS.
int errstat;
if (first && (errstat=rwl_init(&res_lock)) != 0) {
+ berrno be;
Emsg1(M_ABORT, 0, _("Unable to initialize resource lock. ERR=%s\n"),
- strerror(errstat));
+ be.bstrerror(errstat));
}
first = false;
bstrncpy(lc->str, cf, sizeof(lc->str));
lc->fname = lc->str;
scan_err2(lc, _("Cannot open config file \"%s\": %s\n"),
- lc->str, be.strerror());
+ lc->str, be.bstrerror());
free(lc);
return 0;
}
-/*
- *
- * Bacula common code library interface to Python
- *
- * Kern Sibbald, November MMIV
- *
- * Version $Id$
- *
- */
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2004-2006 Free Software Foundation Europe e.V.
+ Copyright (C) 2004-2007 Free Software Foundation Europe e.V.
The main author of Bacula is Kern Sibbald, with contributions from
many others, a complete list can be found in the file AUTHORS.
(FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
Switzerland, email:ftf@fsfeurope.org.
*/
+/*
+ *
+ * Bacula common code library interface to Python
+ *
+ * Kern Sibbald, November MMIV
+ *
+ * Version $Id$
+ *
+ */
#include "bacula.h"
#include "jcr.h"
if ((errstat=rwl_init(&python_rwlock)) != 0) {
berrno be;
Emsg1(M_ABORT, 0, _("Unable to initialize the Python lock. ERR=%s\n"),
- be.strerror(errstat));
+ be.bstrerror(errstat));
}
}
if ((errstat=rwl_writelock(&python_rwlock)) != 0) {
berrno be;
Emsg2(M_ABORT, 0, "Python rwl_writelock failure. stat=%d: ERR=%s\n",
- errstat, be.strerror(errstat));
+ errstat, be.bstrerror(errstat));
}
}
if ((errstat=rwl_writeunlock(&python_rwlock)) != 0) {
berrno be;
Emsg2(M_ABORT, 0, "Python rwl_writeunlock failure. stat=%d: ERR=%s\n",
- errstat, be.strerror(errstat));
+ errstat, be.bstrerror(errstat));
}
}
-/*
- * Manipulation routines for RunScript list
- *
- * Eric Bollengier, May 2006
- *
- * Version $Id$
- *
- */
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2006-2006 Free Software Foundation Europe e.V.
+ Copyright (C) 2006-2007 Free Software Foundation Europe e.V.
The main author of Bacula is Kern Sibbald, with contributions from
many others, a complete list can be found in the file AUTHORS.
(FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
Switzerland, email:ftf@fsfeurope.org.
*/
+/*
+ * Manipulation routines for RunScript list
+ *
+ * Eric Bollengier, May 2006
+ *
+ * Version $Id$
+ *
+ */
#include "bacula.h"
runit=false;
if ((script->when & SCRIPT_Before) && (when & SCRIPT_Before)) {
- if ( (script->on_success && (jcr->JobStatus == JS_Running || jcr->JobStatus == JS_Created))
- ||
- (script->on_failure && job_canceled(jcr))
- )
- {
- Dmsg4(200, "runscript: Run it because SCRIPT_Before (%s,%i,%i,%c)\n", script->command,
+ if ( (script->on_success && (jcr->JobStatus == JS_Running || jcr->JobStatus == JS_Created))
+ ||
+ (script->on_failure && job_canceled(jcr))
+ )
+ {
+ Dmsg4(200, "runscript: Run it because SCRIPT_Before (%s,%i,%i,%c)\n", script->command,
script->on_success,
script->on_failure,
jcr->JobStatus );
- runit = true;
- }
+ runit = true;
+ }
}
if ((script->when & SCRIPT_After) && (when & SCRIPT_After)) {
- if ( (script->on_success && (jcr->JobStatus == JS_Terminated))
- ||
- (script->on_failure && job_canceled(jcr))
- )
- {
- Dmsg4(200, "runscript: Run it because SCRIPT_After (%s,%i,%i,%c)\n", script->command,
+ if ( (script->on_success && (jcr->JobStatus == JS_Terminated))
+ ||
+ (script->on_failure && job_canceled(jcr))
+ )
+ {
+ Dmsg4(200, "runscript: Run it because SCRIPT_After (%s,%i,%i,%c)\n", script->command,
script->on_success,
script->on_failure,
jcr->JobStatus );
- runit = true;
- }
+ runit = true;
+ }
}
if (!script->is_local()) {
if (bpipe == NULL) {
berrno be;
Jmsg(jcr, M_ERROR, 0, _("Runscript: %s could not execute. ERR=%s\n"), name,
- be.strerror());
+ be.bstrerror());
return false;
}
while (fgets(line, sizeof(line), bpipe->rfd)) {
if (status != 0) {
berrno be;
Jmsg(jcr, M_ERROR, 0, _("Runscript: %s returned non-zero status=%d. ERR=%s\n"), name,
- be.code(status), be.strerror(status));
+ be.code(status), be.bstrerror(status));
return false;
}
return true;
-/*
- * Bacula Thread Read/Write locking code. It permits
- * multiple readers but only one writer. Note, however,
- * that the writer thread is permitted to make multiple
- * nested write lock calls.
- *
- * Kern Sibbald, January MMI
- *
- * Version $Id$
- *
- * This code adapted from "Programming with POSIX Threads", by
- * David R. Butenhof
- *
- */
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2001-2006 Free Software Foundation Europe e.V.
+ Copyright (C) 2001-2007 Free Software Foundation Europe e.V.
The main author of Bacula is Kern Sibbald, with contributions from
many others, a complete list can be found in the file AUTHORS.
(FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
Switzerland, email:ftf@fsfeurope.org.
*/
+/*
+ * Bacula Thread Read/Write locking code. It permits
+ * multiple readers but only one writer. Note, however,
+ * that the writer thread is permitted to make multiple
+ * nested write lock calls.
+ *
+ * Kern Sibbald, January MMI
+ *
+ * Version $Id$
+ *
+ * This code adapted from "Programming with POSIX Threads", by
+ * David R. Butenhof
+ *
+ */
#include "bacula.h"
if ((iteration % self->interval) == 0) {
status = rwl_writelock(&data[element].lock);
if (status != 0) {
- Emsg1(M_ABORT, 0, _("Write lock failed. ERR=%s\n"), strerror(status));
+ berrno be;
+ Emsg1(M_ABORT, 0, _("Write lock failed. ERR=%s\n"), be.bstrerror(status));
}
data[element].data = self->thread_num;
data[element].writes++;
self->writes++;
status = rwl_writeunlock(&data[element].lock);
if (status != 0) {
- Emsg1(M_ABORT, 0, _("Write unlock failed. ERR=%s\n"), strerror(status));
+ berrno be;
+ Emsg1(M_ABORT, 0, _("Write unlock failed. ERR=%s\n"), be.bstrerror(status));
}
} else {
/*
*/
status = rwl_readlock(&data[element].lock);
if (status != 0) {
- Emsg1(M_ABORT, 0, _("Read lock failed. ERR=%s\n"), strerror(status));
+ berrno be;
+ Emsg1(M_ABORT, 0, _("Read lock failed. ERR=%s\n"), be.bstrerror(status));
}
self->reads++;
if (data[element].data == self->thread_num)
repeats++;
status = rwl_readunlock(&data[element].lock);
if (status != 0) {
- Emsg1(M_ABORT, 0, _("Read unlock failed. ERR=%s\n"), strerror(status));
+ berrno be;
+ Emsg1(M_ABORT, 0, _("Read unlock failed. ERR=%s\n"), be.bstrerror(status));
}
}
element++;
data[data_count].writes = 0;
status = rwl_init (&data[data_count].lock);
if (status != 0) {
- Emsg1(M_ABORT, 0, _("Init rwlock failed. ERR=%s\n"), strerror(status));
+ berrno be;
+ Emsg1(M_ABORT, 0, _("Init rwlock failed. ERR=%s\n"), be.bstrerror(status));
}
}
status = pthread_create (&threads[count].thread_id,
NULL, thread_routine, (void*)&threads[count]);
if (status != 0) {
- Emsg1(M_ABORT, 0, _("Create thread failed. ERR=%s\n"), strerror(status));
+ berrno be;
+ Emsg1(M_ABORT, 0, _("Create thread failed. ERR=%s\n"), be.bstrerror(status));
}
}
for (count = 0; count < THREADS; count++) {
status = pthread_join (threads[count].thread_id, NULL);
if (status != 0) {
- Emsg1(M_ABORT, 0, _("Join thread failed. ERR=%s\n"), strerror(status));
+ berrno be;
+ Emsg1(M_ABORT, 0, _("Join thread failed. ERR=%s\n"), be.bstrerror(status));
}
thread_writes += threads[count].writes;
printf (_("%02d: interval %d, writes %d, reads %d\n"),
* sha1.c
*
* Description:
- * This file implements the Secure Hashing Algorithm 1 as
- * defined in FIPS PUB 180-1 published April 17, 1995.
+ * This file implements the Secure Hashing Algorithm 1 as
+ * defined in FIPS PUB 180-1 published April 17, 1995.
*
- * The SHA-1, produces a 160-bit message digest for a given
- * data stream. It should take about 2**n steps to find a
- * message with the same digest as a given message and
- * 2**(n/2) to find any two messages with the same digest,
- * when n is the digest size in bits. Therefore, this
- * algorithm can serve as a means of providing a
+ * The SHA-1, produces a 160-bit message digest for a given
+ * data stream. It should take about 2**n steps to find a
+ * message with the same digest as a given message and
+ * 2**(n/2) to find any two messages with the same digest,
+ * when n is the digest size in bits. Therefore, this
+ * algorithm can serve as a means of providing a
* "fingerprint" for a message.
*
* Portability Issues:
* SHA-1 is defined in terms of 32-bit "words". This code
* uses <stdint.h> (included via "sha1.h" to define 32 and 8
- * bit unsigned integer types. If your C compiler does not
- * support 32 bit unsigned integers, this code is not
- * appropriate.
+ * bit unsigned integer types. If your C compiler does not
+ * support 32 bit unsigned integers, this code is not
+ * appropriate.
*
* Caveats:
- * SHA-1 is designed to work with messages less than 2^64 bits
- * long. Although SHA-1 allows a message digest to be generated
- * for messages of any number of bits less than 2^64, this
- * implementation only works with messages with a length that is
- * a multiple of the size of an 8-bit character.
+ * SHA-1 is designed to work with messages less than 2^64 bits
+ * long. Although SHA-1 allows a message digest to be generated
+ * for messages of any number of bits less than 2^64, this
+ * implementation only works with messages with a length that is
+ * a multiple of the size of an 8-bit character.
*
* See sha1.h for copyright
*/
* Define the SHA1 circular left shift macro
*/
#define SHA1CircularShift(bits,word) \
- (((word) << (bits)) | ((word) >> (32-(bits))))
+ (((word) << (bits)) | ((word) >> (32-(bits))))
/* Local Function Prototyptes */
static void SHA1PadMessage(SHA1Context *);
* SHA1Init
*
* Description:
- * This function will initialize the SHA1Context in preparation
- * for computing a new SHA1 message digest.
+ * This function will initialize the SHA1Context in preparation
+ * for computing a new SHA1 message digest.
*
* Parameters:
- * context: [in/out]
- * The context to reset.
+ * context: [in/out]
+ * The context to reset.
*
* Returns:
- * sha Error Code.
+ * sha Error Code.
*
*/
int SHA1Init(SHA1Context *context)
{
if (!context)
{
- return shaNull;
+ return shaNull;
}
- context->Length_Low = 0;
- context->Length_High = 0;
+ context->Length_Low = 0;
+ context->Length_High = 0;
context->Message_Block_Index = 0;
context->Intermediate_Hash[0] = 0x67452301;
context->Intermediate_Hash[3] = 0x10325476;
context->Intermediate_Hash[4] = 0xC3D2E1F0;
- context->Computed = 0;
- context->Corrupted = 0;
+ context->Computed = 0;
+ context->Corrupted = 0;
return shaSuccess;
}
* SHA1Final
*
* Description:
- * This function will return the 160-bit message digest into the
- * Message_Digest array provided by the caller.
- * NOTE: The first octet of hash is stored in the 0th element,
- * the last octet of hash in the 19th element.
+ * This function will return the 160-bit message digest into the
+ * Message_Digest array provided by the caller.
+ * NOTE: The first octet of hash is stored in the 0th element,
+ * the last octet of hash in the 19th element.
*
* Parameters:
- * context: [in/out]
- * The context to use to calculate the SHA-1 hash.
- * Message_Digest: [out]
- * Where the digest is returned.
+ * context: [in/out]
+ * The context to use to calculate the SHA-1 hash.
+ * Message_Digest: [out]
+ * Where the digest is returned.
*
* Returns:
- * sha Error Code.
+ * sha Error Code.
*
*/
int SHA1Final(SHA1Context *context,
- uint8_t Message_Digest[SHA1HashSize])
+ uint8_t Message_Digest[SHA1HashSize])
{
int i;
if (!context || !Message_Digest) {
- return shaNull;
+ return shaNull;
}
if (context->Corrupted) {
- return context->Corrupted;
+ return context->Corrupted;
}
if (!context->Computed) {
- SHA1PadMessage(context);
- for(i=0; i<64; ++i) {
- /* message may be sensitive, clear it out */
- context->Message_Block[i] = 0;
- }
- context->Length_Low = 0; /* and clear length */
- context->Length_High = 0;
- context->Computed = 1;
+ SHA1PadMessage(context);
+ for(i=0; i<64; ++i) {
+ /* message may be sensitive, clear it out */
+ context->Message_Block[i] = 0;
+ }
+ context->Length_Low = 0; /* and clear length */
+ context->Length_High = 0;
+ context->Computed = 1;
}
for(i = 0; i < SHA1HashSize; ++i) {
- Message_Digest[i] = context->Intermediate_Hash[i>>2]
- >> 8 * ( 3 - ( i & 0x03 ) );
+ Message_Digest[i] = context->Intermediate_Hash[i>>2]
+ >> 8 * ( 3 - ( i & 0x03 ) );
}
return shaSuccess;
* SHA1Update
*
* Description:
- * This function accepts an array of octets as the next portion
- * of the message.
+ * This function accepts an array of octets as the next portion
+ * of the message.
*
* Parameters:
- * context: [in/out]
- * The SHA context to update
- * message_array: [in]
- * An array of characters representing the next portion of
- * the message.
- * length: [in]
- * The length of the message in message_array
+ * context: [in/out]
+ * The SHA context to update
+ * message_array: [in]
+ * An array of characters representing the next portion of
+ * the message.
+ * length: [in]
+ * The length of the message in message_array
*
* Returns:
- * sha Error Code.
+ * sha Error Code.
*
*/
int SHA1Update(SHA1Context *context,
- const uint8_t *message_array,
- unsigned length)
+ const uint8_t *message_array,
+ unsigned length)
{
if (!length) {
- return shaSuccess;
+ return shaSuccess;
}
if (!context || !message_array) {
- return shaNull;
+ return shaNull;
}
if (context->Computed) {
- context->Corrupted = shaStateError;
+ context->Corrupted = shaStateError;
- return shaStateError;
+ return shaStateError;
}
if (context->Corrupted) {
- return context->Corrupted;
+ return context->Corrupted;
}
while(length-- && !context->Corrupted) {
context->Message_Block[context->Message_Block_Index++] =
- (*message_array & 0xFF);
+ (*message_array & 0xFF);
context->Length_Low += 8;
if (context->Length_Low == 0) {
- context->Length_High++;
- if (context->Length_High == 0) {
- /* Message is too long */
- context->Corrupted = 1;
- }
+ context->Length_High++;
+ if (context->Length_High == 0) {
+ /* Message is too long */
+ context->Corrupted = 1;
+ }
}
if (context->Message_Block_Index == 64) {
- SHA1ProcessMessageBlock(context);
+ SHA1ProcessMessageBlock(context);
}
message_array++;
* SHA1ProcessMessageBlock
*
* Description:
- * This function will process the next 512 bits of the message
- * stored in the Message_Block array.
+ * This function will process the next 512 bits of the message
+ * stored in the Message_Block array.
*
* Parameters:
- * None.
+ * None.
*
* Returns:
- * Nothing.
+ * Nothing.
*
* Comments:
- * Many of the variable names in this code, especially the
- * single character names, were used because those were the
- * names used in the publication.
+ * Many of the variable names in this code, especially the
+ * single character names, were used because those were the
+ * names used in the publication.
*
*
*/
static void SHA1ProcessMessageBlock(SHA1Context *context)
{
- const uint32_t K[] = { /* Constants defined in SHA-1 */
- 0x5A827999,
- 0x6ED9EBA1,
- 0x8F1BBCDC,
- 0xCA62C1D6
- };
- int t; /* Loop counter */
- uint32_t temp; /* Temporary word value */
- uint32_t W[80]; /* Word sequence */
- uint32_t A, B, C, D, E; /* Word buffers */
+ const uint32_t K[] = { /* Constants defined in SHA-1 */
+ 0x5A827999,
+ 0x6ED9EBA1,
+ 0x8F1BBCDC,
+ 0xCA62C1D6
+ };
+ int t; /* Loop counter */
+ uint32_t temp; /* Temporary word value */
+ uint32_t W[80]; /* Word sequence */
+ uint32_t A, B, C, D, E; /* Word buffers */
/*
- * Initialize the first 16 words in the array W
+ * Initialize the first 16 words in the array W
*/
for(t = 0; t < 16; t++) {
- W[t] = context->Message_Block[t * 4] << 24;
- W[t] |= context->Message_Block[t * 4 + 1] << 16;
- W[t] |= context->Message_Block[t * 4 + 2] << 8;
- W[t] |= context->Message_Block[t * 4 + 3];
+ W[t] = context->Message_Block[t * 4] << 24;
+ W[t] |= context->Message_Block[t * 4 + 1] << 16;
+ W[t] |= context->Message_Block[t * 4 + 2] << 8;
+ W[t] |= context->Message_Block[t * 4 + 3];
}
for(t = 16; t < 80; t++) {
E = context->Intermediate_Hash[4];
for(t = 0; t < 20; t++) {
- temp = SHA1CircularShift(5,A) +
- ((B & C) | ((~B) & D)) + E + W[t] + K[0];
- E = D;
- D = C;
- C = SHA1CircularShift(30,B);
-
- B = A;
- A = temp;
+ temp = SHA1CircularShift(5,A) +
+ ((B & C) | ((~B) & D)) + E + W[t] + K[0];
+ E = D;
+ D = C;
+ C = SHA1CircularShift(30,B);
+
+ B = A;
+ A = temp;
}
for(t = 20; t < 40; t++) {
- temp = SHA1CircularShift(5,A) + (B ^ C ^ D) + E + W[t] + K[1];
- E = D;
- D = C;
- C = SHA1CircularShift(30,B);
- B = A;
- A = temp;
+ temp = SHA1CircularShift(5,A) + (B ^ C ^ D) + E + W[t] + K[1];
+ E = D;
+ D = C;
+ C = SHA1CircularShift(30,B);
+ B = A;
+ A = temp;
}
for(t = 40; t < 60; t++) {
- temp = SHA1CircularShift(5,A) +
- ((B & C) | (B & D) | (C & D)) + E + W[t] + K[2];
- E = D;
- D = C;
- C = SHA1CircularShift(30,B);
- B = A;
- A = temp;
+ temp = SHA1CircularShift(5,A) +
+ ((B & C) | (B & D) | (C & D)) + E + W[t] + K[2];
+ E = D;
+ D = C;
+ C = SHA1CircularShift(30,B);
+ B = A;
+ A = temp;
}
for(t = 60; t < 80; t++) {
- temp = SHA1CircularShift(5,A) + (B ^ C ^ D) + E + W[t] + K[3];
- E = D;
- D = C;
- C = SHA1CircularShift(30,B);
- B = A;
- A = temp;
+ temp = SHA1CircularShift(5,A) + (B ^ C ^ D) + E + W[t] + K[3];
+ E = D;
+ D = C;
+ C = SHA1CircularShift(30,B);
+ B = A;
+ A = temp;
}
context->Intermediate_Hash[0] += A;
*
* Description:
- * According to the standard, the message must be padded to an even
+ * According to the standard, the message must be padded to an even
* 512 bits. The first padding bit must be a '1'. The last 64
- * bits represent the length of the original message. All bits in
- * between should be 0. This function will pad the message
- * according to those rules by filling the Message_Block array
- * accordingly. It will also call the ProcessMessageBlock function
- * provided appropriately. When it returns, it can be assumed that
- * the message digest has been computed.
+ * bits represent the length of the original message. All bits in
+ * between should be 0. This function will pad the message
+ * according to those rules by filling the Message_Block array
+ * accordingly. It will also call the ProcessMessageBlock function
+ * provided appropriately. When it returns, it can be assumed that
+ * the message digest has been computed.
*
* Parameters:
- * context: [in/out]
- * The context to pad
- * ProcessMessageBlock: [in]
- * The appropriate SHA*ProcessMessageBlock function
+ * context: [in/out]
+ * The context to pad
+ * ProcessMessageBlock: [in]
+ * The appropriate SHA*ProcessMessageBlock function
* Returns:
- * Nothing.
+ * Nothing.
*
*/
static void SHA1PadMessage(SHA1Context *context)
{
/*
- * Check to see if the current message block is too small to hold
- * the initial padding bits and length. If so, we will pad the
- * block, process it, and then continue padding into a second
- * block.
+ * Check to see if the current message block is too small to hold
+ * the initial padding bits and length. If so, we will pad the
+ * block, process it, and then continue padding into a second
+ * block.
*/
if (context->Message_Block_Index > 55) {
- context->Message_Block[context->Message_Block_Index++] = 0x80;
- while(context->Message_Block_Index < 64) {
- context->Message_Block[context->Message_Block_Index++] = 0;
- }
+ context->Message_Block[context->Message_Block_Index++] = 0x80;
+ while(context->Message_Block_Index < 64) {
+ context->Message_Block[context->Message_Block_Index++] = 0;
+ }
- SHA1ProcessMessageBlock(context);
+ SHA1ProcessMessageBlock(context);
- while(context->Message_Block_Index < 56) {
- context->Message_Block[context->Message_Block_Index++] = 0;
- }
+ while(context->Message_Block_Index < 56) {
+ context->Message_Block[context->Message_Block_Index++] = 0;
+ }
} else {
- context->Message_Block[context->Message_Block_Index++] = 0x80;
- while(context->Message_Block_Index < 56) {
+ context->Message_Block[context->Message_Block_Index++] = 0x80;
+ while(context->Message_Block_Index < 56) {
- context->Message_Block[context->Message_Block_Index++] = 0;
- }
+ context->Message_Block[context->Message_Block_Index++] = 0;
+ }
}
/*
- * Store the message length as the last 8 octets
+ * Store the message length as the last 8 octets
*/
context->Message_Block[56] = context->Length_High >> 24;
context->Message_Block[57] = context->Length_High >> 16;
* sha1test.c
*
* Description:
- * This file will exercise the SHA-1 code performing the three
- * tests documented in FIPS PUB 180-1 plus one which calls
- * SHA1Input with an exact multiple of 512 bits, plus a few
- * error test checks.
+ * This file will exercise the SHA-1 code performing the three
+ * tests documented in FIPS PUB 180-1 plus one which calls
+ * SHA1Input with an exact multiple of 512 bits, plus a few
+ * error test checks.
*
* Portability Issues:
- * None.
+ * None.
*
*/
#define TEST2a "abcdbcdecdefdefgefghfghighijhi"
#define TEST2b "jkijkljklmklmnlmnomnopnopq"
-#define TEST2 TEST2a TEST2b
+#define TEST2 TEST2a TEST2b
#define TEST3 "a"
#define TEST4a "01234567012345670123456701234567"
#define TEST4b "01234567012345670123456701234567"
/* an exact multiple of 512 bits */
-#define TEST4 TEST4a TEST4b
+#define TEST4 TEST4a TEST4b
char *testarray[4] =
{
TEST1,
uint8_t Message_Digest[20];
/*
- * Perform SHA-1 tests
+ * Perform SHA-1 tests
*/
for(j = 0; j < 4; ++j) {
- printf( "\nTest %d: %d, '%s'\n",
- j+1,
- repeatcount[j],
- testarray[j]);
-
- err = SHA1Init(&sha);
- if (err) {
- fprintf(stderr, "SHA1Reset Error %d.\n", err );
- break; /* out of for j loop */
- }
-
- for(i = 0; i < repeatcount[j]; ++i) {
-
- err = SHA1Input(&sha,
- (const unsigned char *) testarray[j],
- strlen(testarray[j]));
- if (err) {
- fprintf(stderr, "SHA1Input Error %d.\n", err );
- break; /* out of for i loop */
- }
- }
-
- err = SHA1Final(&sha, Message_Digest);
- if (err) {
- fprintf(stderr,
- "SHA1Result Error %d, could not compute message digest.\n",
- err );
- }
- else
- {
- printf("\t");
- for(i = 0; i < 20 ; ++i) {
- printf("%02X ", Message_Digest[i]);
- }
- printf("\n");
- }
- printf("Should match:\n");
- printf("\t%s\n", resultarray[j]);
+ printf( "\nTest %d: %d, '%s'\n",
+ j+1,
+ repeatcount[j],
+ testarray[j]);
+
+ err = SHA1Init(&sha);
+ if (err) {
+ fprintf(stderr, "SHA1Reset Error %d.\n", err );
+ break; /* out of for j loop */
+ }
+
+ for(i = 0; i < repeatcount[j]; ++i) {
+
+ err = SHA1Input(&sha,
+ (const unsigned char *) testarray[j],
+ strlen(testarray[j]));
+ if (err) {
+ fprintf(stderr, "SHA1Input Error %d.\n", err );
+ break; /* out of for i loop */
+ }
+ }
+
+ err = SHA1Final(&sha, Message_Digest);
+ if (err) {
+ fprintf(stderr,
+ "SHA1Result Error %d, could not compute message digest.\n",
+ err );
+ }
+ else
+ {
+ printf("\t");
+ for(i = 0; i < 20 ; ++i) {
+ printf("%02X ", Message_Digest[i]);
+ }
+ printf("\n");
+ }
+ printf("Should match:\n");
+ printf("\t%s\n", resultarray[j]);
}
/* Test some error returns */
}
fd = fopen(argv[1], "rb");
if (!fd) {
- printf("Could not open %s: ERR=%s\n", argv[1], strerror(errno));
+ berrno be;
+ printf("Could not open %s: ERR=%s\n", argv[1], be.bstrerror(errno));
exit(1);
}
SHA1Init(&ctx);
-/*
- * Signal handlers for Bacula daemons
- *
- * Kern Sibbald, April 2000
- *
- * Version $Id$
- *
- * Note, we probably should do a core dump for the serious
- * signals such as SIGBUS, SIGPFE, ...
- * Also, for SIGHUP and SIGUSR1, we should re-read the
- * configuration file. However, since this is a "general"
- * routine, we leave it to the individual daemons to
- * tweek their signals after calling this routine.
- *
- */
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
+ Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
The main author of Bacula is Kern Sibbald, with contributions from
many others, a complete list can be found in the file AUTHORS.
(FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
Switzerland, email:ftf@fsfeurope.org.
*/
+/*
+ * Signal handlers for Bacula daemons
+ *
+ * Kern Sibbald, April 2000
+ *
+ * Version $Id$
+ *
+ * Note, we probably should do a core dump for the serious
+ * signals such as SIGBUS, SIGPFE, ...
+ * Also, for SIGHUP and SIGUSR1, we should re-read the
+ * configuration file. However, since this is a "general"
+ * routine, we leave it to the individual daemons to
+ * tweek their signals after calling this routine.
+ *
+ */
#ifndef HAVE_WIN32
#include "bacula.h"
}
if (chdir(working_directory) != 0) { /* dump in working directory */
berrno be;
- Pmsg2(000, "chdir to %s failed. ERR=%s\n", working_directory, be.strerror());
+ Pmsg2(000, "chdir to %s failed. ERR=%s\n", working_directory, be.bstrerror());
strcpy((char *)working_directory, "/tmp/");
}
unlink("./core"); /* get rid of any old core file */
-/*
- * Directory tree build/traverse routines
- *
- * Kern Sibbald, June MMII
- *
-*/
/*
Bacula® - The Network Backup Solution
(FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
Switzerland, email:ftf@fsfeurope.org.
*/
+/*
+ * Directory tree build/traverse routines
+ *
+ * Kern Sibbald, June MMII
+ *
+*/
#include "bacula.h"
bstrncpy(file, dir->d_name, sizeof(file));
snprintf(pathbuf, MAXPATHLEN-1, "%s/%s", path, file);
if (lstat(pathbuf, &statbuf) < 0) {
- printf("lstat() failed. ERR=%s\n", strerror(errno));
+ berrno be;
+ printf("lstat() failed. ERR=%s\n", be.bstrerror(errno));
continue;
}
// printf("got file=%s, pathbuf=%s\n", file, pathbuf);
watchdog_time = time(NULL);
if ((errstat=rwl_init(&lock)) != 0) {
+ berrno be;
Emsg1(M_ABORT, 0, _("Unable to initialize watchdog lock. ERR=%s\n"),
- strerror(errstat));
+ be.bstrerror(errstat));
}
wd_queue = New(dlist(dummy, &dummy->link));
wd_inactive = New(dlist(dummy, &dummy->link));
{
int errstat;
if ((errstat=rwl_writelock(&lock)) != 0) {
+ berrno be;
Emsg1(M_ABORT, 0, _("rwl_writelock failure. ERR=%s\n"),
- strerror(errstat));
+ be.bstrerror(errstat));
}
}
{
int errstat;
if ((errstat=rwl_writeunlock(&lock)) != 0) {
+ berrno be;
Emsg1(M_ABORT, 0, _("rwl_writeunlock failure. ERR=%s\n"),
- strerror(errstat));
+ be.bstrerror(errstat));
}
}
*
* Initialize queue
* if ((stat = workq_init(&job_wq, max_workers, job_thread)) != 0) {
- * Emsg1(M_ABORT, 0, "Could not init job work queue: ERR=%s\n", strerror(errno));
+ * berrno be;
+ * Emsg1(M_ABORT, 0, "Could not init job work queue: ERR=%s\n", be.bstrerror(errno));
* }
*
* Add an item to the queue
* if ((stat = workq_add(&job_wq, (void *)jcr)) != 0) {
- * Emsg1(M_ABORT, 0, "Could not add job to work queue: ERR=%s\n", strerror(errno));
+ * berrno be;
+ * Emsg1(M_ABORT, 0, "Could not add job to work queue: ERR=%s\n", be.bstrerror(errno));
* }
*
* Terminate the queue
*/
#undef VERSION
-#define VERSION "2.1.10"
-#define BDATE "18 May 2007"
-#define LSMDATE "18May07"
+#define VERSION "2.1.11"
+#define BDATE "20 May 2007"
+#define LSMDATE "20May07"
#define PROG_COPYRIGHT "Copyright (C) %d-2007 Free Software Foundation Europe e.V.\n"
#define BYEAR "2007" /* year for copyright messages in progs */
Technical notes on version 2.1
General:
+20May07
+kes Fix tray-monitor by not requiring a timer interval in bnet_connect()
+kes Complete change of berrno strerror() method to bstrerror()
+Release: 2.1.10 beta
18May07
kes Cleanup incorrect email addresses in bsmtp.
kes Make bat display initial messages rather than discard them.