]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
mlmmj-sub: stop forking to send subscription confirmation
authorBaptiste Daroussin <bapt@FreeBSD.org>
Wed, 8 Mar 2023 17:29:44 +0000 (18:29 +0100)
committerBaptiste Daroussin <bapt@FreeBSD.org>
Wed, 8 Mar 2023 17:29:44 +0000 (18:29 +0100)
include/send_help.h
src/mlmmj-sub.c
src/mlmmj-unsub.c
src/send_help.c
src/subscriberfuncs.c
tests/mlmmj.c

index deea3d80b8fe03f0a649bad36aba3b9a6c3220eb..352f70e3000523739187db0b5930c0b20d3eab25 100644 (file)
@@ -24,3 +24,4 @@
 #pragma once
 
 void send_help(struct ml *ml, const char *queuefilename, const char *emailaddr);
+void send_help_noexit(struct ml *ml, const char *queuefilename, const char *emailaddr);
index cda2b9abc7eb4e07f1d1b7109680c09ee3e113fc..ae139c77f53160c6c95345994735c7b36f4f000d 100644 (file)
@@ -320,12 +320,11 @@ int main(int argc, char **argv)
        char *mlmmjsend, *bindir;
        char *address = NULL, *modstr = NULL;
        int opt, subconfirm = 0, confirmsub = 0, notifysub;
-       int changeuid = 1, status, digest = 0, nomail = 0, both = 0;
+       int changeuid = 1, digest = 0, nomail = 0, both = 0;
        int nogensubscribed = 0;
        int force = 0, quiet = 0;
        enum subtype subbed;
        struct stat st;
-       pid_t pid, childpid = 0;
        uid_t uid;
        enum subtype typesub = SUB_NORMAL;
        enum subreason reasonsub = SUB_ADMIN;
@@ -491,24 +490,8 @@ int main(int argc, char **argv)
                subscribe_type(ml.fd, address, typesub);
        }
 
-       if(confirmsub) {
-               childpid = fork();
-
-               if(childpid < 0) {
-                       log_error(LOG_ARGS, "Could not fork; owner not notified");
-                       confirm_sub(&ml, address, typesub, reasonsub, true);
-               }
-               
-               if(childpid > 0) {
-                       do /* Parent waits for the child */
-                               pid = waitpid(childpid, &status, 0);
-                       while(pid == -1 && errno == EINTR);
-               }
-
-               /* child confirms subscription */
-               if(childpid == 0)
-                       confirm_sub(&ml, address, typesub, reasonsub, true);
-       }
+       if(confirmsub)
+               confirm_sub(&ml, address, typesub, reasonsub, true);
 
        notifysub = !quiet && reasonsub != SUB_SWITCH &&
                        statctrl(ml.ctrlfd, "notifysub");
index 04dc3c131f46dfd94bc4d88466103780bf7fbc8a..e2f6aa6c5b47d1f636960ede6c146ee8dc821e75 100644 (file)
@@ -74,14 +74,12 @@ int main(int argc, char **argv)
        int confirmunsub = 0, unsubconfirm = 0, notifysub = 0;
        int changeuid = 1, quiet = 0;
        int nogennotsubscribed = 0;
-       int status;
        char *address = NULL;
        const char *subdir;
        enum subtype typesub = SUB_ALL;
        enum subreason reasonsub = SUB_ADMIN;
        uid_t uid;
        struct stat st;
-       pid_t pid, childpid;
        struct ml ml;
 
        ml_init(&ml);
@@ -205,24 +203,8 @@ int main(int argc, char **argv)
 
        unsubscribe(ml.fd, address, typesub);
 
-       if(confirmunsub) {
-               childpid = fork();
-
-               if(childpid < 0) {
-                       log_error(LOG_ARGS, "Could not fork");
-                       confirm_sub(&ml, address, typesub, reasonsub, false);
-               }
-
-               if(childpid > 0) {
-                       do /* Parent waits for the child */
-                               pid = waitpid(childpid, &status, 0);
-                       while(pid == -1 && errno == EINTR);
-               }
-
-               /* child confirms subscription */
-               if(childpid == 0)
-                       confirm_sub(&ml, address, typesub, reasonsub, false);
-       }
+       if(confirmunsub)
+               confirm_sub(&ml, address, typesub, reasonsub, false);
 
        notifysub = !quiet && statctrl(ml.ctrlfd, "notifysub");
 
index 023aca9e2bccc03b3b4d39ee18b6e5ecabb267b7..c9e3fd59ce5710470f62027f52bf0345d9c2c0bf 100644 (file)
@@ -30,7 +30,7 @@
 #include "send_mail.h"
 
 void
-send_help(struct ml *ml, const char *queuefilename, const char *emailaddr)
+send_help_noexit(struct ml *ml, const char *queuefilename, const char *emailaddr)
 {
        char *fromaddr;
        struct mail mail = { 0 };
@@ -44,5 +44,11 @@ send_help(struct ml *ml, const char *queuefilename, const char *emailaddr)
                save_queue(queuefilename, &mail);
        else
                unlink(queuefilename);
+}
+
+void
+send_help(struct ml *ml, const char *queuefilename, const char *emailaddr)
+{
+       send_help_noexit(ml, queuefilename, emailaddr);
        exit(EXIT_SUCCESS);
 }
index 334172762478525b6901699e33852ea309c1202b..c0461f9eac3e1b8e52a35c889d4af838927793a7 100644 (file)
@@ -346,5 +346,5 @@ confirm_sub(struct ml *ml, const char *subaddr, enum subtype typesub,
        MY_ASSERT(queuefilename);
        close_text(txt);
 
-       send_help(ml, queuefilename, subaddr);
+       send_help_noexit(ml, queuefilename, subaddr);
 }
index 4d4c12e9d557a681307f4e5280c6ef02e0e45747..a8e4a61db0866558bf24b307d7101c797a94cbde 100644 (file)
@@ -2345,12 +2345,8 @@ ATF_TC_BODY(confirm_sub, tc)
        ATF_REQUIRE(socketpair(AF_UNIX, SOCK_STREAM, 0, smtppipe) >= 0);
        pid_t p2 = single_mail_reception(smtppipe[1]);
        atf_utils_readline(smtppipe[0]);
-       pid_t p = atf_utils_fork();
-       if (p == 0) {
-               confirm_sub(&ml, "test@plop", SUB_NORMAL, SUB_ADMIN, true);
-       }
+       confirm_sub(&ml, "test@plop", SUB_NORMAL, SUB_ADMIN, true);
        atf_utils_wait(p2, 0, "save:mailout.txt", "");
-       atf_utils_wait(p, 0, "", "");
        path = "mailout.txt";
        if (!atf_utils_grep_file(".*An administrator has subscribed you to the normal version of the list.*", path)) {
                atf_utils_cat_file(path, "");
@@ -2363,12 +2359,8 @@ ATF_TC_BODY(confirm_sub, tc)
 
        p2 = single_mail_reception(smtppipe[1]);
        atf_utils_readline(smtppipe[0]);
-       p = atf_utils_fork();
-       if (p == 0) {
-               confirm_sub(&ml, "test@plop", SUB_DIGEST, SUB_ADMIN, true);
-       }
+       confirm_sub(&ml, "test@plop", SUB_DIGEST, SUB_ADMIN, true);
        atf_utils_wait(p2, 0, "save:mailout.txt", "");
-       atf_utils_wait(p, 0, "", "");
        if (!atf_utils_grep_file(".*An administrator has subscribed you to the digest version of the list.*", path)) {
                atf_utils_cat_file(path, "");
                atf_tc_fail("invalid file");
@@ -2380,12 +2372,8 @@ ATF_TC_BODY(confirm_sub, tc)
 
        p2 = single_mail_reception(smtppipe[1]);
        atf_utils_readline(smtppipe[0]);
-       p = atf_utils_fork();
-       if (p == 0) {
-               confirm_sub(&ml, "test@plop", SUB_NOMAIL, SUB_CONFIRM, true);
-       }
+       confirm_sub(&ml, "test@plop", SUB_NOMAIL, SUB_CONFIRM, true);
        atf_utils_wait(p2, 0, "save:mailout.txt", "");
-       atf_utils_wait(p, 0, "", "");
        if (!atf_utils_grep_file(".*Thank you for confirming your subscription. You have now been added to the.*", path)) {
                atf_utils_cat_file(path, "");
                atf_tc_fail("invalid file");
@@ -2397,12 +2385,8 @@ ATF_TC_BODY(confirm_sub, tc)
 
        p2 = single_mail_reception(smtppipe[1]);
        atf_utils_readline(smtppipe[0]);
-       p = atf_utils_fork();
-       if (p == 0) {
-               confirm_sub(&ml, "test@plop", SUB_BOTH, SUB_REQUEST, true);
-       }
+       confirm_sub(&ml, "test@plop", SUB_BOTH, SUB_REQUEST, true);
        atf_utils_wait(p2, 0, "save:mailout.txt", "");
-       atf_utils_wait(p, 0, "", "");
        if (!atf_utils_grep_file(".*Thank you for your request to join us. You have now been added to the.*", path)) {
                atf_utils_cat_file(path, "");
                atf_tc_fail("invalid file");
@@ -2414,12 +2398,8 @@ ATF_TC_BODY(confirm_sub, tc)
 
        p2 = single_mail_reception(smtppipe[1]);
        atf_utils_readline(smtppipe[0]);
-       p = atf_utils_fork();
-       if (p == 0) {
-               confirm_sub(&ml, "test@plop", SUB_NORMAL, SUB_ADMIN, false);
-       }
+       confirm_sub(&ml, "test@plop", SUB_NORMAL, SUB_ADMIN, false);
        atf_utils_wait(p2, 0, "save:mailout.txt", "");
-       atf_utils_wait(p, 0, "", "");
        if (!atf_utils_grep_file(".*An administrator has removed you from the list.*", path)) {
                atf_utils_cat_file(path, "");
                atf_tc_fail("invalid file");
@@ -2427,12 +2407,8 @@ ATF_TC_BODY(confirm_sub, tc)
 
        p2 = single_mail_reception(smtppipe[1]);
        atf_utils_readline(smtppipe[0]);
-       p = atf_utils_fork();
-       if (p == 0) {
-               confirm_sub(&ml, "test@plop", SUB_DIGEST, SUB_ADMIN, false);
-       }
+       confirm_sub(&ml, "test@plop", SUB_DIGEST, SUB_ADMIN, false);
        atf_utils_wait(p2, 0, "save:mailout.txt", "");
-       atf_utils_wait(p, 0, "", "");
        if (!atf_utils_grep_file(".*An administrator has removed you from the list.*", path)) {
                atf_utils_cat_file(path, "");
                atf_tc_fail("invalid file");
@@ -2440,12 +2416,8 @@ ATF_TC_BODY(confirm_sub, tc)
 
        p2 = single_mail_reception(smtppipe[1]);
        atf_utils_readline(smtppipe[0]);
-       p = atf_utils_fork();
-       if (p == 0) {
-               confirm_sub(&ml, "test@plop", SUB_NOMAIL, SUB_CONFIRM, false);
-       }
+       confirm_sub(&ml, "test@plop", SUB_NOMAIL, SUB_CONFIRM, false);
        atf_utils_wait(p2, 0, "save:mailout.txt", "");
-       atf_utils_wait(p, 0, "", "");
        if (!atf_utils_grep_file(".*Thank you for confirming your unsubscribe. You have now been removed from.*", path)) {
                atf_utils_cat_file(path, "");
                atf_tc_fail("invalid file unsubscribe nomail confirm");
@@ -2453,12 +2425,8 @@ ATF_TC_BODY(confirm_sub, tc)
 
        p2 = single_mail_reception(smtppipe[1]);
        atf_utils_readline(smtppipe[0]);
-       p = atf_utils_fork();
-       if (p == 0) {
-               confirm_sub(&ml, "test@plop", SUB_BOTH, SUB_REQUEST, false);
-       }
+       confirm_sub(&ml, "test@plop", SUB_BOTH, SUB_REQUEST, false);
        atf_utils_wait(p2, 0, "save:mailout.txt", "");
-       atf_utils_wait(p, 0, "", "");
        if (!atf_utils_grep_file(".*You have now been removed from the list.*", path)) {
                atf_utils_cat_file(path, "");
                atf_tc_fail("invalid file");