dbuf_size = DEFAULT_NETWORK_BUFFER_SIZE;
}
start_size = dbuf_size;
- if ((msg = realloc_pool_memory(msg, dbuf_size + 100)) == NULL) {
+ /* The extra 512 can hold data such as Sparse/Offset pointer */
+ if ((msg = realloc_pool_memory(msg, dbuf_size + 512)) == NULL) {
Qmsg0(get_jcr(), M_FATAL, 0, _("Could not malloc BSOCKCORE data buffer\n"));
return false;
}
void master_lock() const { if (m_use_locking) pP((&m_mmutex)); };
void master_unlock() const { if (m_use_locking) pV((&m_mmutex)); };
virtual void init();
- void _destroy(); /* called by destroy() */
+ virtual void _destroy(); /* called by destroy() */
virtual int32_t write_nbytes(char *ptr, int32_t nbytes);
virtual int32_t read_nbytes(char *ptr, int32_t nbytes);
virtual int32_t recv(int /*len*/);
virtual bool send();
bool fsend(const char*, ...);
- void close(); /* close connection and destroy packet */
+ virtual void close(); /* close connection and destroy packet */
void destroy(); /* destroy socket packet */
const char *bstrerror(); /* last error on socket */
int get_peer(char *buf, socklen_t buflen);
IMPLEMENT_ASN1_FUNCTIONS(SignatureData)
IMPLEMENT_ASN1_FUNCTIONS(CryptoData)
-#if (OPENSSL_VERSION_NUMBER >= 0x10100000L)
+#if defined(DEFINE_STACK_OF)
DEFINE_STACK_OF(SignerInfo);
DEFINE_STACK_OF(RecipientInfo);
#else
if (keypair->pubkey) {
ret = EVP_PKEY_up_ref(keypair->pubkey);
if (ret == 0)
- goto out_free_new;
+ goto out_free_new;
newpair->pubkey = keypair->pubkey;
}
if (keypair->privkey) {
ret = EVP_PKEY_up_ref(keypair->privkey);
if (ret == 0)
- goto out_free_new;
+ goto out_free_new;
newpair->privkey = keypair->privkey;
}
if (keypair->keyid) {
newpair->keyid = ASN1_OCTET_STRING_dup(keypair->keyid);
if (!newpair->keyid)
- goto out_free_new;
+ goto out_free_new;
}
return newpair;
/* Initialize the OpenSSL message digest context */
digest->ctx = EVP_MD_CTX_new();
if (!digest->ctx)
- goto err;
+ goto err;
EVP_MD_CTX_reset(digest->ctx);
/* Determine the correct OpenSSL message digest type */
cipher_ctx = (CIPHER_CONTEXT *)malloc(sizeof(CIPHER_CONTEXT));
if (!cipher_ctx)
- return NULL;
+ return NULL;
cipher_ctx->ctx = EVP_CIPHER_CTX_new();
if (!cipher_ctx->ctx)
- goto err;
+ goto err;
/*
* Acquire a cipher instance for the given ASN.1 cipher NID
{
devlock *lock;
lock = (devlock *)malloc(sizeof (devlock));
- memset(lock, 0, sizeof(devlock));
+ bmemset(lock, 0, sizeof(devlock));
return lock;
}
/*
Bacula(R) - The Network Backup Solution
- Copyright (C) 2000-2017 Kern Sibbald
+ Copyright (C) 2000-2018 Kern Sibbald
The original author of Bacula is Kern Sibbald, with contributions
from many others, a complete list can be found in the file AUTHORS.
static dlist *global_mgr = NULL; /* used to store all lgmr_thread_t objects */
static pthread_mutex_t lmgr_global_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_t undertaker;
-static bool use_undertaker=true;
+static pthread_cond_t undertaker_cond;
+static pthread_mutex_t undertaker_mutex = PTHREAD_MUTEX_INITIALIZER;
+static bool use_undertaker = true;
+static bool do_quit = false;
+
#define lmgr_is_active() (global_mgr != NULL)
void *check_deadlock(void *)
{
- int old;
lmgr_init_thread();
pthread_cleanup_push(cln_hdl, NULL);
- while (!bmicrosleep(30, 0)) {
- pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &old);
+ while (!do_quit) {
+ struct timeval tv;
+ struct timezone tz;
+ struct timespec timeout;
+
+ gettimeofday(&tv, &tz);
+ timeout.tv_nsec = 0;
+ timeout.tv_sec = tv.tv_sec + 30;
+
+ pthread_mutex_lock(&undertaker_mutex);
+ pthread_cond_timedwait(&undertaker_cond, &undertaker_mutex, &timeout);
+ pthread_mutex_unlock(&undertaker_mutex);
+
+ if(do_quit) {
+ goto bail_out;
+ }
+
if (lmgr_detect_deadlock()) {
/* If we have information about P()/V(), display them */
if (debug_flags & DEBUG_MUTEX_EVENT && chk_dbglvl(DBGLEVEL_EVENT)) {
lmgr_dump();
ASSERT2(0, "Lock deadlock"); /* Abort if we found a deadlock */
}
- pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &old);
- pthread_testcancel();
}
+
+bail_out:
Dmsg0(100, "Exit check_deadlock.\n");
pthread_cleanup_pop(1);
return NULL;
global_mgr = New(dlist(n, &n->link));
if (use_undertaker) {
+ /* Create condwait */
+ status = pthread_cond_init(&undertaker_cond, NULL);
+ if (status != 0) {
+ berrno be;
+ Pmsg1(000, _("pthread_cond_init failed: ERR=%s\n"),
+ be.bstrerror(status));
+ ASSERT2(0, "pthread_cond_init failed");
+ }
status = pthread_create(&undertaker, NULL, check_deadlock, NULL);
if (status != 0) {
berrno be;
return;
}
if (use_undertaker) {
- pthread_cancel(undertaker);
-#ifdef DEVELOPER
+ /* Signal to the check_deadlock thread to stop itself */
+ pthread_mutex_lock(&undertaker_mutex);
+ do_quit = true;
+ pthread_cond_signal(&undertaker_cond);
+ pthread_mutex_unlock(&undertaker_mutex);
/* Should avoid memory leak reporting */
pthread_join(undertaker, NULL);
-#endif
+ pthread_cond_destroy(&undertaker_cond);
}
lmgr_cleanup_thread();
lmgr_p(&lmgr_global_mutex);
/*
Bacula(R) - The Network Backup Solution
- Copyright (C) 2000-2017 Kern Sibbald
+ Copyright (C) 2000-2018 Kern Sibbald
The original author of Bacula is Kern Sibbald, with contributions
from many others, a complete list can be found in the file AUTHORS.
buf->ablen = size;
buf->pool = pool;
buf->next = NULL;
+ P(mutex);
pool_ctl[pool].in_use++;
if (pool_ctl[pool].in_use > pool_ctl[pool].max_used)
pool_ctl[pool].max_used = pool_ctl[pool].in_use;
+ V(mutex);
return (POOLMEM *)(((char *)buf)+HEAD_SIZE);
}
}
}
+/*
+ * Can be called by Bacula's tools that use Bacula's libraries, to control where
+ * to redirect Dmsg() emitted by the code inside the Bacula's library.
+ * This should not be called by the main daemon, this is a Hack !
+ * See in bsnapshot.c how it is used
+ * In your tools be careful to no call any function that here in messages.c
+ * that modify "trace" or close() or re-open() trace_fd
+ */
+void set_trace_for_tools(FILE *new_trace_fd)
+{
+ // don't call fclose(trace_fd) here
+ trace = true;
+ trace_fd = new_trace_fd;
+}
+
void set_hangup(int hangup_value)
{
if (hangup_value != -1) {
void set_debug_flags(char *options);
const char *get_basename(const char *pathname);
bool is_message_type_set(JCR *jcr, int type);
+void set_trace_for_tools(FILE *new_trace_fd); // called by Bacula's tools only
class BDB; /* define forward reference */
typedef bool (*sql_query_call)(JCR *jcr, const char *cmd);
/*
Bacula(R) - The Network Backup Solution
- Copyright (C) 2000-2016 Kern Sibbald
+ Copyright (C) 2000-2018 Kern Sibbald
The original author of Bacula is Kern Sibbald, with contributions
from many others, a complete list can be found in the file AUTHORS.
Public License, v3.0 ("AGPLv3") and some additional permissions and
terms pursuant to its AGPLv3 Section 7.
- This notice must be preserved when any source code is
+ This notice must be preserved when any source code is
conveyed and/or propagated.
Bacula(R) is a registered trademark of Kern Sibbald.
}
}
-#if (OPENSSL_VERSION_NUMBER < 0x10100000L)
+#if (OPENSSL_VERSION_NUMBER < 0x10100000L) || defined(LIBRESSL_VERSION_NUMBER)
/* Array of mutexes for use with OpenSSL static locking */
static pthread_mutex_t *mutexes;
{
int stat = 0;
-#if (OPENSSL_VERSION_NUMBER < 0x10100000L)
+#if (OPENSSL_VERSION_NUMBER < 0x10100000L) || defined(LIBRESSL_VERSION_NUMBER)
if ((stat = openssl_init_threads()) != 0) {
berrno be;
Jmsg1(NULL, M_ABORT, 0,
Jmsg0(NULL, M_ERROR, 0, _("Failed to save OpenSSL PRNG\n"));
}
-#if (OPENSSL_VERSION_NUMBER < 0x10100000L)
+#if (OPENSSL_VERSION_NUMBER < 0x10100000L) || defined(LIBRESSL_VERSION_NUMBER)
openssl_cleanup_threads();
/* Free libssl and libcrypto error strings */
/*
Bacula(R) - The Network Backup Solution
- Copyright (C) 2000-2017 Kern Sibbald
+ Copyright (C) 2000-2018 Kern Sibbald
The original author of Bacula is Kern Sibbald, with contributions
from many others, a complete list can be found in the file AUTHORS.
POOLMEM *tmp2 = get_pool_memory(PM_FNAME);
POOLMEM *tmp = get_pool_memory(PM_FNAME);
OutputType val = first;
-
+
while (val != OT_END) {
*tmp = 0;
Mmsg(tmp, "%s_epoch=%lld%c%s=%s%c", k, bt, separator, k, ed1, separator);
break;
+ case OT_DURATION:
+ bt = va_arg(ap, utime_t);
+ bstrutime(ed1, sizeof(ed1), bt);
+ Mmsg(tmp, "%s=%lld%c%s_str=%s%c", k, bt, separator, k, edit_utime(bt, ed1, sizeof(ed1)), separator);
+ break;
+
case OT_SIZE:
case OT_INT64:
i64 = va_arg(ap, int64_t);
case OT_JOBTYPE:
case OT_JOBSTATUS:
i32 = va_arg(ap, int32_t);
- Mmsg(tmp, "%s=%c%c", k, (char) i32, separator);
+ if (i32 == 0) {
+ Mmsg(tmp, "%s=%c", k, separator);
+ } else {
+ Mmsg(tmp, "%s=%c%c", k, (char)i32, separator);
+ }
break;
case OT_CLEAR:
* name handler value code flags default_value
*/
RES_ITEM msgs_items[] = {
- {"Name", store_name, ITEM(res_msgs.hdr.name), 0, 0, 0},
+ {"Name", store_name, ITEM(res_msgs.hdr.name), 0, ITEM_REQUIRED, 0},
{"Description", store_str, ITEM(res_msgs.hdr.desc), 0, 0, 0},
{"MailCommand", store_str, ITEM(res_msgs.mail_cmd), 0, ITEM_ALLOW_DUPS, 0},
{"OperatorCommand", store_str, ITEM(res_msgs.operator_cmd), 0, ITEM_ALLOW_DUPS, 0},
/* bpipe.c */
BPIPE * open_bpipe(char *prog, int wait, const char *mode, char *envp[]=NULL);
int close_wpipe(BPIPE *bpipe);
+int close_epipe(BPIPE *bpipe);
int close_bpipe(BPIPE *bpipe);
/* cram-md5.c */
/*
Bacula(R) - The Network Backup Solution
- Copyright (C) 2000-2016 Kern Sibbald
+ Copyright (C) 2000-2018 Kern Sibbald
The original author of Bacula is Kern Sibbald, with contributions
from many others, a complete list can be found in the file AUTHORS.
Public License, v3.0 ("AGPLv3") and some additional permissions and
terms pursuant to its AGPLv3 Section 7.
- This notice must be preserved when any source code is
+ This notice must be preserved when any source code is
conveyed and/or propagated.
Bacula(R) is a registered trademark of Kern Sibbald.
{
Dmsg0(500, "runscript: freeing all RUNSCRIPTS object\n");
- RUNSCRIPT *elt;
- foreach_alist(elt, runscripts) {
- free_runscript(elt);
+ if (runscripts){
+ RUNSCRIPT *elt;
+ foreach_alist(elt, runscripts) {
+ free_runscript(elt);
+ }
}
}
/*
Bacula(R) - The Network Backup Solution
- Copyright (C) 2000-2017 Kern Sibbald
+ Copyright (C) 2000-2018 Kern Sibbald
The original author of Bacula is Kern Sibbald, with contributions
from many others, a complete list can be found in the file AUTHORS.
char issuer[256];
char subject[256];
+ if (err == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT ||
+ err == X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN)
+ {
+ /* It seems that the error can be also
+ * 24 X509_V_ERR_INVALID_CA: invalid CA certificate
+ * But it's not very specific...
+ */
+ Jmsg0(NULL, M_ERROR, 0, _("CA certificate is self signed. With OpenSSL 1.1, enforce basicConstraints = CA:true in the certificate creation to avoid this issue\n"));
+ }
X509_NAME_oneline(X509_get_issuer_name(cert), issuer, 256);
X509_NAME_oneline(X509_get_subject_name(cert), subject, 256);
SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT,
openssl_verify_peer);
}
-
return ctx;
err:
return SSL_peek(bsock->tls->openssl, &pktsiz, sizeof(pktsiz))==sizeof(pktsiz);
}
-
#else /* HAVE_OPENSSL */
# error No TLS implementation available.
#endif /* !HAVE_OPENSSL */
/*
Bacula(R) - The Network Backup Solution
- Copyright (C) 2000-2017 Kern Sibbald
+ Copyright (C) 2000-2018 Kern Sibbald
The original author of Bacula is Kern Sibbald, with contributions
from many others, a complete list can be found in the file AUTHORS.
count = 1000;
}
root = (TREE_ROOT *)malloc(sizeof(TREE_ROOT));
- memset(root, 0, sizeof(TREE_ROOT));
+ bmemset(root, 0, sizeof(TREE_ROOT));
/* Assume filename + node = 40 characters average length */
size = count * (BALIGN(sizeof(TREE_NODE)) + 40);
if (count > 1000000 || size > (MAX_BUF_SIZE / 2)) {
TREE_NODE *node;
int size = sizeof(TREE_NODE);
node = (TREE_NODE *)tree_alloc(root, size);
- memset(node, 0, size);
+ bmemset(node, 0, size);
node->delta_seq = -1;
node->can_access = 1;
return node;
BSOCK *dir = jcr->dir_bsock;
bool rtn;
char lastVolume[MAX_NAME_LENGTH];
+ int nb_retry;
+ /*
+ * Calculate the number of possible drives + 30 for the size of the
+ * Volume list to consider.
+ */
+ nb_retry = ((rblist *)res_head[R_DEVICE-r_first]->res_list)->size() + 30;
Dmsg2(dbglvl, "dir_find_next_appendable_volume: reserved=%d Vol=%s\n",
dcr->is_reserved(), dcr->VolumeName);
Mmsg(jcr->errmsg, "Unknown error\n");
P(vol_info_mutex);
dcr->clear_found_in_use();
lastVolume[0] = 0;
- for (int vol_index=1; vol_index < 30; vol_index++) {
+ for (int vol_index=1; vol_index < nb_retry; vol_index++) {
bash_spaces(dcr->media_type);
bash_spaces(dcr->pool_name);
dir->fsend(Find_media, jcr->JobId, vol_index, dcr->pool_name, dcr->media_type,
*/
/* ***FIXME*** find better way to handle voltype */
if (dcr->VolCatInfo.VolCatType != 0 &&
- (dcr->dev->dev_type == B_FILE_DEV || dcr->dev->dev_type == B_ALIGNED_DEV ||
+ (dcr->dev->dev_type == B_FILE_DEV || dcr->dev->dev_type == B_ALIGNED_DEV ||
dcr->dev->dev_type == B_CLOUD_DEV) &&
dcr->dev->dev_type != (int)dcr->VolCatInfo.VolCatType) {
Dmsg2(000, "Skip vol. Wanted VolType=%d Got=%d\n", dcr->dev->dev_type, dcr->VolCatInfo.VolCatType);
POOL_MEM VolumeName;
/* If system job, do not update catalog, except if we explicitly force it. */
- if (jcr->getJobType() == JT_SYSTEM &&
+ if (jcr->getJobType() == JT_SYSTEM &&
!dcr->force_update_volume_info) {
return true;
}
dev->VolCatInfo.VolCatRecycles = dcr->VolCatInfo.VolCatRecycles;
dev->VolCatInfo.VolCatWrites = dcr->VolCatInfo.VolCatWrites;
dev->VolCatInfo.VolCatReads = dcr->VolCatInfo.VolCatReads;
+ dev->VolCatInfo.VolEnable = dcr->VolCatInfo.VolEnable;
dev->VolCatInfo.VolRecycle = dcr->VolCatInfo.VolRecycle;
}
ok = true;
str = dcr->jcr->Job;
break;
case 'v':
- if (dcr->VolCatInfo.VolCatName[0]) {
+ if (dcr->dev->LoadedVolName[0]) {
+ str = dcr->dev->LoadedVolName;
+ } else if (dcr->VolCatInfo.VolCatName[0]) {
str = dcr->VolCatInfo.VolCatName;
} else if (dcr->VolumeName[0]) {
str = dcr->VolumeName;
* int32_t FileIndex
* int32_t Stream
* uint32_t data_length
+ * uint64_t FileOffset (if offset_stream)
*/
#define RECHDR2_LENGTH (3*sizeof(int32_t))
#define WRITE_RECHDR_LENGTH RECHDR2_LENGTH
{
attr = new_attr(bjcr);
- memset(&ar, 0, sizeof(ar));
- memset(&pr, 0, sizeof(pr));
- memset(&jr, 0, sizeof(jr));
- memset(&cr, 0, sizeof(cr));
- memset(&fsr, 0, sizeof(fsr));
- memset(&fr, 0, sizeof(fr));
+ bmemset(&ar, 0, sizeof(ar));
+ bmemset(&pr, 0, sizeof(pr));
+ bmemset(&jr, 0, sizeof(jr));
+ bmemset(&cr, 0, sizeof(cr));
+ bmemset(&fsr, 0, sizeof(fsr));
+ bmemset(&fr, 0, sizeof(fr));
/* Detach bscan's jcr as we are not a real Job on the tape */
}
/* Check Media Info */
- memset(&mr, 0, sizeof(mr));
+ bmemset(&mr, 0, sizeof(mr));
bstrncpy(mr.VolumeName, dev->VolHdr.VolumeName, sizeof(mr.VolumeName));
mr.PoolId = pr.PoolId;
num_media++;
ignored_msgs = 0;
}
unser_session_label(&label, rec);
- memset(&jr, 0, sizeof(jr));
+ bmemset(&jr, 0, sizeof(jr));
bstrncpy(jr.Job, label.Job, sizeof(jr.Job));
if (db_get_job_record(bjcr, db, &jr)) {
/* Job record already exists in DB */
Pmsg3(0, _("End of all Volumes. VolFiles=%u VolBlocks=%u VolBytes=%s\n"), mr.VolFiles,
mr.VolBlocks, edit_uint64_with_commas(mr.VolBytes, ec1));
break;
+ case STREAM_PLUGIN_NAME:
+ break;
+
default:
break;
} /* end switch */
free_bsock(jcr->file_bsock);
free_bsock(jcr->store_bsock);
if (jcr->RestoreBootstrap) {
- free(jcr->RestoreBootstrap);
+ bfree_and_null(jcr->RestoreBootstrap);
}
if (jcr->dcr) {
free_dcr(jcr->dcr);
dcr->EndAddr = dev->EndAddr;
dcr->VolMediaId = dev->VolCatInfo.VolMediaId;
- memset(&jmr, 0, sizeof(jmr));
+ bmemset(&jmr, 0, sizeof(jmr));
jmr.JobId = mjcr->JobId;
jmr.MediaId = mr.MediaId;
jmr.FirstIndex = dcr->VolFirstIndex;
/* read from fd */
ssize_t DEVICE::read(void *buf, size_t len)
{
- ssize_t read_len ;
+ ssize_t read_len;
get_timer_count();