From: Kern Sibbald Date: Thu, 16 Jan 2003 18:43:11 +0000 (+0000) Subject: More cleanup X-Git-Tag: Release-1.29~21 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=bf5feaedbcd17bff3c30ef99d5e7291af8b5a6d5;p=bacula%2Fbacula More cleanup git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@299 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/filed/job.c b/bacula/src/filed/job.c index 11c9a06efb..1efc8b930e 100644 --- a/bacula/src/filed/job.c +++ b/bacula/src/filed/job.c @@ -161,7 +161,7 @@ void *handle_client_request(void *dirp) jcr->last_fname = get_pool_memory(PM_FNAME); jcr->last_fname[0] = 0; jcr->client_name = get_memory(strlen(my_name) + 1); - strcpy(jcr->client_name, my_name); + pm_strcpy(&jcr->client_name, my_name); dir->jcr = (void *)jcr; /**********FIXME******* add command handler error code */ @@ -357,6 +357,7 @@ static int bootstrap_cmd(JCR *jcr) jcr->RestoreBootstrap, strerror(errno)); free_pool_memory(jcr->RestoreBootstrap); jcr->RestoreBootstrap = NULL; + set_jcr_job_status(jcr, JS_ErrorTerminated); return 0; } @@ -713,36 +714,46 @@ static int restore_cmd(JCR *jcr) Dmsg1(110, "bfiled>dird: %s", dir->msg); jcr->JobType = JT_RESTORE; - set_jcr_job_status(jcr, JS_Blocked); + set_jcr_job_status(jcr, JS_Blocked); if (!open_sd_read_session(jcr)) { - return 0; + set_jcr_job_status(jcr, JS_ErrorTerminated); + goto bail_out; } + set_jcr_job_status(jcr, JS_Running); + /* * Do restore of files and data */ do_restore(jcr); + set_jcr_job_status(jcr, JS_Terminated); + if (jcr->JobStatus != JS_Terminated) { + bnet_suppress_error_messages(sd, 1); + } + /* * Send Close session command to Storage daemon */ bnet_fsend(sd, read_close, jcr->Ticket); Dmsg1(130, "bfiled>stored: %s", sd->msg); - /* ****FIXME**** check response */ bnet_recv(sd); /* get OK */ /* Inform Storage daemon that we are done */ bnet_sig(sd, BNET_TERMINATE); - bnet_fsend(dir, EndRestore, jcr->JobStatus, jcr->num_files_examined, jcr->JobBytes); +bail_out: + /* Send termination status back to Dir */ + bnet_fsend(dir, EndRestore, jcr->JobStatus, jcr->num_files_examined, + jcr->JobBytes); /* Inform Director that we are done */ bnet_sig(dir, BNET_TERMINATE); Dmsg0(130, "Done in job.c\n"); - return 1; + return !job_cancelled(jcr); } static int open_sd_read_session(JCR *jcr) diff --git a/bacula/src/filed/restore.c b/bacula/src/filed/restore.c index b4d2ec631a..f5d06e3325 100644 --- a/bacula/src/filed/restore.c +++ b/bacula/src/filed/restore.c @@ -68,6 +68,7 @@ void do_restore(JCR *jcr) set_jcr_job_status(jcr, JS_Running); if (!bnet_set_buffer_size(sd, MAX_NETWORK_BUFFER_SIZE, BNET_SETBUF_READ)) { + set_jcr_job_status(jcr, JS_ErrorTerminated); return; } jcr->buf_size = sd->msglen; @@ -126,7 +127,7 @@ void do_restore(JCR *jcr) */ if (extract) { if (ofd < 0) { - Emsg0(M_ERROR, 0, _("Logic error output file should be open\n")); + Jmsg0(jcr, M_ERROR, 0, _("Logic error output file should be open\n")); } set_attributes(jcr, fname, ofile, lname, type, stream, &statp, attribsEx, &ofd); @@ -359,7 +360,7 @@ void do_restore(JCR *jcr) } else if (extract) { Dmsg1(30, "Found wierd stream %d\n", stream); if (ofd < 0) { - Emsg0(M_ERROR, 0, _("Logic error output file should be open\n")); + Jmsg0(jcr, M_ERROR, 0, _("Logic error output file should be open\n")); } set_attributes(jcr, fname, ofile, lname, type, stream, &statp, attribsEx, &ofd); @@ -417,16 +418,18 @@ static void print_ls_output(JCR *jcr, char *fname, char *lname, int type, struct p = encode_time(statp->st_ctime, p); *p++ = ' '; *p++ = ' '; - for (f=fname; *f && (p-buf) < (int)sizeof(buf); ) + for (f=fname; *f && (p-buf) < (int)sizeof(buf)-10; ) { *p++ = *f++; + } if (type == FT_LNK) { *p++ = ' '; *p++ = '-'; *p++ = '>'; *p++ = ' '; /* Copy link name */ - for (f=lname; *f && (p-buf) < (int)sizeof(buf); ) + for (f=lname; *f && (p-buf) < (int)sizeof(buf)-10; ) { *p++ = *f++; + } } *p++ = '\n'; *p = 0; diff --git a/bacula/src/filed/verify.c b/bacula/src/filed/verify.c index f089e23062..410eaaa58c 100644 --- a/bacula/src/filed/verify.c +++ b/bacula/src/filed/verify.c @@ -42,7 +42,7 @@ void do_verify(JCR *jcr) jcr->buf_size = MAX_NETWORK_BUFFER_SIZE; if ((jcr->big_buf = (char *) malloc(jcr->buf_size)) == NULL) { - Emsg1(M_ABORT, 0, _("Cannot malloc %d network read buffer\n"), MAX_NETWORK_BUFFER_SIZE); + Jmsg1(jcr, M_ABORT, 0, _("Cannot malloc %d network read buffer\n"), MAX_NETWORK_BUFFER_SIZE); } set_find_options((FF_PKT *)jcr->ff, jcr->incremental, jcr->mtime); Dmsg0(10, "Start find files\n"); diff --git a/bacula/src/filed/verify_vol.c b/bacula/src/filed/verify_vol.c index 7386777da6..fff1f556d9 100644 --- a/bacula/src/filed/verify_vol.c +++ b/bacula/src/filed/verify_vol.c @@ -217,8 +217,12 @@ void do_verify_volume(JCR *jcr) Pmsg2(0, "None of above!!! stream=%d data=%s\n", stream,sd->msg); } } + set_jcr_job_status(jcr, JS_Terminated); + goto ok_out; bail_out: + set_jcr_job_status(jcr, JS_ErrorTerminated); +ok_out: if (jcr->compress_buf) { free(jcr->compress_buf); jcr->compress_buf = NULL; @@ -253,7 +257,7 @@ static void print_ls_output(JCR *jcr, char *fname, char *lname, int type, struct p = encode_time(statp->st_ctime, p); *p++ = ' '; *p++ = ' '; - for (f=fname; *f && (p-buf) < (int)sizeof(buf); ) + for (f=fname; *f && (p-buf) < (int)sizeof(buf)-10; ) *p++ = *f++; if (type == FT_LNK) { *p++ = ' '; @@ -261,7 +265,7 @@ static void print_ls_output(JCR *jcr, char *fname, char *lname, int type, struct *p++ = '>'; *p++ = ' '; /* Copy link name */ - for (f=lname; *f && (p-buf) < (int)sizeof(buf); ) + for (f=lname; *f && (p-buf) < (int)sizeof(buf)-10; ) *p++ = *f++; } *p++ = '\n'; diff --git a/bacula/src/findlib/match.c b/bacula/src/findlib/match.c index 3701860623..b22d2883b3 100644 --- a/bacula/src/findlib/match.c +++ b/bacula/src/findlib/match.c @@ -93,8 +93,7 @@ void add_fname_to_include_list(FF_PKT *ff, int prefixed, char *fname) len = strlen(fname); - inc =(struct s_included_file *) bmalloc(sizeof(struct s_included_file) + len + 1); - inc->next = ff->included_files_list; + inc =(struct s_included_file *)bmalloc(sizeof(struct s_included_file) + len + 1); inc->options = 0; inc->VerifyOpts[0] = 'V'; inc->VerifyOpts[1] = ':'; @@ -172,7 +171,18 @@ void add_fname_to_include_list(FF_PKT *ff, int prefixed, char *fname) break; } } - ff->included_files_list = inc; + inc->next = NULL; + /* Chain this one on the end of the list */ + if (!ff->included_files_list) { + /* First one, so set head */ + ff->included_files_list = inc; + } else { + struct s_included_file *next; + /* Walk to end of list */ + for (next=ff->included_files_list; next->next; next=next->next) + { } + next->next = inc; + } Dmsg1(50, "add_fname_to_include fname=%s\n", inc->fname); } diff --git a/bacula/src/lib/message.c b/bacula/src/lib/message.c index 22dcdac944..13c4b39e15 100755 --- a/bacula/src/lib/message.c +++ b/bacula/src/lib/message.c @@ -8,7 +8,7 @@ */ /* - Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker + Copyright (C) 2000-2003 Kern Sibbald and John Walker This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -432,7 +432,6 @@ void close_msg(void *vjcr) if (msgs != daemon_msgs) { /* read what mail prog returned -- should be nothing */ while (fgets(line, len, bpipe->rfd)) { -// Dmsg1(000, "Mail prog got: %s", line); Jmsg1(jcr, M_INFO, 0, _("Mail prog: %s"), line); } } @@ -688,7 +687,7 @@ void d_msg(char *file, int line, int level, char *fmt,...) { char buf[5000]; - int i; + int len; va_list arg_ptr; int details = TRUE; @@ -700,15 +699,15 @@ d_msg(char *file, int line, int level, char *fmt,...) if (level <= debug_level) { #ifdef FULL_LOCATION if (details) { - i= sprintf(buf, "%s: %s:%d ", my_name, file, line); + len= sprintf(buf, "%s: %s:%d ", my_name, file, line); } else { - i = 0; + len = 0; } #else - i = 0; + len = 0; #endif va_start(arg_ptr, fmt); - bvsnprintf(buf+i, sizeof(buf)-i, (char *)fmt, arg_ptr); + bvsnprintf(buf+len, sizeof(buf)-len, (char *)fmt, arg_ptr); va_end(arg_ptr); fputs(buf, stdout); @@ -730,7 +729,7 @@ void t_msg(char *file, int line, int level, char *fmt,...) { char buf[5000]; - int i; + int len; va_list arg_ptr; int details = TRUE; @@ -752,16 +751,15 @@ t_msg(char *file, int line, int level, char *fmt,...) #ifdef FULL_LOCATION if (details) { - sprintf(buf, "%s: %s:%d ", my_name, file, line); - i = strlen(buf); + len = sprintf(buf, "%s: %s:%d ", my_name, file, line); } else { - i = 0; + len = 0; } #else - i = 0; + len = 0; #endif va_start(arg_ptr, fmt); - bvsnprintf(buf+i, sizeof(buf)-i, (char *)fmt, arg_ptr); + bvsnprintf(buf+len, sizeof(buf)-len, (char *)fmt, arg_ptr); va_end(arg_ptr); fputs(buf, trace_fd); @@ -781,7 +779,7 @@ e_msg(char *file, int line, int type, int level, char *fmt,...) { char buf[5000]; va_list arg_ptr; - int i; + int len; /* * Check if we have a message destination defined. @@ -793,36 +791,35 @@ e_msg(char *file, int line, int type, int level, char *fmt,...) } switch (type) { case M_ABORT: - sprintf(buf, "%s: ABORTING due to ERROR in %s:%d\n", + len = sprintf(buf, "%s: ABORTING due to ERROR in %s:%d\n", my_name, file, line); break; case M_ERROR_TERM: - sprintf(buf, "%s: ERROR TERMINATION at %s:%d\n", + len = sprintf(buf, "%s: ERROR TERMINATION at %s:%d\n", my_name, file, line); break; case M_FATAL: if (level == -1) /* skip details */ - sprintf(buf, "%s: Fatal Error because: ", my_name); + len = sprintf(buf, "%s: Fatal Error because: ", my_name); else - sprintf(buf, "%s: Fatal Error at %s:%d because:\n", my_name, file, line); + len = sprintf(buf, "%s: Fatal Error at %s:%d because:\n", my_name, file, line); break; case M_ERROR: if (level == -1) /* skip details */ - sprintf(buf, "%s: Error: ", my_name); + len = sprintf(buf, "%s: Error: ", my_name); else - sprintf(buf, "%s: Error in %s:%d ", my_name, file, line); + len = sprintf(buf, "%s: Error in %s:%d ", my_name, file, line); break; case M_WARNING: - sprintf(buf, "%s: Warning: ", my_name); + len = sprintf(buf, "%s: Warning: ", my_name); break; default: - sprintf(buf, "%s: ", my_name); + len = sprintf(buf, "%s: ", my_name); break; } - i = strlen(buf); va_start(arg_ptr, fmt); - bvsnprintf(buf+i, sizeof(buf)-i, (char *)fmt, arg_ptr); + bvsnprintf(buf+len, sizeof(buf)-len, (char *)fmt, arg_ptr); va_end(arg_ptr); dispatch_message(NULL, type, level, buf); @@ -845,9 +842,8 @@ void Jmsg(void *vjcr, int type, int level, char *fmt,...) { char rbuf[5000]; - char *buf; va_list arg_ptr; - int i, len; + int len; JCR *jcr = (JCR *)vjcr; MSGS *msgs; char *job; @@ -862,22 +858,17 @@ Jmsg(void *vjcr, int type, int level, char *fmt,...) job = jcr->Job; } if (!msgs) { - msgs = daemon_msgs; + msgs = daemon_msgs; /* if no jcr, we use daemon handler */ } if (!job) { - job = ""; + job = ""; /* Set null job name if none */ } - buf = rbuf; /* we are the Director */ /* * Check if we have a message destination defined. * We always report M_ABORT and M_ERROR_TERM */ -/* - * Tmsg5(000, "jcr=%x msgs=%x type=%d send_msg=%x *msg=%x\n", - * jcr, msgs, type, msgs->send_msg, (int)msgs->send_msg[0]); - */ /* There is an apparent compiler bug with the following if * statement, so the set_jcr... is simply a noop to reload * registers. @@ -889,40 +880,37 @@ Jmsg(void *vjcr, int type, int level, char *fmt,...) } switch (type) { case M_ABORT: - sprintf(buf, "%s ABORTING due to ERROR\n", my_name); + len = sprintf(rbuf, "%s ABORTING due to ERROR\n", my_name); break; case M_ERROR_TERM: - sprintf(buf, "%s ERROR TERMINATION\n", my_name); + len = sprintf(rbuf, "%s ERROR TERMINATION\n", my_name); break; case M_FATAL: - sprintf(buf, "%s: %s Fatal error: ", my_name, job); + len = sprintf(rbuf, "%s: %s Fatal error: ", my_name, job); if (jcr) { - jcr->JobStatus = JS_FatalError; + set_jcr_job_status(jcr, JS_FatalError); } break; case M_ERROR: - sprintf(buf, "%s: %s Error: ", my_name, job); + len = sprintf(rbuf, "%s: %s Error: ", my_name, job); if (jcr) { jcr->Errors++; } break; case M_WARNING: - sprintf(buf, "%s: %s Warning: ", my_name, job); + len = sprintf(rbuf, "%s: %s Warning: ", my_name, job); break; default: - sprintf(buf, "%s: ", my_name); + len = sprintf(rbuf, "%s: ", my_name); break; } - i = strlen(buf); va_start(arg_ptr, fmt); - len = bvsnprintf(buf+i, sizeof(rbuf)-i, fmt, arg_ptr); + bvsnprintf(rbuf+len, sizeof(rbuf)-len, fmt, arg_ptr); va_end(arg_ptr); dispatch_message(jcr, type, level, rbuf); - Dmsg3(500, "i=%d sizeof(rbuf)-i=%d len=%d\n", i, sizeof(rbuf)-i, len); - if (type == M_ABORT){ char *p = 0; p[0] = 0; /* generate segmentation violation */ @@ -940,8 +928,7 @@ int m_msg(char *file, int line, POOLMEM **pool_buf, char *fmt, ...) va_list arg_ptr; int i, len, maxlen; - sprintf(*pool_buf, "%s:%d ", file, line); - i = strlen(*pool_buf); + i = sprintf(*pool_buf, "%s:%d ", file, line); again: maxlen = sizeof_pool_memory(*pool_buf) - i - 1; @@ -1000,6 +987,6 @@ again: goto again; } - Jmsg(jcr, type, level, pool_buf); + Jmsg(jcr, type, level, "%s", pool_buf); free_memory(pool_buf); }