/* * Format a scanner error message */ static void s_err(const char *file, int line, LEX *lc, const char *msg, ...) { ConfigFile *ini = (ConfigFile *)(lc->caller_ctx); va_list arg_ptr; char buf[MAXSTRING]; va_start(arg_ptr, msg); bvsnprintf(buf, sizeof(buf), msg, arg_ptr); va_end(arg_ptr); #ifdef TEST_PROGRAM printf("ERROR: Config file error: %s\n" " : Line %d, col %d of file %s\n%s\n", buf, lc->line_no, lc->col_no, lc->fname, lc->line); #endif if (ini->jcr) { /* called from core */ Jmsg(ini->jcr, M_ERROR, 0, _("Config file error: %s\n" " : Line %d, col %d of file %s\n%s\n"), buf, lc->line_no, lc->col_no, lc->fname, lc->line); // } else if (ini->ctx) { /* called from plugin */ // ini->bfuncs->JobMessage(ini->ctx, __FILE__, __LINE__, M_FATAL, 0, // _("Config file error: %s\n" // " : Line %d, col %d of file %s\n%s\n"), // buf, lc->line_no, lc->col_no, lc->fname, lc->line); // } else { /* called from ??? */ e_msg(file, line, M_ERROR, 0, _("Config file error: %s\n" " : Line %d, col %d of file %s\n%s\n"), buf, lc->line_no, lc->col_no, lc->fname, lc->line); } }
/* * Format a scanner warning message */ static void s_warn(const char *file, int line, LEX *lc, const char *msg, ...) { va_list ap; int len, maxlen; POOL_MEM buf(PM_NAME); JCR *jcr = (JCR *)(lc->caller_ctx); while (1) { maxlen = buf.size() - 1; va_start(ap, msg); len = bvsnprintf(buf.c_str(), maxlen, msg, ap); va_end(ap); if (len < 0 || len >= (maxlen - 5)) { buf.realloc_pm(maxlen + maxlen / 2); continue; } break; } if (jcr) { Jmsg(jcr, M_WARNING, 0, _("Bootstrap file warning: %s\n" " : Line %d, col %d of file %s\n%s\n"), buf.c_str(), lc->line_no, lc->col_no, lc->fname, lc->line); } else { p_msg(file, line, 0, _("Bootstrap file warning: %s\n" " : Line %d, col %d of file %s\n%s\n"), buf.c_str(), lc->line_no, lc->col_no, lc->fname, lc->line); } }
/* * Format a scanner warning message */ static void s_warn(const char *file, int line, LEX *lc, const char *msg, ...) { va_list ap; int len, maxlen; POOL_MEM buf(PM_NAME), more(PM_NAME); while (1) { maxlen = buf.size() - 1; va_start(ap, msg); len = bvsnprintf(buf.c_str(), maxlen, msg, ap); va_end(ap); if (len < 0 || len >= (maxlen - 5)) { buf.realloc_pm(maxlen + maxlen / 2); continue; } break; } if (lc->line_no > lc->begin_line_no) { Mmsg(more, _("Problem probably begins at line %d.\n"), lc->begin_line_no); } else { pm_strcpy(more, ""); } if (lc->line_no > 0) { p_msg(file, line, 0, _("Config warning: %s\n" " : line %d, col %d of file %s\n%s\n%s"), buf.c_str(), lc->line_no, lc->col_no, lc->fname, lc->line, more.c_str()); } else { p_msg(file, line, 0, _("Config warning: %s\n"), buf.c_str()); } }
void bmsg(UAContext *ua, const char *fmt, va_list arg_ptr) { BSOCK *bs = ua->UA_sock; int maxlen, len; POOLMEM *msg = NULL; if (bs) { msg = bs->msg; } if (!msg) { msg = get_memory(5000); } maxlen = sizeof_pool_memory(msg) - 1; if (maxlen < 4999) { msg = realloc_pool_memory(msg, 5000); maxlen = 4999; } len = bvsnprintf(msg, maxlen, fmt, arg_ptr); if (len < 0 || len >= maxlen) { pm_strcpy(msg, _("Message too long to display.\n")); len = strlen(msg); } if (bs) { bs->msg = msg; bs->msglen = len; bs->send(); } else { /* No UA, send to Job */ Jmsg(ua->jcr, M_INFO, 0, "%s", msg); free_pool_memory(msg); } }
void bmsg(UAContext *ua, const char *fmt, va_list arg_ptr) { BSOCK *bs = ua->UA_sock; int maxlen, len; POOLMEM *msg = NULL; va_list ap; if (bs) { msg = bs->msg; } if (!msg) { msg = get_pool_memory(PM_EMSG); } again: maxlen = sizeof_pool_memory(msg) - 1; va_copy(ap, arg_ptr); len = bvsnprintf(msg, maxlen, fmt, ap); va_end(ap); if (len < 0 || len >= maxlen) { msg = realloc_pool_memory(msg, maxlen + maxlen/2); goto again; } if (bs) { bs->msg = msg; bs->msglen = len; bs->send(); } else { /* No UA, send to Job */ Jmsg(ua->jcr, M_INFO, 0, "%s", msg); free_pool_memory(msg); } }
/* * Format and send a message * Returns: false on error * true on success */ bool BSOCK::fsend(const char *fmt, ...) { va_list arg_ptr; int maxlen; if (errors || is_terminated()) { return false; } /* This probably won't work, but we vsnprintf, then if we * get a negative length or a length greater than our buffer * (depending on which library is used), the printf was truncated, so * get a bigger buffer and try again. */ for (;;) { maxlen = sizeof_pool_memory(msg) - 1; va_start(arg_ptr, fmt); msglen = bvsnprintf(msg, maxlen, fmt, arg_ptr); va_end(arg_ptr); if (msglen >= 0 && msglen < (maxlen - 5)) { break; } msg = realloc_pool_memory(msg, maxlen + maxlen / 2); } return send(); }
static void configure_lex_error_handler(const char *file, int line, LEX *lc, const char *msg, ...) { /* * This function is an error handler, used by lex. */ va_list ap; int len, maxlen; POOL_MEM buf(PM_NAME); while (1) { maxlen = buf.size() - 1; va_start(ap, msg); len = bvsnprintf(buf.c_str(), maxlen, msg, ap); va_end(ap); if (len < 0 || len >= (maxlen - 5)) { buf.realloc_pm(maxlen + maxlen / 2); continue; } break; } configure_lex_error_handler(file, line, lc, buf); }
/* * Implement snprintf */ int bsnprintf(char *str, int32_t size, const char *fmt, ...) { va_list arg_ptr; int len; va_start(arg_ptr, fmt); len = bvsnprintf(str, size, fmt, arg_ptr); va_end(arg_ptr); return len; }
/* * Special version of error reporting using a static buffer so we don't use * the normal error reporting which uses dynamic memory e.g. recursivly calls * these routines again leading to deadlocks. */ static void smart_alloc_msg(const char *file, int line, const char *fmt, ...) { char buf[256]; va_list arg_ptr; int len; len = bsnprintf(buf, sizeof(buf), _("%s: ABORTING due to ERROR in %s:%d\n"), my_name, get_basename(file), line); va_start(arg_ptr, fmt); bvsnprintf(buf + len, sizeof(buf) - len, (char *)fmt, arg_ptr); va_end(arg_ptr); dispatch_message(NULL, M_ABORT, 0, buf); char *p = 0; p[0] = 0; /* Generate segmentation violation */ }
/** * cli_printf - send reply to a CLI connection * @c: CLI connection * @code: numeric code of the reply, negative for continuation lines * @msg: a printf()-like formatting string. * * This function send a single line of reply to a given CLI connection. * In works in all aspects like bsprintf() except that it automatically * prepends the reply line prefix. * * Please note that if the connection can be already busy sending some * data in which case cli_printf() stores the output to a temporary buffer, * so please avoid sending a large batch of replies without waiting * for the buffers to be flushed. * * If you want to write to the current CLI output, you can use the cli_msg() * macro instead. */ void cli_printf(struct cli *c, int code, char *msg, ...) { va_list args; byte buf[CLI_LINE_SIZE]; int cd = code; int errcode; int size, cnt; if (cd < 0) { cd = -cd; if (cd == c->last_reply) size = bsprintf(buf, " "); else size = bsprintf(buf, "%04d-", cd); errcode = -8000; } else if (cd == CLI_ASYNC_CODE) { size = 1; buf[0] = '+'; errcode = cd; } else { size = bsprintf(buf, "%04d ", cd); errcode = 8000; } c->last_reply = cd; va_start(args, msg); cnt = bvsnprintf(buf+size, sizeof(buf)-size-1, msg, args); va_end(args); if (cnt < 0) { cli_printf(c, errcode, "<line overflow>"); return; } size += cnt; buf[size++] = '\n'; memcpy(cli_alloc_out(c, size), buf, size); }
/* * Format a scanner error message */ static void s_err(const char *file, int line, LEX *lc, const char *msg, ...) { JCR *jcr = (JCR *)(lc->caller_ctx); va_list arg_ptr; char buf[MAXSTRING]; va_start(arg_ptr, msg); bvsnprintf(buf, sizeof(buf), msg, arg_ptr); va_end(arg_ptr); if (jcr) { Jmsg(jcr, M_FATAL, 0, _("Bootstrap file error: %s\n" " : Line %d, col %d of file %s\n%s\n"), buf, lc->line_no, lc->col_no, lc->fname, lc->line); } else { e_msg(file, line, M_FATAL, 0, _("Bootstrap file error: %s\n" " : Line %d, col %d of file %s\n%s\n"), buf, lc->line_no, lc->col_no, lc->fname, lc->line); } }
/* * Print a BSR entry into a memory buffer. */ static void print_bsr_item(POOL_MEM *pool_buf, const char *fmt, ...) { va_list arg_ptr; int len, maxlen; POOL_MEM item(PM_MESSAGE); while (1) { maxlen = item.max_size() - 1; va_start(arg_ptr, fmt); len = bvsnprintf(item.c_str(), maxlen, fmt, arg_ptr); va_end(arg_ptr); if (len < 0 || len >= (maxlen - 5)) { item.realloc_pm(maxlen + maxlen / 2); continue; } break; } pool_buf->strcat(item.c_str()); }
/* * Format a scanner error message */ static void s_warn(const char *file, int line, LEX *lc, const char *msg, ...) { va_list ap; int len, maxlen; ConfigFile *ini; POOL_MEM buf(PM_MESSAGE); while (1) { maxlen = buf.size() - 1; va_start(ap, msg); len = bvsnprintf(buf.c_str(), maxlen, msg, ap); va_end(ap); if (len < 0 || len >= (maxlen - 5)) { buf.realloc_pm(maxlen + maxlen / 2); continue; } break; } ini = (ConfigFile *)(lc->caller_ctx); if (ini->jcr) { /* called from core */ Jmsg(ini->jcr, M_WARNING, 0, _("Config file warning: %s\n" " : Line %d, col %d of file %s\n%s\n"), buf.c_str(), lc->line_no, lc->col_no, lc->fname, lc->line); // } else if (ini->ctx) { /* called from plugin */ // ini->bfuncs->JobMessage(ini->ctx, __FILE__, __LINE__, M_WARNING, 0, // _("Config file warning: %s\n" // " : Line %d, col %d of file %s\n%s\n"), // buf.c_str(), lc->line_no, lc->col_no, lc->fname, lc->line); // } else { /* called from ??? */ p_msg(file, line, 0, _("Config file warning: %s\n" " : Line %d, col %d of file %s\n%s\n"), buf.c_str(), lc->line_no, lc->col_no, lc->fname, lc->line); } }