]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
cleanup: replace most writen with dprintf
authorBaptiste Daroussin <bapt@FreeBSD.org>
Tue, 2 Nov 2021 10:57:52 +0000 (11:57 +0100)
committerBaptiste Daroussin <bapt@FreeBSD.org>
Tue, 2 Nov 2021 11:04:20 +0000 (12:04 +0100)
15 files changed:
include/mlmmj-maintd.h
src/do_all_the_voodoo_here.c
src/incindexfile.c
src/log_oper.c
src/mail-functions.c
src/mlmmj-bounce.c
src/mlmmj-maintd.c
src/mlmmj-process.c
src/mlmmj-receive.c
src/mlmmj-send.c
src/mlmmj-sub.c
src/mlmmj-unsub.c
src/prepstdreply.c
src/send_digest.c
src/send_list.c

index 5ec79bd432265d0783937fa5da95e553d2086112..562222b15038a543a3d8b535d697ff0ed2ef53b4 100644 (file)
@@ -42,16 +42,6 @@ int run_digests(struct mlmmj_list *list, const char *mlmmjsend);
  * C99 -- Jun 09 2004, mmj
  */
 
-#define WRITEMAINTLOG4( s1, s2, s3, s4 ) do { \
-               logstr = concatstr( s1, s2, s3, s4 ) ;\
-               writen(maintdlogfd, logstr, strlen(logstr)); \
-               myfree(logstr); \
-               } while (0);
-
-#define WRITEMAINTLOG6( s1, s2, s3, s4, s5, s6 ) do { \
-               logstr = concatstr( s1, s2, s3, s4, s5, s6 ) ;\
-               writen(maintdlogfd, logstr, strlen(logstr)); \
-               myfree(logstr); \
-               } while (0);
+#define WRITEMAINTLOG(fmt, ...) dprintf(maintdlogfd, fmt, __VA_ARGS__)
 
 #endif /* MLMMJ_MAINTD_H */
index ff6520e96b4c3af0de84ef865a9d2a047857a7fe..d7ea18429851a2bcaec05e68c5ec6f77f3364b10 100644 (file)
@@ -21,6 +21,7 @@
  * IN THE SOFTWARE.
  */
 
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
@@ -74,7 +75,7 @@ int do_all_the_voodoo_here(int infd, int outfd, int hdrfd, int footfd,
                 const struct strlist *delhdrs, struct mailhdr *readhdrs,
                 struct strlist *allhdrs, const char *prefix)
 {
-       char *hdrline, *unfolded, *subject, *unqp;
+       char *hdrline, *unfolded, *unqp;
        int hdrsadded = 0;
        int subject_present = 0;
 
@@ -107,13 +108,11 @@ int do_all_the_voodoo_here(int infd, int outfd, int hdrfd, int footfd,
                        /* add Subject if none is present
                           and a prefix is defined */
                        if (prefix && !subject_present) {
-                               subject = concatstr(3,"Subject: ",prefix,"\n");
-                               writen(outfd, subject, strlen(subject));
-                               myfree(subject);
+                               dprintf(outfd, "Subject: %s\n", prefix);
                                subject_present = 1;
                        }
                        /* write LF */
-                       if(writen(outfd, "\n", 1) < 0) {
+                       if(dprintf(outfd, "\n") < 0) {
                                myfree(hdrline);
                                myfree(unfolded);
                                log_error(LOG_ARGS, "Error writing hdrs.");
@@ -141,12 +140,8 @@ int do_all_the_voodoo_here(int infd, int outfd, int hdrfd, int footfd,
                                unqp = cleanquotedp(hdrline + 8);
                                if(strstr(hdrline + 8, prefix) == NULL &&
                                   strstr(unqp, prefix) == NULL) {
-                                       subject = concatstr(4,
-                                                       "Subject: ", prefix,
-                                                       hdrline + 8, "\n");
-                                       writen(outfd, subject,
-                                                       strlen(subject));
-                                       myfree(subject);
+                                       dprintf(outfd, "Subject: %s%s\n",
+                                           prefix, hdrline + 8);
                                        myfree(hdrline);
                                        myfree(unqp);
                                        continue;
@@ -157,7 +152,7 @@ int do_all_the_voodoo_here(int infd, int outfd, int hdrfd, int footfd,
 
                /* Should it be stripped? */
                if(!delhdrs || !findit(hdrline, delhdrs))
-                       writen(outfd, unfolded, strlen(unfolded));
+                       dprintf(outfd, "%s", unfolded);
 
                myfree(hdrline);
                myfree(unfolded);
index 40a76da97bc4ddb62127503e139b0f4ec0290675..b439460cfe7f11836327f4d1af01e46353fd12b8 100644 (file)
@@ -77,7 +77,7 @@ int incindexfile(const char *listdir)
        index++;
        itoa(index, intbuf);
        lseek(fd, 0, SEEK_SET);
-       writen(fd, intbuf, strlen(intbuf));
+       dprintf(fd, "%s", intbuf);
 
        close(fd); /* Lock is also released */
        myfree(indexfilename);
index ca3d32418b889ba6690e040923bfcf374367b6c9..359d969d7868722a6e3bcb2355b691babfb4e36c 100644 (file)
@@ -97,7 +97,7 @@ int log_oper(const char *prefix, const char *basename, const char *fmt, ...)
        va_end(ap);
 
        logstr = concatstr(4, ct, " ", log_msg, "\n");
-       if(writen(fd, logstr, strlen(logstr)) < 0)
+       if(dprintf(fd, "%s", logstr) < 0)
                log_error(LOG_ARGS, "Could not write to %s", logfilename);
        
        close(fd);
index 9ff128c79453bb466d1cf9484512aec42654eced..2facc1dea606bdec3cdb5589149ef7facf0d6bae 100644 (file)
 #include "log_error.h"
 #include "memory.h"
 
-/* "EHLO \r\n" has length 7 */
-#define EXTRA_EHLO_LEN 7
 int write_ehlo(int sockfd, const char *hostname)
 {
-       size_t len = (size_t)(strlen(hostname) + EXTRA_EHLO_LEN + 1);
-       char *ehlo;
        size_t bytes_written;
-       
-       if((ehlo = mymalloc(len)) == 0)
-               return errno;
-       snprintf(ehlo, len, "EHLO %s\r\n", hostname);
-       len = strlen(ehlo);
-#if 0
-       fprintf(stderr, "\nwrite_ehlo, ehlo = [%s]\n", ehlo);
-#endif
-       bytes_written = writen(sockfd, ehlo, len);
+
+       bytes_written = dprintf(sockfd, "EHLO %s\r\n", hostname);
        if(bytes_written < 0) {
                log_error(LOG_ARGS, "Could not write EHLO");
-               myfree(ehlo);
                return errno;
        }
-       myfree(ehlo);
        return 0;
 }
-/* "HELO \r\n" has length 7 */
-#define EXTRA_HELO_LEN 7
+
 int write_helo(int sockfd, const char *hostname)
 {
-       size_t len = (size_t)(strlen(hostname) + EXTRA_HELO_LEN + 1);
-       char *helo;
        size_t bytes_written;
-       
-       if((helo = mymalloc(len)) == 0)
-               return errno;
-       snprintf(helo, len, "HELO %s\r\n", hostname);
-       len = strlen(helo);
-#if 0
-       fprintf(stderr, "\nwrite_helo, helo = [%s]\n", helo);
-#endif
-       bytes_written = writen(sockfd, helo, len);
+
+       bytes_written = dprintf(sockfd, "HELO %s\r\n", hostname);
        if(bytes_written < 0) {
                log_error(LOG_ARGS, "Could not write HELO");
-               myfree(helo);
                return errno;
        }
-       myfree(helo);
        return 0;
 }
-/* "MAIL FROM:<> \r\n" has length 15 */
-#define EXTRA_FROM_LEN 15
+
 int write_mail_from(int sockfd, const char *from_addr, const char *extra)
 {
-       size_t len = (size_t)(strlen(from_addr) + EXTRA_FROM_LEN +
-                       strlen(extra) + 1);
-       char *mail_from;
        size_t bytes_written;
 
-       mail_from = mymalloc(len);
-
        if(extra && extra[0] != '\0') {
                if(extra[0] == ' ') extra++;
-               snprintf(mail_from, len, "MAIL FROM:<%s> %s\r\n", from_addr,
-                               extra);
+               bytes_written = dprintf(sockfd, "MAIL FROM:<%s> %s\r\n",
+                   from_addr, extra);
        } else
-               snprintf(mail_from, len, "MAIL FROM:<%s>\r\n", from_addr);
-
-       len = strlen(mail_from);
+               bytes_written = dprintf(sockfd, "MAIL FROM:<%s>\r\n", from_addr);
 
-#if 0
-       fprintf(stderr, "%s", mail_from);
-#endif
-       bytes_written = writen(sockfd, mail_from, len);
        if(bytes_written < 0) {
                log_error(LOG_ARGS, "Could not write FROM");
-               myfree(mail_from);
                return errno;
        }
-       myfree(mail_from);
        return 0;
 }
 
-/* "RCPT TO:<>\r\n" has length 12 */
-#define EXTRA_RCPT_LEN 12
 int write_rcpt_to(int sockfd, const char *rcpt_addr)
 {
-       size_t len = (size_t)(strlen(rcpt_addr) + EXTRA_RCPT_LEN + 1);
-       char *rcpt_to;
        size_t bytes_written;
-       
-       if((rcpt_to = mymalloc(len)) == 0)
-               return errno;
 
-       snprintf(rcpt_to, len, "RCPT TO:<%s>\r\n", rcpt_addr);
-       len = strlen(rcpt_to);
-#if 0
-       log_error(LOG_ARGS, "%s", rcpt_to);
-#endif
-       bytes_written = writen(sockfd, rcpt_to, len);
+       bytes_written = dprintf(sockfd, "RCPT TO:<%s>\r\n", rcpt_addr);
        if(bytes_written < 0) {
                log_error(LOG_ARGS, "Could not write TO");
-               myfree(rcpt_to);
                return errno;
        }
-       myfree(rcpt_to);
        return 0;
 }
 
-
 int write_mailbody_from_map(int sockfd, char *mapstart, size_t size,
                            const char *tohdr)
 {
@@ -155,7 +101,7 @@ int write_mailbody_from_map(int sockfd, char *mapstart, size_t size,
 
        for(next = cur = mapstart; next < mapstart + size; next++) {
                if(*next == '\n') {
-                       if(writen(sockfd, cur, next - cur) < 0) {
+                       if(dprintf(sockfd, "%.*s", (int)(next - cur), cur) < 0) {
                                log_error(LOG_ARGS, "Could not write mail");
                                return -1;
                        }
@@ -166,12 +112,12 @@ int write_mailbody_from_map(int sockfd, char *mapstart, size_t size,
                                newlinebuf[2] = '.';
                                len = 3;
                        }
-                       if(writen(sockfd, newlinebuf, len) < 0) {
+                       if(dprintf(sockfd, "%.*s", (int)len, newlinebuf) < 0) {
                                log_error(LOG_ARGS, "Could not write mail");
                                return -1;
                        }
                        if(i && tohdr && *(next+1) == '\n') { /* add To: header */
-                               if(writen(sockfd, tohdr, strlen(tohdr)) < 0) {
+                               if(dprintf(sockfd, "%s", tohdr) < 0) {
                                        log_error(LOG_ARGS, "Could not write"
                                                            " To: header");
                                        return -1;
@@ -268,64 +214,34 @@ int write_dot(int sockfd)
 {
        size_t bytes_written;
 
-       bytes_written = writen(sockfd, "\r\n.\r\n", 5); 
+       bytes_written = dprintf(sockfd, "\r\n.\r\n");
        if(bytes_written < 0)
                return errno;
 
        return 0;
 }
 
-/* "\r\n" has length 2 */
-#define EXTRA_CUSTOM_LEN 2
 int write_custom_line(int sockfd, const char *line)
 {
-       size_t len = strlen(line) + EXTRA_CUSTOM_LEN + 1;
        size_t bytes_written;
-       char *customline;
-       
-       if((customline = mymalloc(len)) == 0)
-               return errno;
-       
-       snprintf(customline, len, "%s\r\n", line);
-       len = strlen(customline);
-#if 0
-       fprintf(stderr, "write_custom_line = [%s]\n", customline);
-       fprintf(stderr, "strlen(customline) = [%d]\n", strlen(customline));
-#endif
-       bytes_written = writen(sockfd, customline, len);
+
+       bytes_written = dprintf(sockfd, "%s\r\n", line);
        if(bytes_written < 0) {
                log_error(LOG_ARGS, "Could not write customline");
-               myfree(customline);
                return errno;
        }
-       myfree(customline);
        return 0;
 }
 
-/* "Reply-To: \r\n" has length 12 */
-#define EXTRA_REPLYTO_LEN 12
 int write_replyto(int sockfd, const char *replyaddr)
 {
-       size_t len = (size_t)(strlen(replyaddr) + EXTRA_REPLYTO_LEN + 1);
-       char *replyto;
        size_t bytes_written;
        
-       if((replyto = mymalloc(len)) == 0)
-               return errno;
-
-       snprintf(replyto, len, "Reply-To: %s\r\n", replyaddr);
-       len = strlen(replyto);
-
-#if 0
-       fprintf(stderr, "\nwrite_replyto, replyto = [%s]\n", replyto);
-#endif
-       bytes_written = writen(sockfd, replyto, len);
+       bytes_written = dprintf(sockfd, "Reply-To: %s\r\n", replyaddr);
        if(bytes_written < 0) {
                log_error(LOG_ARGS, "Could not write Reply-To header");
-               myfree(replyto);
                return errno;
        }
-       myfree(replyto);
        return 0;
 }
 
index 7c1e6f2816478a618b045465afdcc37872cd51e9..f33cbd9c6bf11a537187550109f73e13449fe930 100644 (file)
@@ -93,7 +93,7 @@ static void do_probe(struct mlmmj_list *list, const char *mlmmjsend, const char
        if(fd < 0)
                log_error(LOG_ARGS, "Could not open %s", probefile);
        else
-               if(writen(fd, a, strlen(a)) < 0)
+               if(dprintf(fd, "%s", a) < 0)
                        log_error(LOG_ARGS, "Could not write time in probe");
 
        myfree(probefile);
@@ -239,9 +239,9 @@ int main(int argc, char **argv)
                                log_error(LOG_ARGS,
                                        "Have to invoke either as root "
                                        "or as the user owning listdir");
-                               writen(STDERR_FILENO,
+                               dprintf(STDERR_FILENO,
                                        "Have to invoke either as root "
-                                       "or as the user owning listdir\n", 60);
+                                       "or as the user owning listdir\n");
                                exit(EXIT_FAILURE);
                        }
                } else {
@@ -375,7 +375,7 @@ int main(int argc, char **argv)
        t = time(NULL);
        snprintf(buf, len-26, "%s:%ld # ", number, (long int)t);
        ctime_r(&t, buf+strlen(buf));
-       writen(fd, buf, strlen(buf));
+       dprintf(fd, "%s", buf);
        close(fd);
 
        if(mailname) {
index 5180c9cfa39f1e2c6796ab9b6227990fde8633fb..44767e7509ce5b69e2181bc5cfea013174afe5ad 100644 (file)
@@ -821,11 +821,10 @@ int run_digests(struct mlmmj_list *list, const char *mlmmjsend)
        char *lasttimestr, *lastindexstr, *lastissuestr;
        char *digestname, *indexname;
        char *digestintervalstr, *digestmaxmailsstr;
-       char *s1, *s2, *s3;
+       char *s1, *s2;
        time_t digestinterval, t, lasttime;
        long digestmaxmails, lastindex, index, lastissue;
        int fd, indexfd, lock;
-       size_t lenbuf, lenstr;
 
        if (statctrl(list, "noarchive")) {
                return 0;
@@ -932,16 +931,10 @@ int run_digests(struct mlmmj_list *list, const char *mlmmjsend)
                        log_error(LOG_ARGS, "Could not seek '%s'", digestname);
                } else {
                        /* index + ':' + time + ':' + issue + '\n' + '\0' */
-                       lenbuf = 20 + 1 + 20 + 1 + 20 + 2;
-                       s3 = mymalloc(lenbuf);
-                       lenstr = snprintf(s3, lenbuf, "%ld:%ld:%ld\n", index, (long)t, lastissue);
-                       if (lenstr >= lenbuf)
-                               lenstr = lenbuf - 1;
-                       if (writen(fd, s3, lenstr) == -1) {
+                       if (dprintf(fd, "%ld:%ld:%ld\n", index, (long)t, lastissue) == -1) {
                                log_error(LOG_ARGS, "Could not write new '%s'",
                                                digestname);
                        }
-                       myfree(s3);
                }
        }
 
@@ -1009,43 +1002,37 @@ void do_maintenance(const char *listdir, const char *mlmmjsend,
 
        t = time(NULL);
        if(ctime_r(&t, timenow))
-               WRITEMAINTLOG4(3, "Starting maintenance run at ",
-                               timenow, "\n");
+               WRITEMAINTLOG("Starting maintenance run at %s\n", timenow);
 
 
-       WRITEMAINTLOG4(3, "clean_moderation(", listdir, ");\n");
+       WRITEMAINTLOG("clean_moderation(%s);\n", listdir);
        clean_moderation(&list);
 
-       WRITEMAINTLOG4(3, "clean_discarded(", listdir, ");\n");
+       WRITEMAINTLOG("clean_discarded(%s);\n", listdir);
        clean_discarded(&list);
 
-       WRITEMAINTLOG4(3, "clean_subconf(", listdir, ");\n");
+       WRITEMAINTLOG("clean_subconf(%s);\n", listdir);
        clean_subconf(&list);
 
-       WRITEMAINTLOG4(3, "clean_unsubconf(", listdir, ");\n");
+       WRITEMAINTLOG("clean_unsubconf(%s);\n", listdir);
        clean_unsubconf(&list);
 
-       WRITEMAINTLOG6(5, "resend_queue(", listdir, ", ", mlmmjsend,
-                       ");\n");
+       WRITEMAINTLOG("resend_queue(%s, %s);\n)", listdir, mlmmjsend);
        resend_queue(&list, mlmmjsend);
 
-       WRITEMAINTLOG6(5, "resend_requeue(", listdir, ", ", mlmmjsend,
-                       ");\n");
+       WRITEMAINTLOG("resend_requeue(%s, %s);\n", listdir, mlmmjsend);
        resend_requeue(&list, mlmmjsend);
 
-       WRITEMAINTLOG4(3, "clean_nolongerbouncing(", listdir, ");\n");
+       WRITEMAINTLOG("clean_nolongerbouncing(%s);\n", listdir);
        clean_nolongerbouncing(&list);
 
-       WRITEMAINTLOG6(5, "unsub_bouncers(", listdir, ", ",
-                       mlmmjunsub, ");\n");
+       WRITEMAINTLOG("unsub_bouncers(%s, %s);\n", listdir, mlmmjunsub);
        unsub_bouncers(&list, mlmmjunsub);
 
-       WRITEMAINTLOG6(5, "probe_bouncers(", listdir, ", ",
-                       mlmmjbounce, ");\n");
+       WRITEMAINTLOG("probe_bouncers(%s, %s);\n", listdir, mlmmjbounce);
        probe_bouncers(&list, mlmmjbounce);
 
-       WRITEMAINTLOG6(5, "run_digests(", listdir, ", ", mlmmjsend,
-                       ");\n");
+       WRITEMAINTLOG("run_digests(%s, %s);\n", listdir, mlmmjsend);
        run_digests(&list, mlmmjsend);
 
        close(maintdlogfd);
index 613a25f2cb5c03601de025a3a4212134c0ccf34b..2946cebf111d59229002c0fe5c90cb56c7b11a88 100644 (file)
@@ -556,9 +556,9 @@ int main(int argc, char **argv)
                                log_error(LOG_ARGS,
                                        "Have to invoke either as root "
                                        "or as the user owning listdir");
-                               writen(STDERR_FILENO,
+                               dprintf(STDERR_FILENO,
                                        "Have to invoke either as root "
-                                       "or as the user owning listdir\n", 60);
+                                       "or as the user owning listdir\n");
                                exit(EXIT_FAILURE);
                        }
                } else {
@@ -1028,7 +1028,7 @@ int main(int argc, char **argv)
                                exit(EXIT_FAILURE);
                        }
                        myfree(omitfilename);
-                       if(writen(omitfd, posteraddr, strlen(posteraddr)) < 0) {
+                       if(dprintf(omitfd, "%s", posteraddr) < 0) {
                                log_error(LOG_ARGS,
                                                "could not write omit file");
                                myfree(mqueuename);
index b67de9a27a810529e95dee1f98b9079819fb1f05..1e275425e13e3178560f44b6df0ea3d3fc908b82 100644 (file)
@@ -113,9 +113,9 @@ int main(int argc, char **argv)
                                        "Have to invoke either as root "
                                        "or as the user owning listdir "
                                        "Invoked with uid = [%d]", (int)uid);
-                               writen(STDERR_FILENO,
+                               dprintf(STDERR_FILENO,
                                        "Have to invoke either as root "
-                                       "or as the user owning listdir\n", 60);
+                                       "or as the user owning listdir\n");
                                exit(EXIT_FAILURE);
                        }
                } else {
index 15cecd6988deb408ac83ebf342e094827b29e1ae..f43a918449d0802835dda200104e43e7681015e4 100644 (file)
@@ -318,20 +318,20 @@ int send_mail(int sockfd, const char *from, const char *to,
                tohdr = NULL;
 
        if(prepmailinmem) {
-               retval = writen(sockfd, hdrs, hdrslen);
+               retval = dprintf(sockfd, "%.*s", (int) hdrslen, hdrs);
                if(retval < 0) {
                        log_error(LOG_ARGS, "Could not write mailheaders.\n");
                        return retval;
                }
                if(tohdr) {
-                       retval = writen(sockfd, tohdr, strlen(tohdr));
+                       retval = dprintf(sockfd, "%s", tohdr);
                        if(retval < 0) {
                                log_error(LOG_ARGS, "Could not write To:.\n");
                                return retval;
                        }
                        myfree(tohdr);
                }
-               retval = writen(sockfd, body, bodylen);
+               retval = dprintf(sockfd, "%.*s", (int)bodylen, body);
                if(retval < 0) {
                        log_error(LOG_ARGS, "Could not write mailbody.\n");
                        return retval;
@@ -581,12 +581,12 @@ int send_mail_verp(int sockfd, struct strlist *addrs, char *mailmap,
        }
 
        if(prepmailinmem) {
-               retval = writen(sockfd, hdrs, hdrslen);
+               retval = dprintf(sockfd, "%.*s", (int)hdrslen, hdrs);
                if(retval < 0) {
                        log_error(LOG_ARGS, "Could not write mailheaders.\n");
                        return retval;
                }
-               retval = writen(sockfd, body, bodylen);
+               retval = dprintf(sockfd, "%.*s", (int)bodylen, body);
                if(retval < 0) {
                        log_error(LOG_ARGS, "Could not write mailbody.\n");
                        return retval;
@@ -666,7 +666,8 @@ int requeuemail(const char *listdir, const char *index, struct strlist *addrs,
                int addrcount)
 {
        int addrfd, i;
-       char *dirname, *addrfilename, *addr;
+       const char *addr;
+       char *dirname, *addrfilename;
        
        dirname = concatstr(3, listdir, "/requeue/", index);
        if(mkdir(dirname, 0750) < 0 && errno != EEXIST) {
@@ -691,21 +692,19 @@ int requeuemail(const char *listdir, const char *index, struct strlist *addrs,
                 * ones will be tried first when mlmmj-maintd sends out mails
                 * that have been requeued. addrcount was so far we were */
                for(i = addrcount + 1; i < addrs->count; i++) {
-                       addr = concatstr(2, addrs->strs[i], "\n");
-                       if(writen(addrfd, addr, strlen(addr)) < 0) {
+                       addr = addrs->strs[i];
+                       if(dprintf(addrfd, "%s\n", addr) < 0) {
                                log_error(LOG_ARGS, "Could not add [%s] "
                                                    "to requeue file", addr);
                                return -1;
                        }
-                       myfree(addr);
                }
-               addr = concatstr(2, addrs->strs[addrcount], "\n");
-               if(writen(addrfd, addr, strlen(addr)) < 0) {
+               addr = addrs->strs[addrcount];
+               if(dprintf(addrfd, "%s\n", addr) < 0) {
                        log_error(LOG_ARGS, "Could not add [%s] to requeue "
                                        "file", addr);
                        return -1;
                }
-               myfree(addr);
        }
        myfree(addrfilename);
        close(addrfd);
@@ -889,9 +888,9 @@ int main(int argc, char **argv)
                                log_error(LOG_ARGS,
                                        "Have to invoke either as root "
                                        "or as the user owning listdir");
-                               writen(STDERR_FILENO,
+                               dprintf(STDERR_FILENO,
                                        "Have to invoke either as root "
-                                       "or as the user owning listdir\n", 60);
+                                       "or as the user owning listdir\n");
                                exit(EXIT_FAILURE);
                        }
                } else {
@@ -1104,7 +1103,7 @@ int main(int argc, char **argv)
                                                S_IRUSR|S_IWUSR);
                        myfree(tmpstr);
                        if(tmpfd >= 0) {
-                               writen(tmpfd, bounceaddr, strlen(bounceaddr));
+                               dprintf(tmpfd, "%s", bounceaddr);
                                fsync(tmpfd);
                        }
                        close(tmpfd);
@@ -1117,7 +1116,7 @@ int main(int argc, char **argv)
                                                S_IRUSR|S_IWUSR);
                        myfree(tmpstr);
                        if(tmpfd >= 0) {
-                               writen(tmpfd, to_addr, strlen(to_addr));
+                               dprintf(tmpfd, "%s", to_addr);
                                fsync(tmpfd);
                        }
                        close(tmpfd);
@@ -1132,8 +1131,7 @@ int main(int argc, char **argv)
                                                        S_IRUSR|S_IWUSR);
                                myfree(tmpstr);
                                if(tmpfd >= 0) {
-                                       writen(tmpfd, replyto,
-                                               strlen(replyto));
+                                       dprintf(tmpfd, "%s", replyto);
                                        fsync(tmpfd);
                                }
                                close(tmpfd);
index 066e505e13802eb178415e5abc21834203696c1b..d23e690e2668125d4ce6a3d194e3911e34c1aee1 100644 (file)
@@ -98,7 +98,7 @@ static void moderate_sub(struct mlmmj_list *list, const char *subaddr,
                break;
        }
 
-       if(writen(fd, str, strlen(str)) < 0) {
+       if(dprintf(fd, "%s", str) < 0) {
                log_error(LOG_ARGS, "could not write to %s"
                                "ignoring request: %s", str);
                exit(EXIT_FAILURE);
@@ -408,7 +408,7 @@ static void generate_subconfirm(struct mlmmj_list *list, const char *subaddr,
 
        myfree(confirmfilename);
 
-       if(writen(subconffd, subaddr, strlen(subaddr)) < 0) {
+       if(dprintf(subconffd, "%s", subaddr) < 0) {
                log_error(LOG_ARGS, "Could not write to subconffd");
                myfree(confirmfilename);
                 myfree(randomstr);
index 6eec81caad9689c0191a08e96f5433f70ec62960..3fee1737714a25ba78a53a51649b8eac2bdd8f68 100644 (file)
@@ -167,7 +167,7 @@ static void generate_unsubconfirm(struct mlmmj_list *list, const char *subaddr,
 
        myfree(confirmfilename);
 
-       if(writen(subconffd, subaddr, strlen(subaddr)) < 0) {
+       if (dprintf(subconffd, "%s", subaddr) < 0) {
                log_error(LOG_ARGS, "Could not write unsubconffile");
                 myfree(randomstr);
                myfree(confirmfilename);
@@ -246,14 +246,14 @@ static ssize_t unsubscribe(int subreadfd, int subwritefd, const char *address)
        }
 
        if(suboff > 0) {
-               writeres = writen(subwritefd, inmap, suboff);
+               writeres = dprintf(subwritefd, "%.*s", (int)suboff, inmap);
                if(writeres < 0)
                        return -1;
        }
        written += writeres;
        
-       writeres = writen(subwritefd, inmap + len + suboff,
-                               st.st_size - len - suboff);
+       writeres = dprintf(subwritefd, "%.*s", (int)(st.st_size - len - suboff),
+                       inmap + len + suboff);
        if(writeres < 0)
                return -1;
 
index 0c87404836eb6e405ddf689d978b509516b26630..ab5ea5a06226383b6428901b46e7d40a6cb3856f 100644 (file)
@@ -1642,9 +1642,7 @@ char *prepstdreply(text *txt, struct mlmmj_list *list,
                if (*line == ' ' || *line == '\t') {
                        /* line beginning with linear whitespace is a
                           continuation of previous header line */
-                       len = strlen(line);
-                       line[len] = '\n';
-                       if(writen(outfd, line, len+1) < 0) {
+                       if(dprintf(outfd, "%s\n", line) < 0) {
                                log_error(LOG_ARGS, "Could not write std mail");
                                myfree(line);
                                myfree(retstr);
@@ -1682,9 +1680,7 @@ char *prepstdreply(text *txt, struct mlmmj_list *list,
                                line = concatstr(2, "Subject: ", tmp);
                                myfree(tmp);
                        }
-                       len = strlen(line);
-                       line[len] = '\n';
-                       if(writen(outfd, line, len+1) < 0) {
+                       if(dprintf(outfd, "%s\n", line) < 0) {
                                log_error(LOG_ARGS, "Could not write std mail");
                                myfree(line);
                                myfree(retstr);
@@ -1697,9 +1693,7 @@ char *prepstdreply(text *txt, struct mlmmj_list *list,
        }
 
        for (i=0; headers[i] != NULL; i++) {
-               len = strlen(headers[i]);
-               headers[i][len] = '\n';
-               if(writen(outfd, headers[i], len+1) < 0) {
+               if(dprintf(outfd, "%s\n", headers[i]) < 0) {
                        log_error(LOG_ARGS, "Could not write std mail");
                        if (line)
                                myfree(line);
@@ -1710,7 +1704,7 @@ char *prepstdreply(text *txt, struct mlmmj_list *list,
        }
 
        /* end the headers */
-       if(writen(outfd, "\n", 1) < 0) {
+       if(dprintf(outfd, "\n") < 0) {
                log_error(LOG_ARGS, "Could not write std mail");
                if (line)
                        myfree(line);
@@ -1723,9 +1717,7 @@ char *prepstdreply(text *txt, struct mlmmj_list *list,
                line = get_processed_text_line(txt, 0, list);
        }
        while(line) {
-                       len = strlen(line);
-                       line[len] = '\n';
-                       if(writen(outfd, line, len+1) < 0) {
+                       if(dprintf(outfd, "%s\n", line) < 0) {
                                myfree(str);
                                log_error(LOG_ARGS, "Could not write std mail");
                                myfree(retstr);
index 6f0558473c7933d0e7d3347768473faf6d2b6aad..abdf895665966389a9190d9d4c405b0794b38a90 100644 (file)
@@ -370,7 +370,7 @@ fallback_subject:
 
        myfree(subject);
 
-       if (writen(fd, tmp, strlen(tmp)) < 0) {
+       if (dprintf(fd, "%s", tmp) < 0) {
                myfree(tmp);
                goto errdighdrs;
        }
@@ -383,7 +383,7 @@ fallback_subject:
        close(hdrfd);
        hdrfd = -1;
 
-       if (writen(fd, "\n", 1) < 0) {
+       if (dprintf(fd, "\n") < 0) {
 errdighdrs:
                log_error(LOG_ARGS, "Could not write digest headers to '%s'",
                                queuename);
@@ -407,7 +407,7 @@ errdighdrs:
                                "\nContent-Type: text/plain; charset=UTF-8"
                                "\nContent-Transfer-Encoding: 8bit"
                                "\n\n");
-               if (writen(fd, tmp, strlen(tmp)) == -1) {
+               if (dprintf(fd, "%s", tmp) == -1) {
                        log_error(LOG_ARGS, "Could not write digest text/plain"
                                        " part headers to '%s'", queuename);
                        close(fd);
@@ -428,7 +428,7 @@ errdighdrs:
                        if (line == NULL) break;
                        len = strlen(line);
                        line[len] = '\n';
-                       if(writen(fd, line, len+1) < 0) {
+                       if(dprintf(fd, "%s", line) < 0) {
                                myfree(line);
                                log_error(LOG_ARGS, "Could not write"
                                                " std mail");
@@ -461,7 +461,7 @@ errdighdrs:
                                "\nContent-Disposition: inline; filename=\"",
                                        list->name, "_", buf, ".eml\""
                                "\n\n");
-               if (writen(fd, tmp, strlen(tmp)) == -1) {
+               if (dprintf(fd, "%s", tmp) == -1) {
                        log_error(LOG_ARGS, "Could not write digest part "
                                        "headers for archive index %d to "
                                        "'%s'", i, queuename);
@@ -491,7 +491,7 @@ errdighdrs:
        }
 
        tmp = concatstr(3, "\n--", boundary, "--\n");
-       if (writen(fd, tmp, strlen(tmp)) == -1) {
+       if (dprintf(fd, "%s", tmp) == -1) {
                log_error(LOG_ARGS, "Could not write digest end to '%s'",
                                queuename);
                close(fd);
index a3a9f6fe04f25f17955856077582193ef7e0ef42..75bf183607b8de6c777b56f0f833bf81b60ec946 100644 (file)
@@ -141,10 +141,9 @@ static void print_subs(int fd, subs_list_state *s)
        const char *sub;
        rewind_subs_list(s);
        while ((sub = get_sub(s)) != NULL) {
-               if (writen(fd, sub, strlen(sub)) < 0) {
+               if (dprintf(fd, "%s\n", sub) < 0) {
                        log_error(LOG_ARGS, "error writing subs list");
                }
-               writen(fd, "\n", 1);
        }
 }
 
@@ -199,11 +198,11 @@ void send_list(struct mlmmj_list *list, const char *emailaddr,
                        exit(EXIT_FAILURE);
                }
                print_subs(fd, normalsls);
-               writen(fd, "\n-- \n", 5);
+               dprintf(fd, "\n-- \n");
                print_subs(fd, nomailsls);
-               writen(fd, "\n-- \n", 5);
+               dprintf(fd, "\n-- \n");
                print_subs(fd, digestsls);
-               writen(fd, "\n-- \nend of output\n", 19);
+               dprintf(fd, "\n-- \nend of output\n");
                close(fd);
        }