/*
* Create a unique filename for the mail command
*/
-static void make_unique_mail_filename(JCR *jcr, POOLMEM **name, DEST *d)
+static void make_unique_mail_filename(JCR *jcr, POOLMEM *&name, DEST *d)
{
if (jcr) {
Mmsg(name, "%s/%s.mail.%s.%d", working_directory, my_name,
/*
* Open a mail pipe
*/
-static BPIPE *open_mail_pipe(JCR *jcr, POOLMEM **cmd, DEST *d)
+static BPIPE *open_mail_pipe(JCR *jcr, POOLMEM *&cmd, DEST *d)
{
BPIPE *bpipe;
int use_bsmtp = (d->mail_cmd && jcr);
if (use_bsmtp) {
- *cmd = edit_job_codes(jcr, *cmd, d->mail_cmd, d->where);
+ cmd = edit_job_codes(jcr, cmd, d->mail_cmd, d->where);
} else {
#if 1
Mmsg(cmd, "/usr/lib/sendmail -F Bacula %s", d->where);
}
fflush(stdout);
- if (!(bpipe = open_bpipe(*cmd, 120, "rw"))) {
+ if (!(bpipe = open_bpipe(cmd, 120, "rw"))) {
+ berrno be;
Jmsg(jcr, M_ERROR, 0, "open mail pipe %s failed: ERR=%s\n",
- *cmd, strerror(errno));
+ cmd, be.strerror());
}
#if 1
goto rem_temp_file;
}
- if (!(bpipe=open_mail_pipe(jcr, &cmd, d))) {
+ if (!(bpipe=open_mail_pipe(jcr, cmd, d))) {
Pmsg0(000, "open mail pipe failed.\n");
goto rem_temp_file;
}
stat = close_bpipe(bpipe);
if (stat != 0 && msgs != daemon_msgs) {
+ berrno be;
+ be.set_errno(stat);
Dmsg1(150, "Calling emsg. CMD=%s\n", cmd);
- Jmsg3(jcr, M_ERROR, 0, _("Mail program terminated in error. stat=%d\n"
+ Jmsg2(jcr, M_ERROR, 0, _("Mail program terminated in error.\n"
"CMD=%s\n"
- "ERR=%s\n"), stat, cmd, strerror(stat));
+ "ERR=%s\n"), cmd, be.strerror());
}
free_memory(line);
rem_temp_file:
case MD_OPERATOR:
Dmsg1(800, "OPERATOR for collowing msg: %s\n", msg);
mcmd = get_pool_memory(PM_MESSAGE);
- if ((bpipe=open_mail_pipe(jcr, &mcmd, d))) {
+ if ((bpipe=open_mail_pipe(jcr, mcmd, d))) {
int stat;
fputs(msg, bpipe->wfd);
/* Messages to the operator go one at a time */
stat = close_bpipe(bpipe);
if (stat != 0) {
+ berrno be;
+ be.set_errno(stat);
Jmsg2(jcr, M_ERROR, 0, _("Operator mail program terminated in error.\n"
"CMD=%s\n"
- "ERR=%s\n"), mcmd, strerror(stat));
+ "ERR=%s\n"), mcmd, be.strerror());
}
}
free_pool_memory(mcmd);
Dmsg1(800, "MAIL for following msg: %s", msg);
if (!d->fd) {
POOLMEM *name = get_pool_memory(PM_MESSAGE);
- make_unique_mail_filename(jcr, &mp_chr(name), d);
+ make_unique_mail_filename(jcr, name, d);
d->fd = fopen(mp_chr(name), "w+");
if (!d->fd) {
d->fd = stdout;
POOLMEM *pool_buf;
pool_buf = get_pool_memory(PM_EMSG);
- i = Mmsg(&pool_buf, "%s:%d ", file, line);
+ i = Mmsg(pool_buf, "%s:%d ", file, line);
for (;;) {
maxlen = sizeof_pool_memory(pool_buf) - i - 1;
return len;
}
+int m_msg(const char *file, int line, POOLMEM *&pool_buf, const char *fmt, ...)
+{
+ va_list arg_ptr;
+ int i, len, maxlen;
+
+ i = sprintf(pool_buf, "%s:%d ", file, line);
+
+ for (;;) {
+ maxlen = sizeof_pool_memory(pool_buf) - i - 1;
+ va_start(arg_ptr, fmt);
+ len = bvsnprintf(pool_buf+i, maxlen, fmt, arg_ptr);
+ va_end(arg_ptr);
+ if (len < 0 || len >= (maxlen-5)) {
+ pool_buf = realloc_pool_memory(pool_buf, maxlen + i + maxlen/2);
+ continue;
+ }
+ break;
+ }
+ return len;
+}
+
+
/*
* Edit a message into a Pool Memory buffer NO file:lineno
* Returns: string length of what was edited.
return len;
}
+int Mmsg(POOLMEM *&pool_buf, const char *fmt, ...)
+{
+ va_list arg_ptr;
+ int len, maxlen;
+
+ for (;;) {
+ maxlen = sizeof_pool_memory(pool_buf) - 1;
+ va_start(arg_ptr, fmt);
+ len = bvsnprintf(pool_buf, maxlen, fmt, arg_ptr);
+ va_end(arg_ptr);
+ if (len < 0 || len >= (maxlen-5)) {
+ pool_buf = realloc_pool_memory(pool_buf, maxlen + maxlen/2);
+ continue;
+ }
+ break;
+ }
+ return len;
+}
+
+
static pthread_mutex_t msg_queue_mutex = PTHREAD_MUTEX_INITIALIZER;
/*
POOLMEM *pool_buf;
pool_buf = get_pool_memory(PM_EMSG);
- i = Mmsg(&pool_buf, "%s:%d ", file, line);
+ i = Mmsg(pool_buf, "%s:%d ", file, line);
for (;;) {
maxlen = sizeof_pool_memory(pool_buf) - i - 1;