FILE *con_fd = NULL; /* Console file descriptor */
brwlock_t con_lock; /* Console lock structure */
-static char *catalog_db = NULL; /* database type */
+static char *catalog_db = NULL; /* database type */
const char *host_os = HOST_OS;
const char *distname = DISTNAME;
init_msg(JCR *jcr, MSGS *msg)
{
DEST *d, *dnew, *temp_chain = NULL;
+ int i;
if (jcr == NULL && msg == NULL) {
init_last_jobs_list();
*
*/
int fd;
- int i;
fd = open("/dev/null", O_RDONLY, 0644);
if (fd > 2) {
close(fd);
if (msg == NULL) {
daemon_msgs = (MSGS *)malloc(sizeof(MSGS));
memset(daemon_msgs, 0, sizeof(MSGS));
-#if !defined(HAVE_WIN32)
for (i=1; i<=M_MAX; i++) {
add_msg_dest(daemon_msgs, MD_STDOUT, i, NULL, NULL);
}
-#endif
Dmsg1(050, "Create daemon global message resource %p\n", daemon_msgs);
return;
}
term_last_jobs_list();
}
-
+static bool open_dest_file(JCR *jcr, DEST *d, const char *mode)
+{
+ d->fd = fopen(d->where, mode);
+ if (!d->fd) {
+ berrno be;
+ d->fd = stdout;
+ Qmsg2(jcr, M_ERROR, 0, _("fopen %s failed: ERR=%s\n"), d->where,
+ be.strerror());
+ d->fd = NULL;
+ return false;
+ }
+ return true;
+}
/*
* Handle sending the message to the appropriate place
int len, dtlen;
MSGS *msgs;
BPIPE *bpipe;
+ char *mode;
Dmsg2(850, "Enter dispatch_msg type=%d msg=%s", type, msg);
}
if (type == M_ABORT || type == M_ERROR_TERM) {
-#if !defined(HAVE_WIN32)
fputs(dt, stdout);
fputs(msg, stdout); /* print this here to INSURE that it is printed */
fflush(stdout);
-#endif
}
/* Now figure out where to send the message */
}
fputs(msg, d->fd);
break;
+ case MD_APPEND:
+ Dmsg1(850, "APPEND for following msg: %s", msg);
+ mode = "ab";
+ goto send_to_file;
case MD_FILE:
Dmsg1(850, "FILE for following msg: %s", msg);
- if (!d->fd) {
- d->fd = fopen(d->where, "w+b");
- if (!d->fd) {
- berrno be;
- d->fd = stdout;
- Qmsg2(jcr, M_ERROR, 0, _("fopen %s failed: ERR=%s\n"), d->where,
- be.strerror());
- d->fd = NULL;
- break;
- }
+ mode = "w+b";
+send_to_file:
+ if (!d->fd && !open_dest_file(jcr, d, mode)) {
+ break;
}
fputs(dt, d->fd);
fputs(msg, d->fd);
- break;
- case MD_APPEND:
- Dmsg1(850, "APPEND for following msg: %s", msg);
- if (!d->fd) {
- d->fd = fopen(d->where, "ab");
- if (!d->fd) {
- berrno be;
- d->fd = stdout;
- Qmsg2(jcr, M_ERROR, 0, _("fopen %s failed: ERR=%s\n"), d->where,
- be.strerror());
- d->fd = NULL;
- break;
+ /* On error, we close and reopen to handle log rotation */
+ if (ferror(d->fd)) {
+ fclose(d->fd);
+ if (open_dest_file(jcr, d, mode)) {
+ fputs(dt, d->fd);
+ fputs(msg, d->fd);
}
}
- fputs(dt, d->fd);
- fputs(msg, d->fd);
break;
case MD_DIRECTOR:
Dmsg1(850, "DIRECTOR for following msg: %s", msg);
if (trace) {
if (!trace_fd) {
char fn[200];
- bsnprintf(fn, sizeof(fn), "%s/bacula.trace", working_directory ? working_directory : ".");
+ bsnprintf(fn, sizeof(fn), "%s/%s.trace", working_directory ? working_directory : ".", my_name);
trace_fd = fopen(fn, "a+b");
}
if (trace_fd) {
if (level <= debug_level) {
if (!trace_fd) {
- bsnprintf(buf, sizeof(buf), "%s/bacula.trace", working_directory);
+ bsnprintf(buf, sizeof(buf), "%s/%s.trace", working_directory ? working_directory : ".", my_name);
trace_fd = fopen(buf, "a+b");
}
if (type == M_ABORT){
char *p = 0;
+ printf("Bacula forced SEG FAULT to obtain traceback.\n");
+ syslog(LOG_DAEMON|LOG_ERR, "Bacula forced SEG FAULT to obtain traceback.\n");
p[0] = 0; /* generate segmentation violation */
}
if (type == M_ERROR_TERM) {