/* Imported functions */
extern int status_cmd(JCR *jcr);
-
+extern int qstatus_cmd(JCR *jcr);
+
/* Forward referenced functions */
static int backup_cmd(JCR *jcr);
static int bootstrap_cmd(JCR *jcr);
static int hello_cmd(JCR *jcr);
static int job_cmd(JCR *jcr);
static int include_cmd(JCR *jcr);
+static int fileset_cmd(JCR *jcr);
static int level_cmd(JCR *jcr);
static int verify_cmd(JCR *jcr);
static int restore_cmd(JCR *jcr);
static int runbefore_cmd(JCR *jcr);
static int runafter_cmd(JCR *jcr);
static int run_cmd(JCR *jcr, char *cmd, const char *name);
+static void set_options(findFOPTS *fo, const char *opts);
/* Exported functions */
struct s_cmds {
- char *cmd;
+ const char *cmd;
int (*func)(JCR *);
};
{"exclude", exclude_cmd},
{"Hello", hello_cmd},
{"include", include_cmd},
+ {"fileset", fileset_cmd},
{"JobId=", job_cmd},
{"level = ", level_cmd},
{"restore", restore_cmd},
{"session", session_cmd},
{"status", status_cmd},
+ {".status", qstatus_cmd},
{"storage ", storage_cmd},
{"verify", verify_cmd},
{"bootstrap", bootstrap_cmd},
*/
void *handle_client_request(void *dirp)
{
- int i, found, quit;
+ int i;
+ bool found, quit;
JCR *jcr;
BSOCK *dir = (BSOCK *)dirp;
/**********FIXME******* add command handler error code */
- for (quit=0; !quit;) {
+ for (quit=false; !quit;) {
/* Read command */
if (bnet_recv(dir) < 0) {
}
dir->msg[dir->msglen] = 0;
Dmsg1(100, "<dird: %s", dir->msg);
- found = FALSE;
+ found = false;
for (i=0; cmds[i].cmd; i++) {
if (strncmp(cmds[i].cmd, dir->msg, strlen(cmds[i].cmd)) == 0) {
if (!jcr->authenticated && cmds[i].func != hello_cmd) {
bnet_fsend(dir, no_auth);
break;
}
- found = TRUE; /* indicate command found */
+ found = true; /* indicate command found */
+ Dmsg1(100, "Executing %s command.\n", cmds[i].cmd);
if (!cmds[i].func(jcr)) { /* do command */
- quit = TRUE; /* error or fully terminated, get out */
- Dmsg0(20, "Command error or Job done.\n");
+ quit = true; /* error or fully terminated, get out */
+ Dmsg0(20, "Quit command loop due to command error or Job done.\n");
}
break;
}
}
if (!found) { /* command not found */
bnet_fsend(dir, errmsg);
- quit = TRUE;
+ quit = true;
break;
}
}
/* Inform Director that we are done */
bnet_sig(dir, BNET_TERMINATE);
+ /* Clean up fileset */
+ FF_PKT *ff = (FF_PKT *)jcr->ff;
+ findFILESET *fileset = ff->fileset;
+ if (fileset) {
+ int i, j, k;
+ /* Delete FileSet Include lists */
+ for (i=0; i<fileset->include_list.size(); i++) {
+ findINCEXE *incexe = (findINCEXE *)fileset->include_list.get(i);
+ for (j=0; j<incexe->opts_list.size(); j++) {
+ findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j);
+ for (k=0; k<fo->regex.size(); k++) {
+ regfree((regex_t *)fo->regex.get(k));
+ }
+ fo->regex.destroy();
+ fo->wild.destroy();
+ fo->base.destroy();
+ if (fo->reader) {
+ free(fo->reader);
+ }
+ if (fo->writer) {
+ free(fo->writer);
+ }
+ }
+ incexe->opts_list.destroy();
+ incexe->name_list.destroy();
+ }
+ fileset->include_list.destroy();
+
+ /* Delete FileSet Exclude lists */
+ for (i=0; i<fileset->exclude_list.size(); i++) {
+ findINCEXE *incexe = (findINCEXE *)fileset->exclude_list.get(i);
+ for (j=0; j<incexe->opts_list.size(); j++) {
+ findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j);
+ fo->regex.destroy();
+ fo->wild.destroy();
+ fo->base.destroy();
+ }
+ incexe->opts_list.destroy();
+ incexe->name_list.destroy();
+ }
+ fileset->exclude_list.destroy();
+ free(fileset);
+ }
Dmsg0(100, "Calling term_find_files\n");
term_find_files((FF_PKT *)jcr->ff);
Dmsg0(100, "Done with term_find_files\n");
return 0;
}
Dmsg0(120, "OK Authenticate\n");
- jcr->authenticated = TRUE;
+ jcr->authenticated = true;
return 1;
}
P(cjcr->mutex);
cjcr->store_bsock->timed_out = 1;
cjcr->store_bsock->terminated = 1;
-#if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32)
+/*
+ * #if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32)
+ */
+#if !defined(HAVE_CYGWIN)
pthread_kill(cjcr->my_thread_id, TIMEOUT_SIGNAL);
#endif
V(cjcr->mutex);
ecmd = edit_job_codes(jcr, ecmd, cmd, "");
bpipe = open_bpipe(ecmd, 0, "r");
free_pool_memory(ecmd);
+ if (bpipe == NULL) {
+ Jmsg(jcr, M_FATAL, 0, _("%s could not execute\n"), name);
+ set_jcr_job_status(jcr, JS_FatalError);
+ return 0;
+ }
while (fgets(line, sizeof(line), bpipe->rfd)) {
Jmsg(jcr, M_INFO, 0, _("%s: %s"), name, line);
}
case '<':
p++; /* skip over < */
if ((ffd = fopen(p, "r")) == NULL) {
+ berrno be;
Jmsg(jcr, M_FATAL, 0, _("Cannot open %s file: %s. ERR=%s\n"),
- list==INC_LIST?"included":"excluded", p, strerror(errno));
+ list==INC_LIST?"included":"excluded", p, be.strerror());
return;
}
/* Copy File options */
return bnet_fsend(dir, OKinc);
}
+static bool init_fileset(JCR *jcr)
+{
+ FF_PKT *ff;
+ findFILESET *fileset;
+
+ if (!jcr->ff) {
+ return false;
+ }
+ ff = (FF_PKT *)jcr->ff;
+ if (ff->fileset) {
+ return false;
+ }
+ fileset = (findFILESET *)malloc(sizeof(findFILESET));
+ memset(fileset, 0, sizeof(findFILESET));
+ ff->fileset = fileset;
+ fileset->state = state_none;
+ fileset->include_list.init(1, true);
+ fileset->exclude_list.init(1, true);
+ return true;
+}
+
+static findFOPTS *start_options(FF_PKT *ff)
+{
+ int state = ff->fileset->state;
+ findINCEXE *incexe = ff->fileset->incexe;
+
+ if (state != state_options) {
+ ff->fileset->state = state_options;
+ findFOPTS *fo = (findFOPTS *)malloc(sizeof(findFOPTS));
+ memset(fo, 0, sizeof(findFOPTS));
+ fo->regex.init(1, true);
+ fo->wild.init(1, true);
+ fo->base.init(1, true);
+ incexe->current_opts = fo;
+ incexe->opts_list.append(fo);
+ }
+ return incexe->current_opts;
+
+}
+
+/*
+ * Add fname to include/exclude fileset list. First check for
+ * | and < and if necessary perform command.
+ */
+static void add_file_to_fileset(JCR *jcr, const char *fname, findFILESET *fileset)
+{
+ char *p;
+ BPIPE *bpipe;
+ POOLMEM *fn;
+ FILE *ffd;
+ char buf[1000];
+ int stat;
+
+ p = (char *)fname;
+ switch (*p) {
+ case '|':
+ p++; /* skip over | */
+ fn = get_pool_memory(PM_FNAME);
+ fn = edit_job_codes(jcr, fn, p, "");
+ bpipe = open_bpipe(fn, 0, "r");
+ free_pool_memory(fn);
+ if (!bpipe) {
+ Jmsg(jcr, M_FATAL, 0, _("Cannot run program: %s. ERR=%s\n"),
+ p, strerror(errno));
+ return;
+ }
+ while (fgets(buf, sizeof(buf), bpipe->rfd)) {
+ strip_trailing_junk(buf);
+ fileset->incexe->name_list.append(bstrdup(buf));
+ }
+ if ((stat=close_bpipe(bpipe)) != 0) {
+ Jmsg(jcr, M_FATAL, 0, _("Error running program: %s. RtnStat=%d ERR=%s\n"),
+ p, stat, strerror(errno));
+ return;
+ }
+ break;
+ case '<':
+ p++; /* skip over < */
+ if ((ffd = fopen(p, "r")) == NULL) {
+ berrno be;
+ Jmsg(jcr, M_FATAL, 0, _("Cannot open FileSet input file: %s. ERR=%s\n"),
+ p, be.strerror());
+ return;
+ }
+ while (fgets(buf, sizeof(buf), ffd)) {
+ strip_trailing_junk(buf);
+ fileset->incexe->name_list.append(bstrdup(buf));
+ }
+ fclose(ffd);
+ break;
+ default:
+ fileset->incexe->name_list.append(bstrdup(fname));
+ break;
+ }
+}
+
+
+static void add_fileset(JCR *jcr, const char *item)
+{
+ FF_PKT *ff = (FF_PKT *)jcr->ff;
+ findFILESET *fileset = ff->fileset;
+ int state = fileset->state;
+ findFOPTS *current_opts;
+
+ Dmsg1(100, "%s\n", item);
+ int code = item[0];
+ if (item[1] == ' ') { /* If string follows */
+ item += 2; /* point to string */
+ }
+
+ if (state == state_error) {
+ return;
+ }
+ switch (code) {
+ case 'I':
+ /* New include */
+ fileset->incexe = (findINCEXE *)malloc(sizeof(findINCEXE));
+ memset(fileset->incexe, 0, sizeof(findINCEXE));
+ fileset->incexe->opts_list.init(1, true);
+ fileset->incexe->name_list.init(1, true);
+ fileset->include_list.append(fileset->incexe);
+ break;
+ case 'E':
+ /* New exclude */
+ fileset->incexe = (findINCEXE *)malloc(sizeof(findINCEXE));
+ memset(fileset->incexe, 0, sizeof(findINCEXE));
+ fileset->incexe->opts_list.init(1, true);
+ fileset->incexe->name_list.init(1, true);
+ fileset->exclude_list.append(fileset->incexe);
+ break;
+ case 'N':
+ state = state_none;
+ break;
+ case 'F':
+ /* File item to either include/include list */
+ state = state_include;
+ add_file_to_fileset(jcr, item, fileset);
+ break;
+ case 'R':
+ current_opts = start_options(ff);
+ regex_t *preg;
+ int rc;
+ char prbuf[500];
+ preg = (regex_t *)malloc(sizeof(regex_t));
+ rc = regcomp(preg, item, REG_EXTENDED);
+ if (rc != 0) {
+ regerror(rc, preg, prbuf, sizeof(prbuf));
+ regfree(preg);
+ free(preg);
+ Jmsg(jcr, M_FATAL, 0, "REGEX %s compile error. ERR=%s\n", item, prbuf);
+ state = state_error;
+ break;
+ }
+ current_opts->regex.append(preg);
+ state = state_options;
+ break;
+ case 'B':
+ current_opts = start_options(ff);
+ current_opts->base.append(bstrdup(item));
+ state = state_options;
+ break;
+ case 'W':
+ current_opts = start_options(ff);
+ current_opts->wild.append(bstrdup(item));
+ state = state_options;
+ break;
+ case 'O':
+ current_opts = start_options(ff);
+ set_options(current_opts, item);
+ state = state_options;
+ break;
+ case 'D':
+ current_opts = start_options(ff);
+ current_opts->reader = bstrdup(item);
+ state = state_options;
+ break;
+ case 'T':
+ current_opts = start_options(ff);
+ current_opts->writer = bstrdup(item);
+ state = state_options;
+ break;
+ default:
+ Jmsg(jcr, M_FATAL, 0, "Invalid FileSet command: %s\n", item);
+ state = state_error;
+ break;
+ }
+ ff->fileset->state = state;
+}
+
+static bool term_fileset(JCR *jcr)
+{
+ FF_PKT *ff = (FF_PKT *)jcr->ff;
+ findFILESET *fileset = ff->fileset;
+ int i, j, k;
+
+ for (i=0; i<fileset->include_list.size(); i++) {
+ findINCEXE *incexe = (findINCEXE *)fileset->include_list.get(i);
+ Dmsg0(400, "I\n");
+ for (j=0; j<incexe->opts_list.size(); j++) {
+ findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j);
+ for (k=0; k<fo->regex.size(); k++) {
+ Dmsg1(400, "R %s\n", (char *)fo->regex.get(k));
+ }
+ for (k=0; k<fo->wild.size(); k++) {
+ Dmsg1(400, "W %s\n", (char *)fo->wild.get(k));
+ }
+ for (k=0; k<fo->base.size(); k++) {
+ Dmsg1(400, "B %s\n", (char *)fo->base.get(k));
+ }
+ if (fo->reader) {
+ Dmsg1(400, "D %s\n", fo->reader);
+ }
+ if (fo->writer) {
+ Dmsg1(400, "T %s\n", fo->writer);
+ }
+ }
+ for (j=0; j<incexe->name_list.size(); j++) {
+ Dmsg1(400, "F %s\n", (char *)incexe->name_list.get(j));
+ }
+ }
+ for (i=0; i<fileset->exclude_list.size(); i++) {
+ findINCEXE *incexe = (findINCEXE *)fileset->exclude_list.get(i);
+ Dmsg0(400, "E\n");
+ for (j=0; j<incexe->opts_list.size(); j++) {
+ findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j);
+ for (k=0; k<fo->regex.size(); k++) {
+ Dmsg1(400, "R %s\n", (char *)fo->regex.get(k));
+ }
+ for (k=0; k<fo->wild.size(); k++) {
+ Dmsg1(400, "W %s\n", (char *)fo->wild.get(k));
+ }
+ for (k=0; k<fo->base.size(); k++) {
+ Dmsg1(400, "B %s\n", (char *)fo->base.get(k));
+ }
+ }
+ for (j=0; j<incexe->name_list.size(); j++) {
+ Dmsg1(400, "F %s\n", (char *)incexe->name_list.get(j));
+ }
+ }
+ return ff->fileset->state != state_error;
+}
+
+
+/*
+ * As an optimization, we should do this during
+ * "compile" time in filed/job.c, and keep only a bit mask
+ * and the Verify options.
+ */
+static void set_options(findFOPTS *fo, const char *opts)
+{
+ int j;
+ const char *p;
+
+ for (p=opts; *p; p++) {
+ switch (*p) {
+ case 'a': /* alway replace */
+ case '0': /* no option */
+ break;
+ case 'e':
+ fo->flags |= FO_EXCLUDE;
+ break;
+ case 'f':
+ fo->flags |= FO_MULTIFS;
+ break;
+ case 'h': /* no recursion */
+ fo->flags |= FO_NO_RECURSION;
+ break;
+ case 'M': /* MD5 */
+ fo->flags |= FO_MD5;
+ break;
+ case 'n':
+ fo->flags |= FO_NOREPLACE;
+ break;
+ case 'p': /* use portable data format */
+ fo->flags |= FO_PORTABLE;
+ break;
+ case 'r': /* read fifo */
+ fo->flags |= FO_READFIFO;
+ break;
+ case 'S':
+ fo->flags |= FO_SHA1;
+ break;
+ case 's':
+ fo->flags |= FO_SPARSE;
+ break;
+ case 'm':
+ fo->flags |= FO_MTIMEONLY;
+ break;
+ case 'k':
+ fo->flags |= FO_KEEPATIME;
+ break;
+ case 'V': /* verify options */
+ /* Copy Verify Options */
+ for (j=0; *p && *p != ':'; p++) {
+ fo->VerifyOpts[j] = *p;
+ if (j < (int)sizeof(fo->VerifyOpts) - 1) {
+ j++;
+ }
+ }
+ fo->VerifyOpts[j] = 0;
+ break;
+ case 'w':
+ fo->flags |= FO_IF_NEWER;
+ break;
+ case 'Z': /* gzip compression */
+ fo->flags |= FO_GZIP;
+ fo->GZIP_level = *++p - '0';
+ Dmsg1(200, "Compression level=%d\n", fo->GZIP_level);
+ break;
+ default:
+ Emsg1(M_ERROR, 0, "Unknown include/exclude option: %c\n", *p);
+ break;
+ }
+ }
+}
+
+
+/*
+ * Director is passing his Fileset
+ */
+static int fileset_cmd(JCR *jcr)
+{
+ BSOCK *dir = jcr->dir_bsock;
+
+ if (!init_fileset(jcr)) {
+ return 0;
+ }
+ while (bnet_recv(dir) >= 0) {
+ strip_trailing_junk(dir->msg);
+ Dmsg1(400, "Fileset: %s\n", dir->msg);
+ add_fileset(jcr, dir->msg);
+ }
+ if (!term_fileset(jcr)) {
+ return 0;
+ }
+ return bnet_fsend(dir, OKinc);
+}
+
+
/*
* Get list of files to exclude from Director
*
unlink(jcr->RestoreBootstrap);
free_pool_memory(jcr->RestoreBootstrap);
}
- Mmsg(&fname, "%s/%s.%s.bootstrap", me->working_directory, me->hdr.name,
+ Mmsg(fname, "%s/%s.%s.bootstrap", me->working_directory, me->hdr.name,
jcr->Job);
Dmsg1(400, "bootstrap=%s\n", fname);
jcr->RestoreBootstrap = fname;
bs = fopen(fname, "a+"); /* create file */
if (!bs) {
+ berrno be;
/*
* Suck up what he is sending to us so that he will then
* read our error message.
{ }
Jmsg(jcr, M_FATAL, 0, _("Could not create bootstrap file %s: ERR=%s\n"),
- jcr->RestoreBootstrap, strerror(errno));
+ jcr->RestoreBootstrap, be.strerror());
free_pool_memory(jcr->RestoreBootstrap);
jcr->RestoreBootstrap = NULL;
set_jcr_job_status(jcr, JS_ErrorTerminated);
his_time = str_to_uint64(buf);
rt = get_current_btime() - bt_start; /* compute round trip time */
bt_adj -= his_time - bt_start - rt/2;
- Dmsg2(100, "rt=%s adj=%s\n", edit_uint64(rt, ed1), edit_uint64(bt_adj, ed2));
+ Dmsg2(200, "rt=%s adj=%s\n", edit_uint64(rt, ed1), edit_uint64(bt_adj, ed2));
}
bt_adj = bt_adj / 8; /* compute average time */
Dmsg2(100, "adj = %d since_time=%d\n", (int)adj, (int)since_time);
jcr->incremental = 1; /* set incremental or decremental backup */
- jcr->mtime = since_time; /* set since time */
+ jcr->mtime = (time_t)since_time; /* set since time */
} else {
Jmsg1(jcr, M_FATAL, 0, "Unknown backup level: %s\n", level);
free_memory(level);
Dmsg3(110, "Open storage: %s:%d ssl=%d\n", jcr->stored_addr, stored_port, enable_ssl);
/* Open command communications with Storage daemon */
/* Try to connect for 1 hour at 10 second intervals */
- sd = bnet_connect(jcr, 10, me->SDConnectTimeout, _("Storage daemon"),
+ sd = bnet_connect(jcr, 10, (int)me->SDConnectTimeout, _("Storage daemon"),
jcr->stored_addr, NULL, stored_port, 1);
if (sd == NULL) {
Jmsg(jcr, M_FATAL, 0, _("Failed to connect to Storage daemon: %s:%d\n"),
jcr->stored_addr, stored_port);
+ Dmsg2(100, "Failed to connect to Storage daemon: %s:%d\n",
+ jcr->stored_addr, stored_port);
return 0;
}
+ Dmsg0(110, "Connection OK to SD.\n");
jcr->store_bsock = sd;
if (!blast_data_to_storage_daemon(jcr, NULL)) {
set_jcr_job_status(jcr, JS_ErrorTerminated);
bnet_suppress_error_messages(sd, 1);
+ Dmsg0(110, "Error in blast_data.\n");
} else {
set_jcr_job_status(jcr, JS_Terminated);
if (jcr->JobStatus != JS_Terminated) {
}
cleanup:
-
bnet_fsend(dir, EndJob, jcr->JobStatus, jcr->JobFiles,
edit_uint64(jcr->ReadBytes, ed1),
edit_uint64(jcr->JobBytes, ed2), jcr->Errors);
+ Dmsg1(110, "End FD msg: %s\n", dir->msg);
return 0; /* return and stop command loop */
}
if (jcr->RunAfterJob) {
free_pool_memory(jcr->RunAfterJob);
}
+
+
return;
}
FILE *bs;
char buf[2000];
BSOCK *sd = jcr->store_bsock;
- char *bootstrap = "bootstrap\n";
+ const char *bootstrap = "bootstrap\n";
int stat = 0;
Dmsg1(400, "send_bootstrap_file: %s\n", jcr->RestoreBootstrap);
}
bs = fopen(jcr->RestoreBootstrap, "r");
if (!bs) {
+ berrno be;
Jmsg(jcr, M_FATAL, 0, _("Could not open bootstrap file %s: ERR=%s\n"),
- jcr->RestoreBootstrap, strerror(errno));
+ jcr->RestoreBootstrap, be.strerror());
set_jcr_job_status(jcr, JS_ErrorTerminated);
goto bail_out;
}
sd->msglen = strlen(sd->msg);
bnet_send(sd);
while (fgets(buf, sizeof(buf), bs)) {
- sd->msglen = Mmsg(&sd->msg, "%s", buf);
+ sd->msglen = Mmsg(sd->msg, "%s", buf);
bnet_send(sd);
}
bnet_sig(sd, BNET_EOD);