From: Baptiste Daroussin Date: Fri, 28 Oct 2022 13:29:43 +0000 (+0200) Subject: mlmmj-maintd: improve error handling of bouncers unsubscribtion X-Git-Tag: RELEASE_1_4_0a1~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f35d104e3d4e69d2fa768d5ba38b838bd723cb7a;p=thirdparty%2Fmlmmj.git mlmmj-maintd: improve error handling of bouncers unsubscribtion Now report an error if something went wrong, and keep the bounce file around to make sure that maintd get another chance and unsubscribing bouncers. (In the hope that an administrator will see the logs and fix what needs to be fixed) --- diff --git a/ChangeLog b/ChangeLog index fb6a02a4..fb8504b5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,8 @@ o Reduce subscription confirmation address length to fit RFC 5321 o Use arc4random is available o Reduce memory manipulation + o When unsubscribing bouncers, keep the bounce file if something went + wrong and report in syslog what went wrong 1.3.0 o Czech translation (Jiří Šolc) o Don't use address extensions from non-list addresses diff --git a/src/mlmmj-maintd.c b/src/mlmmj-maintd.c index b616888a..31bd665a 100644 --- a/src/mlmmj-maintd.c +++ b/src/mlmmj-maintd.c @@ -487,7 +487,7 @@ probe_bouncers(int dfd, const char *mlmmjbounce, const char *listdir, int logfd) } static bool -unsub_bouncers(int dfd, const char *mlmmjunsub, const char *listdir, int logfd) +unsub_bouncers(int dfd, int logfd) { DIR *bouncedir; char *probefile, *address, *a, *firstbounce; @@ -566,8 +566,12 @@ unsub_bouncers(int dfd, const char *mlmmjunsub, const char *listdir, int logfd) } *a = '@'; - exec_and_wait(mlmmjunsub, "-L", listdir, "-b", "-a", address, - NULL); + if (!do_unsubscribe(dfd, address, SUB_ALL)) { + log(" - Some errors during unsubscription of %s\n", + address); + ret = false; + continue; + } unlinkat(bfd, dp->d_name, 0); xasprintf(&a, "%s.lastmsg", dp->d_name); unlinkat(bfd, a, 0); @@ -675,7 +679,7 @@ out: } void do_maintenance(int listfd, const char *listdir, const char *mlmmjsend, - const char *mlmmjbounce, const char *mlmmjunsub) + const char *mlmmjbounce) { char *random, *logname; char timenow[64]; @@ -757,7 +761,7 @@ void do_maintenance(int listfd, const char *listdir, const char *mlmmjsend, "traces, see %s", MAINTD_LOGFILE); log("unsub_bouncers\n"); - if (!unsub_bouncers(listfd, mlmmjunsub, listdir, logfd)) + if (!unsub_bouncers(listfd, logfd)) log_err("An error occured while unsubscribing bouncing emails, " "see %s", MAINTD_LOGFILE); @@ -842,8 +846,7 @@ int main(int argc, char **argv) if(listdir) { log_set_namef("%s(%s)", argv[0], listdir); int fd = open(listdir, O_DIRECTORY); - do_maintenance(fd, listdir, mlmmjsend, mlmmjbounce, - mlmmjunsub); + do_maintenance(fd, listdir, mlmmjsend, mlmmjbounce); goto mainsleep; } @@ -873,8 +876,7 @@ int main(int argc, char **argv) char *l; xasprintf(&l, "%s/%s", dirlists, dp->d_name); log_set_namef("%s(%s)", argv[0], l); - do_maintenance(fd, l, mlmmjsend, mlmmjbounce, - mlmmjunsub); + do_maintenance(fd, l, mlmmjsend, mlmmjbounce); free(l); close(fd); } diff --git a/tests/mlmmj-maintd.sh b/tests/mlmmj-maintd.sh index f97a9d8b..ba29d9b1 100755 --- a/tests/mlmmj-maintd.sh +++ b/tests/mlmmj-maintd.sh @@ -450,4 +450,27 @@ run_digests atf_check -s exit:1 test -f list/subscribers.d/p atf_check -s exit:1 test -f list/digesters.d/p atf_check -s exit:1 test -f list/nomailsubs.d/p + + echo "a:1234 # plop" > list/bounce/plop=meh + echo "plop@meh" > list/digesters.d/p + rm -rf list/nomailsubs.d + atf_check -s exit:0 -e match:"An error occured while unsubscribing bouncing emails, see mlmmj-maintd.lastrun.log" $mlmmjmaintd -L list -F + atf_check -s exit:0 test -f list/bounce/plop=meh + atf_check -s exit:1 test -f list/digesters.d/p + output="Starting maintenance run at + +clean_moderation +clean_discarded +clean_subconf +clean_unsubconf +resend_queue +resend_requeue +clean_nolongerbouncing +unsub_bouncers + - Some errors during unsubscription of plop@meh +probe_bouncers +run_digests + - No readable index file: no digest +" + atf_check -o "inline:$output" sed -e "s/at .*/at/" list/mlmmj-maintd.lastrun.log }