#ifndef LOG_ERROR_H
#define LOG_ERROR_H
-#define log_error(msg) log_error_do(msg,__FILE__,__LINE__)
+#include <errno.h>
+
+#define LOG_ARGS __FILE__, __LINE__, strerror(errno)
void log_set_name(const char *name);
-void log_error_do(const char *msg, const char *file, int line);
+void log_error(const char *file, int line, const char *errstr,
+ const char *fmt, ...);
#endif /* LOG_ERROR_H */
snprintf(tmpstr, len, "%s/listaddress", listdir);
if((listnamefile = fopen(tmpstr, "r")) == NULL) {
- log_error("Could not get listname:");
+ log_error(LOG_ARGS, "Could not open '%s'", tmpstr);
exit(EXIT_FAILURE);
}
fd = open(indexfilename, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR);
if(fd == -1) {
- log_error("Error opening index file");
+ log_error(LOG_ARGS, "Error opening index file");
exit(EXIT_FAILURE);
}
lock = myexcllock(fd);
if(lock) {
- log_error("Error locking index file");
+ log_error(LOG_ARGS, "Error locking index file");
close(fd);
exit(EXIT_FAILURE);
}
*sockfd = socket(PF_INET, SOCK_STREAM, 0);
if(*sockfd == -1) {
- log_error( "Could not get socket");
+ log_error(LOG_ARGS, "Could not get socket");
exit(EXIT_FAILURE);
}
addr.sin_family = PF_INET;
addr.sin_port = htons(25);
len = sizeof(addr);
if(connect(*sockfd, (struct sockaddr *)&addr, len) == -1) {
- log_error("Could not connect");
+ log_error(LOG_ARGS, "Could not connect");
exit(EXIT_FAILURE);
}
}
size_t len;
if((mailfile = fopen(mailfilename, "r")) == NULL) {
- log_error("listcontrol, could not open mail");
+ log_error(LOG_ARGS, "listcontrol, could not open mail");
exit(EXIT_FAILURE);
}
recipdelimsign = index(controladdr, RECIPDELIM);
"-L", listdir,
"-a", fromemails.emaillist[0],
"-C", 0);
- log_error("execlp() of mlmmj-sub failed");
+ log_error(LOG_ARGS, "execlp() of '%s' failed", mlmmjsub);
exit(EXIT_FAILURE);
} else /* Not a valid From: address, so we silently ignore */
exit(EXIT_SUCCESS);
"-L", listdir,
"-a", tmpstr,
"-c", 0);
- log_error("execlp() of mlmmj-sub failed");
+ log_error(LOG_ARGS, "execlp() of '%s' failed", mlmmjsub);
exit(EXIT_FAILURE);
} else {
/* Not proper confirm */
"-L", listdir,
"-a", fromemails.emaillist[0],
"-C", 0);
- log_error("execlp() of mlmmj-unsub failed");
+ log_error(LOG_ARGS, "execlp() of '%s' failed", mlmmjunsub);
exit(EXIT_FAILURE);
} else /* Not a valid From: address, so we silently ignore */
exit(EXIT_SUCCESS);
"-L", listdir,
"-a", tmpstr,
"-c", 0);
- log_error("execlp() of mlmmj-unsub failed");
+ log_error(LOG_ARGS, "execlp() of '%s' failed", mlmmjunsub);
exit(EXIT_FAILURE);
} else {
exit(EXIT_SUCCESS);
-#include <sys/types.h>
-#include <unistd.h>
#include <stdio.h>
#include <string.h>
-#include <errno.h>
#include <stdlib.h>
+#include <stdarg.h>
#include "log_error.h"
#include "../config.h"
log_name = strdup(name);
}
-void log_error_do(const char *msg, const char *file, int line)
+void log_error(const char *file, int line, const char *errstr,
+ const char *fmt, ...)
{
static int syslog_is_open = 0;
+ char buf[1024];
+ va_list ap;
+
+ va_start(ap, fmt);
+ vsnprintf(buf, sizeof(buf), fmt, ap);
+ va_end(ap);
+
if (!log_name) log_name = "mlmmj-UNKNOWN";
+
#ifdef HAVE_SYSLOG
if(!syslog_is_open) {
openlog(log_name, LOG_PID|LOG_CONS, LOG_MAIL);
syslog_is_open = 1;
}
- syslog(LOG_ERR, "%s:%d: %s: %s", file, line, msg, strerror(errno));
+ syslog(LOG_ERR, "%s:%d: %s: %s", file, line, buf, errstr);
#else
fprintf(stderr, "%s[%d]: %s:%d: %s: %s\n", log_name, (int)getpid(),
- file, line,
- msg, strerror(errno));
+ file, line, buf, errstr);
#endif
}
#endif
bytes_written = writen(sockfd, helo, len);
if(bytes_written < 0) {
- log_error("Could not write HELO");
+ log_error(LOG_ARGS, "Could not write HELO");
free(helo);
return errno;
}
#endif
bytes_written = writen(sockfd, mail_from, len);
if(bytes_written < 0) {
- log_error("Could not write FROM");
+ log_error(LOG_ARGS, "Could not write FROM");
free(mail_from);
return errno;
}
#endif
bytes_written = writen(sockfd, rcpt_to, len);
if(bytes_written < 0) {
- log_error( "Could not write TO" );
+ log_error(LOG_ARGS, "Could not write TO");
free(rcpt_to);
return errno;
}
/* Read from beginning of the file */
if(fseek(infile, 0L, SEEK_SET) == -1) {
- log_error("write_crlf,fseek");
+ log_error(LOG_ARGS, "fseek() failed");
return errno;
}
#endif
bytes_written = writen(sockfd, customline, len);
if(bytes_written < 0) {
- log_error( "Could not write customline" );
+ log_error(LOG_ARGS, "Could not write customline");
free(customline);
return errno;
}
#endif
bytes_written = writen(sockfd, replyto, len);
if(bytes_written < 0) {
- log_error( "Could not write Reply-To:" );
+ log_error(LOG_ARGS, "Could not write Reply-To header");
free(replyto);
return errno;
}
int write_data(int sockfd)
{
if(write_custom_line(sockfd, "DATA")) {
- log_error("mail-functions.c:write_data");
+ log_error(LOG_ARGS, "Could not write DATA");
return errno;
}
int write_quit(int sockfd)
{
if(write_custom_line(sockfd, "QUIT")) {
- log_error("mail-functions.c:write_quit");
+ log_error(LOG_ARGS, "Could not write QUIT");
return errno;
}
int write_rset(int sockfd)
{
if(write_custom_line(sockfd, "RSET")) {
- log_error("mail-functions.c:write_rset");
+ log_error(LOG_ARGS, "Could not write RSET");
return errno;
}
if(fd == -1) {
free(donemailname);
- log_error("could not create mail file in queue directory");
+ log_error(LOG_ARGS, "could not create mail file in queue directory");
exit(EXIT_FAILURE);
}
if((donemailfile = fdopen(fd, "w")) == NULL) {
free(donemailname);
- log_error("could not fdopen() output mail file");
+ log_error(LOG_ARGS, "could not fdopen() output mail file");
exit(EXIT_FAILURE);
}
if((rawmailfile = fopen(mailfile, "r")) == NULL) {
free(donemailname);
- log_error("could not fopen() input mail file");
+ log_error(LOG_ARGS, "could not fopen() input mail file");
exit(EXIT_FAILURE);
}
execlp(mlmmjsend, mlmmjsend,
"-L", listdir,
"-m", donemailname, 0);
- log_error("execlp() of mlmmj-send failed");
+ log_error(LOG_ARGS, "execlp() of '%s' failed", mlmmjsend);
return EXIT_FAILURE;
}
}
if(fd < 0) {
- log_error("could not create mail file in incoming directory");
+ log_error(LOG_ARGS, "could not create mail file in incoming directory");
free(infilename);
exit(EXIT_FAILURE);
}
execlp(mlmmjprocess, mlmmjprocess,
"-L", listdir,
"-m", infilename, 0);
- log_error("execlp() of mlmmj-process failed");
+ log_error(LOG_ARGS, "execlp() of '%s' failed", mlmmjprocess);
return EXIT_FAILURE;
}
int retval;
if((retval = write_mail_from(sockfd, from)) != 0) {
- log_error("Could not write MAIL FROM\n");
+ log_error(LOG_ARGS, "Could not write MAIL FROM\n");
/* FIXME: Queue etc.*/
write_rset(sockfd);
return retval;
}
if((retval = checkwait_smtpreply(sockfd, MLMMJ_FROM)) != 0) {
- log_error("Wrong MAIL FROM:\n");
+ log_error(LOG_ARGS, "Wrong MAIL FROM:\n");
write_rset(sockfd);
/* FIXME: Queue etc.*/
return retval;
}
if((retval = write_rcpt_to(sockfd, to)) != 0) {
- log_error("Could not write RCPT TO:\n");
+ log_error(LOG_ARGS, "Could not write RCPT TO:\n");
/* FIXME: Queue etc.*/
write_rset(sockfd);
return retval;
}
if((retval = checkwait_smtpreply(sockfd, MLMMJ_RCPTTO)) != 0) {
- log_error("Wrong RCPT TO:\n");
+ log_error(LOG_ARGS, "Wrong RCPT TO:\n");
write_rset(sockfd);
/* FIXME: Queue etc.*/
return retval;
}
if((retval = write_data(sockfd)) != 0) {
- log_error("Could not write DATA\b");
+ log_error(LOG_ARGS, "Could not write DATA\b");
write_rset(sockfd);
/* FIXME: Queue etc.*/
return retval;
}
if((checkwait_smtpreply(sockfd, MLMMJ_DATA)) != 0) {
- log_error("Mailserver not ready for DATA\n");
+ log_error(LOG_ARGS, "Mailserver not ready for DATA\n");
write_rset(sockfd);
/* FIXME: Queue etc.*/
return retval;
}
if(replyto)
if((retval = write_replyto(sockfd, replyto)) != 0) {
- log_error("Could not write reply-to addr.\n");
+ log_error(LOG_ARGS, "Could not write reply-to addr.\n");
write_rset(sockfd);
/* FIXME: Queue etc.*/
return retval;
}
if((retval = write_mailbody_from_file(sockfd, mailfile)) != 0) {
- log_error("Could not write mailbody\n");
+ log_error(LOG_ARGS, "Could not write mailbody\n");
write_rset(sockfd);
/* FIXME: Queue etc.*/
return retval;
}
if((retval = write_dot(sockfd)) != 0) {
- log_error("Could not write <CR><LF>.<CR><LF>\n");
+ log_error(LOG_ARGS, "Could not write <CR><LF>.<CR><LF>\n");
write_rset(sockfd);
/* FIXME: Queue etc.*/
return retval;
}
if((checkwait_smtpreply(sockfd, MLMMJ_DOT)) != 0) {
- log_error("Mailserver did not acknowledge end of mail\n"
+ log_error(LOG_ARGS, "Mailserver did not acknowledge end of mail\n"
"<CR><LF>.<CR><LF> was written, to no"
"avail\n");
write_rset(sockfd);
/* initialize file with mail to send */
if((mailfile = fopen(mailfilename, "r")) == NULL) {
- log_error(mailfilename);
+ log_error(LOG_ARGS, "Could not open '%s'", mailfilename);
exit(EXIT_FAILURE);
}
if(listdir[0] != '1') {
subfilename = concatstr(2, listdir, "/subscribers");
if((subfile = fopen(subfilename, "r")) == NULL) {
- log_error("Could not open subscriberfile:");
+ log_error(LOG_ARGS, "Could not open subscriberfile:");
exit(EXIT_FAILURE);
}
}
}
if((retval = checkwait_smtpreply(sockfd, MLMMJ_CONNECT)) != 0) {
- log_error("No proper greeting to our connect\n"
+ log_error(LOG_ARGS, "No proper greeting to our connect\n"
"We continue and hope for the best\n");
/* FIXME: Queue etc. */
}
write_helo(sockfd, "localhost");
if((checkwait_smtpreply(sockfd, MLMMJ_HELO)) != 0) {
- log_error("Error with HELO\n"
+ log_error(LOG_ARGS, "Error with HELO\n"
"We continue and hope for the best\n");
/* FIXME: quit and tell admin to configure correctly */
}
write_quit(sockfd);
if((checkwait_smtpreply(sockfd, MLMMJ_QUIT)) != 0) {
- log_error("Mailserver would not let us QUIT\n"
+ log_error(LOG_ARGS, "Mailserver would not let us QUIT\n"
"We close the socket anyway though\n");
}
subtextfilename = concatstr(2, listdir, "/text/sub-ok");
if((subtextfile = fopen(subtextfilename, "r")) == NULL) {
- log_error("Could not open text/sub-confirm\n");
+ log_error(LOG_ARGS, "Could not open '%s'", subtextfilename);
free(subtextfilename);
exit(EXIT_FAILURE);
}
printf("%s\n", queuefilename);
if((queuefile = fopen(queuefilename, "w")) == NULL) {
- log_error(queuefilename);
+ log_error(LOG_ARGS, "Could not open '%s'", queuefilename);
free(queuefilename);
free(randomstr);
exit(EXIT_FAILURE);
"-T", subaddr,
"-F", fromaddr,
"-m", queuefilename, 0);
- log_error("execlp() of mlmmj-send failed");
+ log_error(LOG_ARGS, "execlp() of '%s' failed", mlmmjsend);
exit(EXIT_FAILURE);
}
confirmfilename = concatstr(3, listdir, "/subconf/", randomstr);
if((subconffile = fopen(confirmfilename, "w")) == NULL) {
- log_error(confirmfilename);
+ log_error(LOG_ARGS, "Could not open '%s'", confirmfilename);
free(confirmfilename);
free(randomstr);
exit(EXIT_FAILURE);
subtextfilename = concatstr(2, listdir, "/text/sub-confirm");
if((subtextfile = fopen(subtextfilename, "r")) == NULL) {
- log_error("Could not open text/sub-confirm\n");
+ log_error(LOG_ARGS, "Could not open '%s'", subtextfilename);
free(randomstr);
free(subtextfilename);
exit(EXIT_FAILURE);
printf("%s\n", queuefilename);
if((queuefile = fopen(queuefilename, "w")) == NULL) {
- log_error(queuefilename);
+ log_error(LOG_ARGS, "Could not open '%s'", queuefilename);
free(queuefilename);
free(randomstr);
exit(EXIT_FAILURE);
"-F", fromaddr,
"-R", confirmaddr,
"-m", queuefilename, 0);
- log_error("execlp() of mlmmj-send failed");
+ log_error(LOG_ARGS, "execlp() of '%s' failed", mlmmjsend);
exit(EXIT_FAILURE);
}
subfilefd = open(subfilename, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR);
if(subfilefd == -1) {
- log_error("Could not open subscriberfile:");
+ log_error(LOG_ARGS, "Could not open '%s'", subfilename);
exit(EXIT_FAILURE);
}
lock = myexcllock(subfilefd);
if(lock) {
- log_error("Error locking subscriber file:");
+ log_error(LOG_ARGS, "Error locking subscriber file");
close(subfilefd);
exit(EXIT_FAILURE);
}
subtextfilename = concatstr(2, listdir, "/text/unsub-ok");
if((subtextfile = fopen(subtextfilename, "r")) == NULL) {
- log_error("Could not open text/unsub-ok\n");
+ log_error(LOG_ARGS, "Could not open '%s'", subtextfilename);
free(subtextfilename);
exit(EXIT_FAILURE);
}
printf("%s\n", queuefilename);
if((queuefile = fopen(queuefilename, "w")) == NULL) {
- log_error(queuefilename);
+ log_error(LOG_ARGS, "Could not open '%s'", queuefilename);
free(queuefilename);
free(randomstr);
exit(EXIT_FAILURE);
"-T", subaddr,
"-F", fromaddr,
"-m", queuefilename, 0);
- log_error("execlp() of mlmmjsend failed");
+ log_error(LOG_ARGS, "execlp() of '%s' failed", mlmmjsend);
exit(EXIT_FAILURE);
}
confirmfilename = concatstr(3, listdir, "/unsubconf/", randomstr);
if((subconffile = fopen(confirmfilename, "w")) == NULL) {
- log_error(confirmfilename);
+ log_error(LOG_ARGS, "Could not open '%s'", confirmfilename);
free(confirmfilename);
free(randomstr);
exit(EXIT_FAILURE);
subtextfilename = concatstr(2, listdir, "/text/unsub-confirm");
if((subtextfile = fopen(subtextfilename, "r")) == NULL) {
- log_error("Could not open text/unsub-confirm\n");
+ log_error(LOG_ARGS, "Could not open '%s'", subtextfilename);
free(randomstr);
free(subtextfilename);
exit(EXIT_FAILURE);
printf("%s\n", queuefilename);
if((queuefile = fopen(queuefilename, "w")) == NULL) {
- log_error(queuefilename);
+ log_error(LOG_ARGS, "Could not open '%s'", queuefilename);
free(queuefilename);
free(randomstr);
exit(EXIT_FAILURE);
"-F", fromaddr,
"-R", confirmaddr,
"-m", queuefilename, 0);
- log_error("execlp() of mlmmj-send failed");
+ log_error(LOG_ARGS, "execlp() of '%s' failed", mlmmjsend);
exit(EXIT_FAILURE);
}
subread = open(subreadname, O_RDWR);
if(subread == -1) {
- log_error("Could not open subscriberfile:");
+ log_error(LOG_ARGS, "Could not open '%s'", subreadname);
exit(EXIT_FAILURE);
}
sublock = myexcllock(subread);
if(sublock) {
- log_error("Error locking subscriber file:");
+ log_error(LOG_ARGS, "Error locking subscriber file");
close(subread);
exit(EXIT_FAILURE);
}
subwrite = open(subreadname, O_RDWR);
if(subwrite == -1){
- log_error("Could not open subfile:");
+ log_error(LOG_ARGS, "Could not open '%s'", subreadname);
exit(EXIT_FAILURE);
}
if(unsubconfirm)
helpfilename = concatstr(2, listdir, "/text/listhelp");
if((helpfile = fopen(helpfilename, "r")) == NULL) {
- log_error("Could not open text/help\n");
+ log_error(LOG_ARGS, "Could not open text/help");
free(helpfilename);
exit(EXIT_FAILURE);
}
printf("%s\n", queuefilename);
if((queuefile = fopen(queuefilename, "w")) == NULL) {
- log_error(queuefilename);
+ log_error(LOG_ARGS, "Could not open '%s'", queuefilename);
free(queuefilename);
free(randomstr);
exit(EXIT_FAILURE);
"-T", emailaddr,
"-F", fromaddr,
"-m", queuefilename, 0);
- log_error("execlp() of mlmmjsend failed");
+ log_error(LOG_ARGS, "execlp() of '%s' failed", mlmmjsend);
exit(EXIT_FAILURE);
}