# HG changeset patch # User mortenp # Date 1082739093 -36000 # Node ID 3509e8837988fe5dfce3ab2e8b8958530d1f39e5 # Parent 7f4c75a4a34643b627b4b72d8ea647a59f9d3de8 changed log_error() to be a function (no C99 here) diff -r 7f4c75a4a346 -r 3509e8837988 include/log_error.h --- a/include/log_error.h Sat Apr 24 00:15:52 2004 +1000 +++ b/include/log_error.h Sat Apr 24 02:51:33 2004 +1000 @@ -9,9 +9,12 @@ #ifndef LOG_ERROR_H #define LOG_ERROR_H -#define log_error(msg) log_error_do(msg,__FILE__,__LINE__) +#include + +#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 */ diff -r 7f4c75a4a346 -r 3509e8837988 src/getlistaddr.c --- a/src/getlistaddr.c Sat Apr 24 00:15:52 2004 +1000 +++ b/src/getlistaddr.c Sat Apr 24 02:51:33 2004 +1000 @@ -27,7 +27,7 @@ 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); } diff -r 7f4c75a4a346 -r 3509e8837988 src/incindexfile.c --- a/src/incindexfile.c Sat Apr 24 00:15:52 2004 +1000 +++ b/src/incindexfile.c Sat Apr 24 02:51:33 2004 +1000 @@ -40,14 +40,14 @@ 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); } diff -r 7f4c75a4a346 -r 3509e8837988 src/init_sockfd.c --- a/src/init_sockfd.c Sat Apr 24 00:15:52 2004 +1000 +++ b/src/init_sockfd.c Sat Apr 24 02:51:33 2004 +1000 @@ -21,7 +21,7 @@ *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; @@ -29,7 +29,7 @@ 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); } } diff -r 7f4c75a4a346 -r 3509e8837988 src/listcontrol.c --- a/src/listcontrol.c Sat Apr 24 00:15:52 2004 +1000 +++ b/src/listcontrol.c Sat Apr 24 02:51:33 2004 +1000 @@ -32,7 +32,7 @@ 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); @@ -57,7 +57,7 @@ "-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); @@ -77,7 +77,7 @@ "-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 */ @@ -92,7 +92,7 @@ "-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); @@ -112,7 +112,7 @@ "-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); diff -r 7f4c75a4a346 -r 3509e8837988 src/log_error.c --- a/src/log_error.c Sat Apr 24 00:15:52 2004 +1000 +++ b/src/log_error.c Sat Apr 24 02:51:33 2004 +1000 @@ -1,9 +1,7 @@ -#include -#include #include #include -#include #include +#include #include "log_error.h" #include "../config.h" @@ -20,19 +18,27 @@ 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 } diff -r 7f4c75a4a346 -r 3509e8837988 src/mail-functions.c --- a/src/mail-functions.c Sat Apr 24 00:15:52 2004 +1000 +++ b/src/mail-functions.c Sat Apr 24 02:51:33 2004 +1000 @@ -39,7 +39,7 @@ #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; } @@ -64,7 +64,7 @@ #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; } @@ -92,7 +92,7 @@ #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; } @@ -113,7 +113,7 @@ /* 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; } @@ -168,7 +168,7 @@ #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; } @@ -196,7 +196,7 @@ #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; } @@ -207,7 +207,7 @@ 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; } @@ -217,7 +217,7 @@ 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; } @@ -227,7 +227,7 @@ 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; } diff -r 7f4c75a4a346 -r 3509e8837988 src/mlmmj-process.c --- a/src/mlmmj-process.c Sat Apr 24 00:15:52 2004 +1000 +++ b/src/mlmmj-process.c Sat Apr 24 02:51:33 2004 +1000 @@ -97,13 +97,13 @@ 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); } @@ -111,7 +111,7 @@ 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); } @@ -169,7 +169,7 @@ 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; } diff -r 7f4c75a4a346 -r 3509e8837988 src/mlmmj-recieve.c --- a/src/mlmmj-recieve.c Sat Apr 24 00:15:52 2004 +1000 +++ b/src/mlmmj-recieve.c Sat Apr 24 02:51:33 2004 +1000 @@ -74,7 +74,7 @@ } 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); } @@ -97,7 +97,7 @@ 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; } diff -r 7f4c75a4a346 -r 3509e8837988 src/mlmmj-send.c --- a/src/mlmmj-send.c Sat Apr 24 00:15:52 2004 +1000 +++ b/src/mlmmj-send.c Sat Apr 24 02:51:33 2004 +1000 @@ -85,65 +85,65 @@ 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 .\n"); + log_error(LOG_ARGS, "Could not write .\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" ". was written, to no" "avail\n"); write_rset(sockfd); @@ -221,7 +221,7 @@ /* 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); } @@ -238,7 +238,7 @@ 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); } } @@ -252,13 +252,13 @@ } 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 */ } @@ -277,7 +277,7 @@ 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"); } diff -r 7f4c75a4a346 -r 3509e8837988 src/mlmmj-sub.c --- a/src/mlmmj-sub.c Sat Apr 24 00:15:52 2004 +1000 +++ b/src/mlmmj-sub.c Sat Apr 24 02:51:33 2004 +1000 @@ -40,7 +40,7 @@ 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); } @@ -55,7 +55,7 @@ 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); @@ -104,7 +104,7 @@ "-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); } @@ -124,7 +124,7 @@ 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); @@ -151,7 +151,7 @@ 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); @@ -163,7 +163,7 @@ 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); @@ -208,7 +208,7 @@ "-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); } @@ -282,13 +282,13 @@ 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); } diff -r 7f4c75a4a346 -r 3509e8837988 src/mlmmj-unsub.c --- a/src/mlmmj-unsub.c Sat Apr 24 00:15:52 2004 +1000 +++ b/src/mlmmj-unsub.c Sat Apr 24 02:51:33 2004 +1000 @@ -41,7 +41,7 @@ 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); } @@ -56,7 +56,7 @@ 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); @@ -105,7 +105,7 @@ "-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); } @@ -125,7 +125,7 @@ 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); @@ -152,7 +152,7 @@ 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); @@ -164,7 +164,7 @@ 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); @@ -209,7 +209,7 @@ "-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); } @@ -293,13 +293,13 @@ 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); } @@ -313,7 +313,7 @@ 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) diff -r 7f4c75a4a346 -r 3509e8837988 src/send_help.c --- a/src/send_help.c Sat Apr 24 00:15:52 2004 +1000 +++ b/src/send_help.c Sat Apr 24 02:51:33 2004 +1000 @@ -34,7 +34,7 @@ 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); } @@ -49,7 +49,7 @@ 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); @@ -106,6 +106,6 @@ "-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); }