From: Baptiste Daroussin Date: Wed, 8 Mar 2023 17:29:44 +0000 (+0100) Subject: mlmmj-sub: stop forking to send subscription confirmation X-Git-Tag: RELEASE_1_4_0b1~70 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e9b1103d47ed00047acccc702a2bc4d8f0f01dd6;p=thirdparty%2Fmlmmj.git mlmmj-sub: stop forking to send subscription confirmation --- diff --git a/include/send_help.h b/include/send_help.h index deea3d80..352f70e3 100644 --- a/include/send_help.h +++ b/include/send_help.h @@ -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); diff --git a/src/mlmmj-sub.c b/src/mlmmj-sub.c index cda2b9ab..ae139c77 100644 --- a/src/mlmmj-sub.c +++ b/src/mlmmj-sub.c @@ -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"); diff --git a/src/mlmmj-unsub.c b/src/mlmmj-unsub.c index 04dc3c13..e2f6aa6c 100644 --- a/src/mlmmj-unsub.c +++ b/src/mlmmj-unsub.c @@ -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"); diff --git a/src/send_help.c b/src/send_help.c index 023aca9e..c9e3fd59 100644 --- a/src/send_help.c +++ b/src/send_help.c @@ -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); } diff --git a/src/subscriberfuncs.c b/src/subscriberfuncs.c index 33417276..c0461f9e 100644 --- a/src/subscriberfuncs.c +++ b/src/subscriberfuncs.c @@ -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); } diff --git a/tests/mlmmj.c b/tests/mlmmj.c index 4d4c12e9..a8e4a61d 100644 --- a/tests/mlmmj.c +++ b/tests/mlmmj.c @@ -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");