Skip to content

Commit

Permalink
Merge branch 'bareos-15.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco van Wieringen committed Jan 1, 2016
2 parents 0ed68c1 + 273b26d commit 207398b
Show file tree
Hide file tree
Showing 16 changed files with 165 additions and 115 deletions.
4 changes: 2 additions & 2 deletions src/dird/dird.c
Expand Up @@ -1041,8 +1041,8 @@ static bool check_resources()
if (me->secure_erase_cmdline) {
set_secure_erase_cmdline(me->secure_erase_cmdline);
}
if (me->log_date_format) {
set_log_date_format(me->log_date_format);
if (me->log_timestamp_format) {
set_log_timestamp_format(me->log_timestamp_format);
}
}

Expand Down
9 changes: 6 additions & 3 deletions src/dird/dird_conf.c
Expand Up @@ -148,7 +148,7 @@ static RES_ITEM dir_items[] = {
{ "AuditEvents", CFG_TYPE_AUDIT, ITEM(res_dir.audit_events), 0, 0, NULL, "14.2.0-", NULL },
{ "SecureEraseCommand", CFG_TYPE_STR, ITEM(res_dir.secure_erase_cmdline), 0, 0, NULL, "15.2.1-",
"Specify command that will be called when bareos unlinks files." },
{ "LogDateFormat", CFG_TYPE_STR, ITEM(res_dir.log_date_format), 0, 0, NULL, NULL, NULL },
{ "LogTimestampFormat", CFG_TYPE_STR, ITEM(res_dir.log_timestamp_format), 0, 0, NULL, "15.2.3-", NULL },
{ NULL, 0, { 0 }, 0, 0, NULL, NULL, NULL }
};

Expand Down Expand Up @@ -2394,8 +2394,8 @@ void free_resource(RES *sres, int type)
if (res->res_dir.secure_erase_cmdline) {
free(res->res_dir.secure_erase_cmdline);
}
if (res->res_dir.log_date_format) {
free(res->res_dir.log_date_format);
if (res->res_dir.log_timestamp_format) {
free(res->res_dir.log_timestamp_format);
}
break;
case R_DEVICE:
Expand Down Expand Up @@ -2646,6 +2646,9 @@ void free_resource(RES *sres, int type)
if (res->res_msgs.operator_cmd) {
free(res->res_msgs.operator_cmd);
}
if (res->res_msgs.timestamp_format) {
free(res->res_msgs.timestamp_format);
}
free_msgs_res((MSGSRES *)res); /* free message resource */
res = NULL;
break;
Expand Down
2 changes: 1 addition & 1 deletion src/dird/dird_conf.h
Expand Up @@ -146,7 +146,7 @@ class DIRRES: public BRSRES {
uint32_t stats_collect_interval; /* Statistics collect interval in seconds */
char *verid; /* Custom Id to print in version command */
char *secure_erase_cmdline; /* Cmdline to execute to perform secure erase of file */
char *log_date_format; /* Date format to use in generic logging messages */
char *log_timestamp_format; /* Timestamp format to use in generic logging messages */
s_password keyencrkey; /* Key Encryption Key */
};

Expand Down
4 changes: 2 additions & 2 deletions src/filed/filed.c
Expand Up @@ -603,8 +603,8 @@ static bool check_resources()
if (me->secure_erase_cmdline) {
set_secure_erase_cmdline(me->secure_erase_cmdline);
}
if (me->log_date_format) {
set_log_date_format(me->log_date_format);
if (me->log_timestamp_format) {
set_log_timestamp_format(me->log_timestamp_format);
}
}

Expand Down
9 changes: 6 additions & 3 deletions src/filed/filed_conf.c
Expand Up @@ -123,7 +123,7 @@ static RES_ITEM cli_items[] = {
{ "LmdbThreshold", CFG_TYPE_PINT32, ITEM(res_client.lmdb_threshold), 0, 0, NULL, NULL, NULL },
{ "SecureEraseCommand", CFG_TYPE_STR, ITEM(res_client.secure_erase_cmdline), 0, 0, NULL, "15.2.1-",
"Specify command that will be called when bareos unlinks files." },
{ "LogDateFormat", CFG_TYPE_STR, ITEM(res_client.log_date_format), 0, 0, NULL, NULL, NULL },
{ "LogTimestampFormat", CFG_TYPE_STR, ITEM(res_client.log_timestamp_format), 0, 0, NULL, "15.2.3-", NULL },
{ NULL, 0, { 0 }, 0, 0, NULL, NULL, NULL }
};

Expand Down Expand Up @@ -366,8 +366,8 @@ void free_resource(RES *sres, int type)
if (res->res_client.secure_erase_cmdline) {
free(res->res_client.secure_erase_cmdline);
}
if (res->res_client.log_date_format) {
free(res->res_client.log_date_format);
if (res->res_client.log_timestamp_format) {
free(res->res_client.log_timestamp_format);
}
break;
case R_MSGS:
Expand All @@ -377,6 +377,9 @@ void free_resource(RES *sres, int type)
if (res->res_msgs.operator_cmd) {
free(res->res_msgs.operator_cmd);
}
if (res->res_msgs.timestamp_format) {
free(res->res_msgs.timestamp_format);
}
free_msgs_res((MSGSRES *)res); /* free message resource */
res = NULL;
break;
Expand Down
2 changes: 1 addition & 1 deletion src/filed/filed_conf.h
Expand Up @@ -117,7 +117,7 @@ class CLIENTRES : public BRSRES {
TLS_CONTEXT *tls_ctx; /* Shared TLS Context */
char *verid; /* Custom Id to print in version command */
char *secure_erase_cmdline; /* Cmdline to execute to perform secure erase of file */
char *log_date_format; /* Date format to use in generic logging messages */
char *log_timestamp_format; /* Timestamp format to use in generic logging messages */
uint64_t max_bandwidth_per_job; /* Bandwidth limitation (global) */
};

Expand Down
4 changes: 2 additions & 2 deletions src/include/version.h
Expand Up @@ -4,8 +4,8 @@
#define LSMDATE "16Nov15"

#define PROG_COPYRIGHT "Copyright (C) %d-2012 Free Software Foundation Europe e.V.\n" \
"Copyright (C) 2013-2015 Bareos GmbH & Co. KG\n"
#define BYEAR "2015" /* year for copyright messages in progs */
"Copyright (C) 2013-2016 Bareos GmbH & Co. KG\n"
#define BYEAR "2016" /* year for copyright messages in progs */

/*
BAREOS® - Backup Archiving REcovery Open Sourced
Expand Down
62 changes: 43 additions & 19 deletions src/lib/message.c
Expand Up @@ -76,7 +76,7 @@ void setup_tsd_key();
static pthread_mutex_t fides_mutex = PTHREAD_MUTEX_INITIALIZER;
static MSGSRES *daemon_msgs; /* Global messages */
static char *catalog_db = NULL; /* Database type */
static const char *log_date_format = "%d-%b %H:%M";
static const char *log_timestamp_format = "%d-%b %H:%M";
static void (*message_callback)(int type, char *msg) = NULL;
static FILE *trace_fd = NULL;
#if defined(HAVE_WIN32)
Expand Down Expand Up @@ -145,13 +145,11 @@ static void delivery_error(const char *fmt,...)
int i, len, maxlen;
POOLMEM *pool_buf;
char dt[MAX_TIME_LENGTH];
int dtlen;

pool_buf = get_pool_memory(PM_EMSG);

bstrftime(dt, sizeof(dt), time(NULL), log_date_format);
bstrftime(dt, sizeof(dt), time(NULL), log_timestamp_format);
bstrncat(dt, " ", sizeof(dt));
dtlen = strlen(dt);

i = Mmsg(pool_buf, "%s Message delivery ERROR: ", dt);

Expand Down Expand Up @@ -306,7 +304,7 @@ void init_msg(JCR *jcr, MSGSRES *msg, job_code_callback_t job_code_callback)
daemon_msgs = (MSGSRES *)malloc(sizeof(MSGSRES));
memset(daemon_msgs, 0, sizeof(MSGSRES));
for (i=1; i<=M_MAX; i++) {
add_msg_dest(daemon_msgs, MD_STDOUT, i, NULL, NULL);
add_msg_dest(daemon_msgs, MD_STDOUT, i, NULL, NULL, NULL);
}
Dmsg1(050, "Create daemon global message resource %p\n", daemon_msgs);
return;
Expand Down Expand Up @@ -392,7 +390,8 @@ void init_console_msg(const char *wd)
* but in the case of MAIL is a space separated list of
* email addresses, ...
*/
void add_msg_dest(MSGSRES *msg, int dest_code, int msg_type, char *where, char *mail_cmd)
void add_msg_dest(MSGSRES *msg, int dest_code, int msg_type,
char *where, char *mail_cmd, char *timestamp_format)
{
DEST *d;

Expand All @@ -406,7 +405,7 @@ void add_msg_dest(MSGSRES *msg, int dest_code, int msg_type, char *where, char *
Dmsg4(850, "Add to existing d=%p msgtype=%d destcode=%d where=%s\n",
d, msg_type, dest_code, NPRT(where));
set_bit(msg_type, d->msg_types);
set_bit(msg_type, msg->send_msg); /* set msg_type bit in our local */
set_bit(msg_type, msg->send_msg); /* Set msg_type bit in our local */
return;
}
}
Expand All @@ -418,16 +417,23 @@ void add_msg_dest(MSGSRES *msg, int dest_code, int msg_type, char *where, char *
memset(d, 0, sizeof(DEST));
d->next = msg->dest_chain;
d->dest_code = dest_code;
set_bit(msg_type, d->msg_types); /* set type bit in structure */
set_bit(msg_type, msg->send_msg); /* set type bit in our local */
set_bit(msg_type, d->msg_types); /* Set type bit in structure */
set_bit(msg_type, msg->send_msg); /* Set type bit in our local */

if (where) {
d->where = bstrdup(where);
}

if (mail_cmd) {
d->mail_cmd = bstrdup(mail_cmd);
}
Dmsg5(850, "add new d=%p msgtype=%d destcode=%d where=%s mailcmd=%s\n",
d, msg_type, dest_code, NPRT(where), NPRT(d->mail_cmd));

if (timestamp_format) {
d->timestamp_format = bstrdup(timestamp_format);
}

Dmsg6(850, "add new d=%p msgtype=%d destcode=%d where=%s mailcmd=%s timestampformat=%s\n",
d, msg_type, dest_code, NPRT(where), NPRT(d->mail_cmd), NPRT(d->timestamp_format));
msg->dest_chain = d;
}

Expand Down Expand Up @@ -681,6 +687,9 @@ void free_msgs_res(MSGSRES *msgs)
if (d->mail_cmd) {
free(d->mail_cmd);
}
if (d->timestamp_format) {
free(d->timestamp_format);
}
old = d; /* save pointer to release */
d = d->next; /* point to next buffer */
free(old); /* free the destination item */
Expand Down Expand Up @@ -844,7 +853,7 @@ void dispatch_message(JCR *jcr, int type, utime_t mtime, char *msg)
MSGSRES *msgs;
BPIPE *bpipe;
const char *mode;
bool dt_set = false;
bool dt_conversion = false;

Dmsg2(850, "Enter dispatch_message type=%d msg=%s", type, msg);

Expand All @@ -861,12 +870,9 @@ void dispatch_message(JCR *jcr, int type, utime_t mtime, char *msg)
if (mtime == 1) {
*dt = 0;
dtlen = 0;
mtime = time(NULL); /* get time for SQL log */
mtime = time(NULL); /* Get time for SQL log */
} else {
bstrftime(dt, sizeof(dt), mtime, log_date_format);
bstrncat(dt, " ", sizeof(dt));
dtlen = strlen(dt);
dt_set = true;
dt_conversion = true;
}

/*
Expand Down Expand Up @@ -926,6 +932,10 @@ void dispatch_message(JCR *jcr, int type, utime_t mtime, char *msg)
* If closing this message resource, print and send to syslog, then get out.
*/
if (msgs->is_closing()) {
if (dt_conversion) {
bstrftime(dt, sizeof(dt), mtime, log_timestamp_format);
bstrncat(dt, " ", sizeof(dt));
}
fputs(dt, stdout);
fputs(msg, stdout);
fflush(stdout);
Expand All @@ -935,6 +945,20 @@ void dispatch_message(JCR *jcr, int type, utime_t mtime, char *msg)

for (d = msgs->dest_chain; d; d = d->next) {
if (bit_is_set(type, d->msg_types)) {
/*
* See if a specific timestamp format was specified for this log resource.
* Otherwise apply the global setting in log_timestamp_format.
*/
if (dt_conversion) {
if (d->timestamp_format) {
bstrftime(dt, sizeof(dt), mtime, d->timestamp_format);
} else {
bstrftime(dt, sizeof(dt), mtime, log_timestamp_format);
}
bstrncat(dt, " ", sizeof(dt));
dtlen = strlen(dt);
}

switch (d->dest_code) {
case MD_CATALOG:
if (!jcr || !jcr->db) {
Expand Down Expand Up @@ -1875,7 +1899,7 @@ void q_msg(const char *file, int line, JCR *jcr, int type, utime_t mtime, const
/*
* Set gobal date format used for log messages.
*/
void set_log_date_format(const char *format)
void set_log_timestamp_format(const char *format)
{
log_date_format = format;
log_timestamp_format = format;
}
3 changes: 2 additions & 1 deletion src/lib/message.h
Expand Up @@ -112,6 +112,7 @@ typedef struct s_dest {
char msg_types[NR_MSG_TYPES]; /* Message type mask */
char *where; /* Filename/program name */
char *mail_cmd; /* Mail command */
char *timestamp_format; /* Timestamp format to use in logging messages */
int syslog_facility; /* Syslog Facility */
POOLMEM *mail_filename; /* Unique mail filename */
} DEST;
Expand Down Expand Up @@ -165,7 +166,7 @@ void Jmsg(JCR *jcr, int type, utime_t mtime, const char *fmt,...);
void Qmsg(JCR *jcr, int type, utime_t mtime, const char *fmt,...);
bool get_trace(void);
const char *get_basename(const char *pathname);
void set_log_date_format(const char *format);
void set_log_timestamp_format(const char *format);

typedef bool (*db_log_insert_func)(JCR *jcr, utime_t mtime, char *msg);
extern DLL_IMP_EXP db_log_insert_func p_db_log_insert;
Expand Down
1 change: 1 addition & 0 deletions src/lib/msg_res.h
Expand Up @@ -38,6 +38,7 @@ static RES_ITEM msgs_items[] = {
{ "Description", CFG_TYPE_STR, ITEM(res_msgs.hdr.desc), 0, 0, NULL, NULL, NULL },
{ "MailCommand", CFG_TYPE_STR, ITEM(res_msgs.mail_cmd), 0, 0, NULL, NULL, NULL },
{ "OperatorCommand", CFG_TYPE_STR, ITEM(res_msgs.operator_cmd), 0, 0, NULL, NULL, NULL },
{ "TimestampFormat", CFG_TYPE_STR, ITEM(res_msgs.timestamp_format), 0, 0, NULL, NULL, NULL },
{ "Syslog", CFG_TYPE_MSGS, ITEM(res_msgs), MD_SYSLOG, 0, NULL, NULL, NULL },
{ "Mail", CFG_TYPE_MSGS, ITEM(res_msgs), MD_MAIL, 0, NULL, NULL, NULL },
{ "MailOnError", CFG_TYPE_MSGS, ITEM(res_msgs), MD_MAIL_ON_ERROR, 0, NULL, NULL, NULL },
Expand Down
1 change: 1 addition & 0 deletions src/lib/parse_conf.h
Expand Up @@ -280,6 +280,7 @@ class MSGSRES : public BRSRES {
public:
char *mail_cmd; /* Mail command */
char *operator_cmd; /* Operator command */
char *timestamp_format; /* Timestamp format */
DEST *dest_chain; /* chain of destinations */
char send_msg[nbytes_for_bits(M_MAX+1)]; /* Bit array of types */

Expand Down
3 changes: 2 additions & 1 deletion src/lib/protos.h
Expand Up @@ -268,7 +268,8 @@ void my_name_is(int argc, char *argv[], const char *name);
void init_msg(JCR *jcr, MSGSRES *msg, job_code_callback_t job_code_callback = NULL);
void term_msg(void);
void close_msg(JCR *jcr);
void add_msg_dest(MSGSRES *msg, int dest, int type, char *where, char *dest_code);
void add_msg_dest(MSGSRES *msg, int dest, int type,
char *where, char *mail_cmd, char *timestamp_format);
void rem_msg_dest(MSGSRES *msg, int dest, int type, char *where);
void Jmsg(JCR *jcr, int type, utime_t mtime, const char *fmt, ...);
void dispatch_message(JCR *jcr, int type, utime_t mtime, char *buf);
Expand Down

0 comments on commit 207398b

Please sign in to comment.