}
/* Recheck at least once per minute */
bmicrosleep((next_check_secs < twait)?next_check_secs:twait, 0);
- /* Attempt to handle clock shift from/to daylight savings time
+ /* Attempt to handle clock shift (but not daylight savings time changes)
* we allow a skew of 10 seconds before invalidating everything.
*/
now = time(NULL);
- if (now < prev+10 || now > (prev+next_check_secs+10)) {
+ if (now < prev-10 || now > (prev+next_check_secs+10)) {
schedules_invalidated = true;
}
}
wom = mday / 7;
woy = tm_woy(now); /* get week of year */
+ Dmsg7(dbglvl, "now = %x: h=%d m=%d md=%d wd=%d wom=%d woy=%d\n",
+ now, hour, month, mday, wday, wom, woy);
+
/*
* Compute values for next hour from now.
* We do this to be sure we don't miss a job while
nh_wom = nh_mday / 7;
nh_woy = tm_woy(now); /* get week of year */
+ Dmsg7(dbglvl, "nh = %x: h=%d m=%d md=%d wd=%d wom=%d woy=%d\n",
+ next_hour, nh_hour, nh_month, nh_mday, nh_wday, nh_wom, nh_woy);
+
/* Loop through all jobs */
LockRes();
foreach_res(job, R_JOB) {
Dmsg3(dbglvl, "run@%p: run_now=%d run_nh=%d\n", run, run_now, run_nh);
- /* find time (time_t) job is to be run */
- (void)localtime_r(&now, &tm); /* reset tm structure */
- tm.tm_min = run->minute; /* set run minute */
- tm.tm_sec = 0; /* zero secs */
- if (run_now) {
- runtime = mktime(&tm);
- add_job(job, run, now, runtime);
- }
- /* If job is to be run in the next hour schedule it */
- if (run_nh) {
- /* Set correct values */
- tm.tm_hour = nh_hour;
- tm.tm_mday = nh_mday + 1; /* fixup because we biased for tests above */
- tm.tm_mon = nh_month;
- tm.tm_year = nh_year;
- runtime = mktime(&tm);
- add_job(job, run, now, runtime);
- }
+ if (run_now || run_nh) {
+ /* find time (time_t) job is to be run */
+ (void)localtime_r(&now, &tm); /* reset tm structure */
+ tm.tm_min = run->minute; /* set run minute */
+ tm.tm_sec = 0; /* zero secs */
+ runtime = mktime(&tm);
+ if (run_now) {
+ add_job(job, run, now, runtime);
+ }
+ /* If job is to be run in the next hour schedule it */
+ if (run_nh) {
+ add_job(job, run, now, runtime + 3600);
+ }
+ }
}
}
UnlockRes();
bsock->suppress_error_msgs = flag;
}
-
-/*
- * Transmit spooled data now to a BSOCK
- */
-int bnet_despool_to_bsock(BSOCK * bsock, void update_attr_spool_size(ssize_t size),
- ssize_t tsize)
-{
- int32_t pktsiz;
- size_t nbytes;
- ssize_t last = 0, size = 0;
- int count = 0;
-
- rewind(bsock->spool_fd);
- while (fread((char *)&pktsiz, 1, sizeof(int32_t), bsock->spool_fd) ==
- sizeof(int32_t)) {
- size += sizeof(int32_t);
- bsock->msglen = ntohl(pktsiz);
- if (bsock->msglen > 0) {
- if (bsock->msglen > (int32_t) sizeof_pool_memory(bsock->msg)) {
- bsock->msg = realloc_pool_memory(bsock->msg, bsock->msglen + 1);
- }
- nbytes = fread(bsock->msg, 1, bsock->msglen, bsock->spool_fd);
- if (nbytes != (size_t) bsock->msglen) {
- berrno be;
- Dmsg2(400, "nbytes=%d msglen=%d\n", nbytes, bsock->msglen);
- Qmsg1(bsock->jcr(), M_FATAL, 0, _("fread attr spool error. ERR=%s\n"),
- be.strerror());
- update_attr_spool_size(tsize - last);
- return 0;
- }
- size += nbytes;
- if ((++count & 0x3F) == 0) {
- update_attr_spool_size(size - last);
- last = size;
- }
- }
- bnet_send(bsock);
- }
- update_attr_spool_size(tsize - last);
- if (ferror(bsock->spool_fd)) {
- berrno be;
- Qmsg1(bsock->jcr(), M_FATAL, 0, _("fread attr spool error. ERR=%s\n"),
- be.strerror());
- return 0;
- }
- return 1;
-}
-
-
/*
* Send a message over the network. The send consists of
* two network packets. The first is sends a 32 bit integer containing
return bsock->send();
}
-#ifdef xxx
-bool bnet_send(BSOCK * bsock)
-{
- int32_t rc;
- int32_t pktsiz;
-
- if (bsock->errors || bsock->terminated || bsock->msglen > 1000000) {
- return false;
- }
- pktsiz = htonl((int32_t)bsock->msglen);
- /* send int32_t containing size of data packet */
- bsock->timer_start = watchdog_time; /* start timer */
- bsock->timed_out = 0;
- rc = write_nbytes(bsock, (char *)&pktsiz, sizeof(int32_t));
- bsock->timer_start = 0; /* clear timer */
- if (rc != sizeof(int32_t)) {
- if (bsock->msglen == BNET_TERMINATE) { /* if we were terminating */
- bsock->terminated = 1;
- return false; /* ignore any errors */
- }
- bsock->errors++;
- if (errno == 0) {
- bsock->b_errno = EIO;
- } else {
- bsock->b_errno = errno;
- }
- if (rc < 0) {
- if (!bsock->suppress_error_msgs && !bsock->timed_out) {
- Qmsg4(bsock->jcr(), M_ERROR, 0,
- _("Write error sending len to %s:%s:%d: ERR=%s\n"), bsock->who,
- bsock->host(), bsock->port(), bnet_strerror(bsock));
- }
- } else {
- Qmsg5(bsock->jcr(), M_ERROR, 0,
- _("Wrote %d bytes to %s:%s:%d, but only %d accepted.\n"),
- sizeof(int32_t), bsock->who(),
- bsock->host(), bsock->port(), rc);
- }
- return false;
- }
-
- bsock->out_msg_no++; /* increment message number */
- if (bsock->msglen <= 0) { /* length only? */
- return true; /* yes, no data */
- }
-
- /* send data packet */
- bsock->timer_start = watchdog_time; /* start timer */
- bsock->timed_out = 0;
- rc = write_nbytes(bsock, bsock->msg, bsock->msglen);
- bsock->timer_start = 0; /* clear timer */
- if (rc != bsock->msglen) {
- bsock->errors++;
- if (errno == 0) {
- bsock->b_errno = EIO;
- } else {
- bsock->b_errno = errno;
- }
- if (rc < 0) {
- if (!bsock->suppress_error_msgs) {
- Qmsg5(bsock->jcr(), M_ERROR, 0,
- _("Write error sending %d bytes to %s:%s:%d: ERR=%s\n"),
- bsock->msglen, bsock->who(),
- bsock->host(), bsock->port(), bnet_strerror(bsock));
- }
- } else {
- Qmsg5(bsock->jcr(), M_ERROR, 0,
- _("Wrote %d bytes to %s:%s:%d, but only %d accepted.\n"),
- bsock->msglen, bsock->who(), bsock->host(),
- bsock->port(), rc);
- }
- return false;
- }
- return true;
-}
-#endif
/*
* Establish a TLS connection -- server side
return send();
}
+/*
+ * Despool spooled attributes
+ */
+bool BSOCK::despool(void update_attr_spool_size(ssize_t size), ssize_t tsize)
+{
+ int32_t pktsiz;
+ size_t nbytes;
+ ssize_t last = 0, size = 0;
+ int count = 0;
+
+ rewind(spool_fd);
+ while (fread((char *)&pktsiz, 1, sizeof(int32_t), spool_fd) ==
+ sizeof(int32_t)) {
+ size += sizeof(int32_t);
+ msglen = ntohl(pktsiz);
+ if (msglen > 0) {
+ if (msglen > (int32_t) sizeof_pool_memory(msg)) {
+ msg = realloc_pool_memory(msg, msglen + 1);
+ }
+ nbytes = fread(msg, 1, msglen, spool_fd);
+ if (nbytes != (size_t) msglen) {
+ 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());
+ update_attr_spool_size(tsize - last);
+ return false;
+ }
+ size += nbytes;
+ if ((++count & 0x3F) == 0) {
+ update_attr_spool_size(size - last);
+ last = size;
+ }
+ }
+ send();
+ }
+ update_attr_spool_size(tsize - last);
+ if (ferror(spool_fd)) {
+ berrno be;
+ Qmsg1(jcr(), M_FATAL, 0, _("fread attr spool error. ERR=%s\n"),
+ be.strerror());
+ return false;
+ }
+ return true;
+}
+
+
void BSOCK::close()
{
BSOCK *bsock = this;
char *host() { return m_host; };
int port() { return m_port; };
JCR *jcr() { return m_jcr; };
+ bool despool(void update_attr_spool_size(ssize_t size), ssize_t tsize);
};
/*
const char *bnet_sig_to_ascii (BSOCK *bsock);
int bnet_wait_data (BSOCK *bsock, int sec);
int bnet_wait_data_intr (BSOCK *bsock, int sec);
-int bnet_despool_to_bsock (BSOCK *bsock, void update(ssize_t size), ssize_t size);
bool is_bnet_stop (BSOCK *bsock);
int is_bnet_error (BSOCK *bsock);
void bnet_suppress_error_messages(BSOCK *bsock, bool flag);
}
wd_queue = New(dlist(dummy, &dummy->link));
wd_inactive = New(dlist(dummy, &dummy->link));
+ wd_is_init = true;
if ((stat = pthread_create(&wd_tid, NULL, watchdog_thread, NULL)) != 0) {
return stat;
}
- wd_is_init = true;
return 0;
}
edit_uint64(jcr->JobBytes, ec1));
Dmsg4(200, Job_end, jcr->Job, jcr->JobStatus, jcr->JobFiles, ec1);
- bnet_sig(dir, BNET_EOD); /* send EOD to Director daemon */
+ dir->signal(BNET_EOD); /* send EOD to Director daemon */
return ok;
}
-/*
- * Spooling code
- *
- * Kern Sibbald, March 2004
- *
- * 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.
*/
+/*
+ * Spooling code
+ *
+ * Kern Sibbald, March 2004
+ *
+ * Version $Id$
+ */
#include "bacula.h"
#include "stored.h"
void list_spool_stats(void sendit(const char *msg, int len, void *sarg), void *arg)
{
- char *msg, ed1[30], ed2[30];
+ char ed1[30], ed2[30];
+ POOL_MEM msg(PM_MESSAGE);
int len;
- msg = (char *)get_pool_memory(PM_MESSAGE);
-
if (spool_stats.data_jobs || spool_stats.max_data_size) {
len = Mmsg(msg, _("Data spooling: %u active jobs, %s bytes; %u total jobs, %s max bytes/job.\n"),
spool_stats.data_jobs, edit_uint64_with_commas(spool_stats.data_size, ed1),
spool_stats.total_data_jobs,
edit_uint64_with_commas(spool_stats.max_data_size, ed2));
- sendit(msg, len, arg);
+ sendit(msg.c_str(), len, arg);
}
if (spool_stats.attr_jobs || spool_stats.max_attr_size) {
len = Mmsg(msg, _("Attr spooling: %u active jobs, %s bytes; %u total jobs, %s max bytes.\n"),
spool_stats.total_attr_jobs,
edit_uint64_with_commas(spool_stats.max_attr_size, ed2));
- sendit(msg, len, arg);
+ sendit(msg.c_str(), len, arg);
}
-
- free_pool_memory(msg);
}
bool begin_data_spool(DCR *dcr)
V(mutex);
Jmsg(jcr, M_INFO, 0, _("Sending spooled attrs to the Director. Despooling %s bytes ...\n"),
edit_uint64_with_commas(size, ec1));
- bnet_despool_to_bsock(jcr->dir_bsock, update_attr_spool_size, size);
+ jcr->dir_bsock->despool(update_attr_spool_size, size);
return close_attr_spool_file(jcr, jcr->dir_bsock);
}
return true;
General:
01Apr07
+kes Move bnet_despool() into class in bsock.c
kes Modify job report to include director name and Build OS.
kes Move drop and check_catalog() before fork.
kes Add update database scripts (version 9 to 10) to updatedb directory.