Limit verbosity of messages printed to stderr.
Showing
2 changed files
with
60 additions
and
29 deletions
... | @@ -110,7 +110,8 @@ extern int check_quota (struct mu_auth_data *auth, | ... | @@ -110,7 +110,8 @@ extern int check_quota (struct mu_auth_data *auth, |
110 | 110 | ||
111 | int mda (mu_mailbox_t mbx, char *username); | 111 | int mda (mu_mailbox_t mbx, char *username); |
112 | int switch_user_id (struct mu_auth_data *auth, int user); | 112 | int switch_user_id (struct mu_auth_data *auth, int user); |
113 | void mailer_err (char *fmt, ...) MU_PRINTFLIKE(1,2); | 113 | void mailer_err (char *msg, char *arg, char *fmt, ...) |
114 | MU_PRINTFLIKE(3,4); | ||
114 | 115 | ||
115 | #ifdef WITH_GUILE | 116 | #ifdef WITH_GUILE |
116 | struct mda_data | 117 | struct mda_data | ... | ... |
... | @@ -47,7 +47,6 @@ void close_fds (void); | ... | @@ -47,7 +47,6 @@ void close_fds (void); |
47 | int make_tmp (const char *from, mu_mailbox_t *mbx); | 47 | int make_tmp (const char *from, mu_mailbox_t *mbx); |
48 | void deliver (mu_mailbox_t msg, char *name); | 48 | void deliver (mu_mailbox_t msg, char *name); |
49 | void guess_retval (int ec); | 49 | void guess_retval (int ec); |
50 | void mailer_err (char *fmt, ...); | ||
51 | void notify_biff (mu_mailbox_t mbox, char *name, size_t size); | 50 | void notify_biff (mu_mailbox_t mbox, char *name, size_t size); |
52 | 51 | ||
53 | const char *program_version = "mail.local (" PACKAGE_STRING ")"; | 52 | const char *program_version = "mail.local (" PACKAGE_STRING ")"; |
... | @@ -572,7 +571,8 @@ switch_user_id (struct mu_auth_data *auth, int user) | ... | @@ -572,7 +571,8 @@ switch_user_id (struct mu_auth_data *auth, int user) |
572 | # error "No way to reset user privileges?" | 571 | # error "No way to reset user privileges?" |
573 | #endif | 572 | #endif |
574 | if (rc < 0) | 573 | if (rc < 0) |
575 | mailer_err ("setreuid(0, %d): %s (r=%d, e=%d)", | 574 | mailer_err ("cannot set user priviledes", auth->name, |
575 | "setreuid(0, %d): %s (r=%d, e=%d)", | ||
576 | uid, strerror (errno), getuid (), geteuid ()); | 576 | uid, strerror (errno), getuid (), geteuid ()); |
577 | return rc; | 577 | return rc; |
578 | } | 578 | } |
... | @@ -603,13 +603,16 @@ make_tmp (const char *from, mu_mailbox_t *mbox) | ... | @@ -603,13 +603,16 @@ make_tmp (const char *from, mu_mailbox_t *mbox) |
603 | tempfile = mu_tempname (NULL); | 603 | tempfile = mu_tempname (NULL); |
604 | if ((status = mu_file_stream_create (&stream, tempfile, MU_STREAM_RDWR))) | 604 | if ((status = mu_file_stream_create (&stream, tempfile, MU_STREAM_RDWR))) |
605 | { | 605 | { |
606 | mailer_err (_("Unable to open temporary file: %s"), mu_strerror (status)); | 606 | mailer_err ("Temporary failure", NULL, |
607 | _("Unable to open temporary file: %s"), | ||
608 | mu_strerror (status)); | ||
607 | exit (exit_code); | 609 | exit (exit_code); |
608 | } | 610 | } |
609 | 611 | ||
610 | if ((status = mu_stream_open (stream))) | 612 | if ((status = mu_stream_open (stream))) |
611 | { | 613 | { |
612 | mailer_err (_("unable to open temporary file: %s"), mu_strerror (status)); | 614 | mailer_err ("Temporary failure", NULL, |
615 | _("unable to open temporary file: %s"), mu_strerror (status)); | ||
613 | exit (exit_code); | 616 | exit (exit_code); |
614 | } | 617 | } |
615 | 618 | ||
... | @@ -639,7 +642,8 @@ make_tmp (const char *from, mu_mailbox_t *mbox) | ... | @@ -639,7 +642,8 @@ make_tmp (const char *from, mu_mailbox_t *mbox) |
639 | } | 642 | } |
640 | else | 643 | else |
641 | { | 644 | { |
642 | mailer_err (_("Cannot determine sender address")); | 645 | mailer_err ("Cannot determine sender address", NULL, |
646 | _("Cannot determine sender address")); | ||
643 | exit (EX_UNAVAILABLE); | 647 | exit (EX_UNAVAILABLE); |
644 | } | 648 | } |
645 | if (auth) | 649 | if (auth) |
... | @@ -663,7 +667,9 @@ make_tmp (const char *from, mu_mailbox_t *mbox) | ... | @@ -663,7 +667,9 @@ make_tmp (const char *from, mu_mailbox_t *mbox) |
663 | 667 | ||
664 | if (status) | 668 | if (status) |
665 | { | 669 | { |
666 | mailer_err (_("Error writing temporary file: %s"), mu_strerror (status)); | 670 | mailer_err ("Temporary failure", NULL, |
671 | _("Error writing temporary file: %s"), | ||
672 | mu_strerror (status)); | ||
667 | mu_stream_destroy (&stream, mu_stream_get_owner (stream)); | 673 | mu_stream_destroy (&stream, mu_stream_get_owner (stream)); |
668 | return status; | 674 | return status; |
669 | } | 675 | } |
... | @@ -680,7 +686,8 @@ make_tmp (const char *from, mu_mailbox_t *mbox) | ... | @@ -680,7 +686,8 @@ make_tmp (const char *from, mu_mailbox_t *mbox) |
680 | if (status) | 686 | if (status) |
681 | { | 687 | { |
682 | errno = status; | 688 | errno = status; |
683 | mailer_err (_("Error writing temporary file: %s"), mu_strerror (status)); | 689 | mailer_err ("Error writing temporary file", NULL, |
690 | _("Error writing temporary file: %s"), mu_strerror (status)); | ||
684 | mu_stream_destroy (&stream, mu_stream_get_owner (stream)); | 691 | mu_stream_destroy (&stream, mu_stream_get_owner (stream)); |
685 | return status; | 692 | return status; |
686 | } | 693 | } |
... | @@ -690,7 +697,9 @@ make_tmp (const char *from, mu_mailbox_t *mbox) | ... | @@ -690,7 +697,9 @@ make_tmp (const char *from, mu_mailbox_t *mbox) |
690 | || (status = mu_mailbox_open (*mbox, MU_STREAM_READ)) | 697 | || (status = mu_mailbox_open (*mbox, MU_STREAM_READ)) |
691 | || (status = mu_mailbox_set_stream (*mbox, stream))) | 698 | || (status = mu_mailbox_set_stream (*mbox, stream))) |
692 | { | 699 | { |
693 | mailer_err (_("Error opening temporary file: %s"), mu_strerror (status)); | 700 | mailer_err ("Error opening temporary file", NULL, |
701 | _("Error opening temporary file: %s"), | ||
702 | mu_strerror (status)); | ||
694 | mu_stream_destroy (&stream, mu_stream_get_owner (stream)); | 703 | mu_stream_destroy (&stream, mu_stream_get_owner (stream)); |
695 | return status; | 704 | return status; |
696 | } | 705 | } |
... | @@ -699,7 +708,8 @@ make_tmp (const char *from, mu_mailbox_t *mbox) | ... | @@ -699,7 +708,8 @@ make_tmp (const char *from, mu_mailbox_t *mbox) |
699 | if (status) | 708 | if (status) |
700 | { | 709 | { |
701 | errno = status; | 710 | errno = status; |
702 | mailer_err (_("Error creating temporary message: %s"), | 711 | mailer_err ("Error collecting message", NULL, |
712 | _("Error creating temporary message: %s"), | ||
703 | mu_strerror (status)); | 713 | mu_strerror (status)); |
704 | mu_stream_destroy (&stream, mu_stream_get_owner (stream)); | 714 | mu_stream_destroy (&stream, mu_stream_get_owner (stream)); |
705 | return status; | 715 | return status; |
... | @@ -725,7 +735,8 @@ deliver (mu_mailbox_t imbx, char *name) | ... | @@ -725,7 +735,8 @@ deliver (mu_mailbox_t imbx, char *name) |
725 | auth = mu_get_auth_by_name (name); | 735 | auth = mu_get_auth_by_name (name); |
726 | if (!auth) | 736 | if (!auth) |
727 | { | 737 | { |
728 | mailer_err (_("%s: no such user"), name); | 738 | mailer_err ("no such user", name, |
739 | _("%s: no such user"), name); | ||
729 | exit_code = EX_UNAVAILABLE; | 740 | exit_code = EX_UNAVAILABLE; |
730 | return; | 741 | return; |
731 | } | 742 | } |
... | @@ -741,7 +752,8 @@ deliver (mu_mailbox_t imbx, char *name) | ... | @@ -741,7 +752,8 @@ deliver (mu_mailbox_t imbx, char *name) |
741 | 752 | ||
742 | if ((status = mu_mailbox_get_message (imbx, 1, &msg)) != 0) | 753 | if ((status = mu_mailbox_get_message (imbx, 1, &msg)) != 0) |
743 | { | 754 | { |
744 | mailer_err (_("Cannot get message from the temporary mailbox: %s"), | 755 | mailer_err ("cannot read message", name, |
756 | _("Cannot get message from the temporary mailbox: %s"), | ||
745 | mu_strerror (status)); | 757 | mu_strerror (status)); |
746 | mu_auth_data_free (auth); | 758 | mu_auth_data_free (auth); |
747 | return; | 759 | return; |
... | @@ -749,7 +761,8 @@ deliver (mu_mailbox_t imbx, char *name) | ... | @@ -749,7 +761,8 @@ deliver (mu_mailbox_t imbx, char *name) |
749 | 761 | ||
750 | if ((status = mu_message_get_stream (msg, &istream)) != 0) | 762 | if ((status = mu_message_get_stream (msg, &istream)) != 0) |
751 | { | 763 | { |
752 | mailer_err (_("Cannot get input message stream: %s"), | 764 | mailer_err ("cannot read message", name, |
765 | _("Cannot get input message stream: %s"), | ||
753 | mu_strerror (status)); | 766 | mu_strerror (status)); |
754 | mu_auth_data_free (auth); | 767 | mu_auth_data_free (auth); |
755 | return; | 768 | return; |
... | @@ -757,7 +770,8 @@ deliver (mu_mailbox_t imbx, char *name) | ... | @@ -757,7 +770,8 @@ deliver (mu_mailbox_t imbx, char *name) |
757 | 770 | ||
758 | if ((status = mu_mailbox_create (&mbox, auth->mailbox)) != 0) | 771 | if ((status = mu_mailbox_create (&mbox, auth->mailbox)) != 0) |
759 | { | 772 | { |
760 | mailer_err (_("Cannot open mailbox %s: %s"), | 773 | mailer_err ("cannot read message", name, |
774 | _("Cannot open mailbox %s: %s"), | ||
761 | auth->mailbox, mu_strerror (status)); | 775 | auth->mailbox, mu_strerror (status)); |
762 | mu_auth_data_free (auth); | 776 | mu_auth_data_free (auth); |
763 | return; | 777 | return; |
... | @@ -776,7 +790,8 @@ deliver (mu_mailbox_t imbx, char *name) | ... | @@ -776,7 +790,8 @@ deliver (mu_mailbox_t imbx, char *name) |
776 | return; | 790 | return; |
777 | if (status != 0) | 791 | if (status != 0) |
778 | { | 792 | { |
779 | mailer_err (_("Cannot open mailbox %s: %s"), path, mu_strerror (status)); | 793 | mailer_err ("cannot open mailbox", name, |
794 | _("Cannot open mailbox %s: %s"), path, mu_strerror (status)); | ||
780 | mu_mailbox_destroy (&mbox); | 795 | mu_mailbox_destroy (&mbox); |
781 | return; | 796 | return; |
782 | } | 797 | } |
... | @@ -787,7 +802,8 @@ deliver (mu_mailbox_t imbx, char *name) | ... | @@ -787,7 +802,8 @@ deliver (mu_mailbox_t imbx, char *name) |
787 | 802 | ||
788 | if (status) | 803 | if (status) |
789 | { | 804 | { |
790 | mailer_err (_("Cannot lock mailbox `%s': %s"), path, | 805 | mailer_err ("cannot lock mailbox", name, |
806 | _("Cannot lock mailbox `%s': %s"), path, | ||
791 | mu_strerror (status)); | 807 | mu_strerror (status)); |
792 | mu_mailbox_destroy (&mbox); | 808 | mu_mailbox_destroy (&mbox); |
793 | exit_code = EX_TEMPFAIL; | 809 | exit_code = EX_TEMPFAIL; |
... | @@ -796,7 +812,8 @@ deliver (mu_mailbox_t imbx, char *name) | ... | @@ -796,7 +812,8 @@ deliver (mu_mailbox_t imbx, char *name) |
796 | 812 | ||
797 | if ((status = mu_mailbox_get_stream (mbox, &ostream))) | 813 | if ((status = mu_mailbox_get_stream (mbox, &ostream))) |
798 | { | 814 | { |
799 | mailer_err (_("Cannot get stream for mailbox %s: %s"), | 815 | mailer_err ("cannot access mailbox", name, |
816 | _("Cannot get stream for mailbox %s: %s"), | ||
800 | path, mu_strerror (status)); | 817 | path, mu_strerror (status)); |
801 | mu_mailbox_destroy (&mbox); | 818 | mu_mailbox_destroy (&mbox); |
802 | return; | 819 | return; |
... | @@ -804,7 +821,8 @@ deliver (mu_mailbox_t imbx, char *name) | ... | @@ -804,7 +821,8 @@ deliver (mu_mailbox_t imbx, char *name) |
804 | 821 | ||
805 | if ((status = mu_stream_size (ostream, &size))) | 822 | if ((status = mu_stream_size (ostream, &size))) |
806 | { | 823 | { |
807 | mailer_err (_("Cannot get stream size (mailbox %s): %s"), | 824 | mailer_err ("cannot access mailbox", name, |
825 | _("Cannot get stream size (mailbox %s): %s"), | ||
808 | path, mu_strerror (status)); | 826 | path, mu_strerror (status)); |
809 | mu_mailbox_destroy (&mbox); | 827 | mu_mailbox_destroy (&mbox); |
810 | return; | 828 | return; |
... | @@ -818,7 +836,8 @@ deliver (mu_mailbox_t imbx, char *name) | ... | @@ -818,7 +836,8 @@ deliver (mu_mailbox_t imbx, char *name) |
818 | switch (check_quota (auth, size, &n)) | 836 | switch (check_quota (auth, size, &n)) |
819 | { | 837 | { |
820 | case MQUOTA_EXCEEDED: | 838 | case MQUOTA_EXCEEDED: |
821 | mailer_err (_("%s: mailbox quota exceeded for this recipient"), name); | 839 | mailer_err ("mailbox quota exceeded for this recipient", name, |
840 | _("%s: mailbox quota exceeded for this recipient"), name); | ||
822 | exit_code = EX_QUOTA(); | 841 | exit_code = EX_QUOTA(); |
823 | failed++; | 842 | failed++; |
824 | break; | 843 | break; |
... | @@ -829,14 +848,17 @@ deliver (mu_mailbox_t imbx, char *name) | ... | @@ -829,14 +848,17 @@ deliver (mu_mailbox_t imbx, char *name) |
829 | default: | 848 | default: |
830 | if ((status = mu_stream_size (istream, &isize))) | 849 | if ((status = mu_stream_size (istream, &isize))) |
831 | { | 850 | { |
832 | mailer_err (_("Cannot get stream size (input message %s): %s"), | 851 | mailer_err ("cannot access mailbox", name, |
852 | _("Cannot get stream size (input message %s): %s"), | ||
833 | path, mu_strerror (status)); | 853 | path, mu_strerror (status)); |
834 | exit_code = EX_UNAVAILABLE; | 854 | exit_code = EX_UNAVAILABLE; |
835 | failed++; | 855 | failed++; |
836 | } | 856 | } |
837 | else if (isize > n) | 857 | else if (isize > n) |
838 | { | 858 | { |
839 | mailer_err (_("%s: message would exceed maximum mailbox size for this recipient"), | 859 | mailer_err ("message would exceed maximum mailbox size for this recipient", |
860 | name, | ||
861 | _("%s: message would exceed maximum mailbox size for this recipient"), | ||
840 | name); | 862 | name); |
841 | exit_code = EX_QUOTA(); | 863 | exit_code = EX_QUOTA(); |
842 | failed++; | 864 | failed++; |
... | @@ -893,10 +915,12 @@ deliver (mu_mailbox_t imbx, char *name) | ... | @@ -893,10 +915,12 @@ deliver (mu_mailbox_t imbx, char *name) |
893 | original size */ | 915 | original size */ |
894 | int rc = mu_stream_truncate (ostream, size); | 916 | int rc = mu_stream_truncate (ostream, size); |
895 | if (rc) | 917 | if (rc) |
896 | mailer_err (_("Error writing to mailbox: %s. Mailbox NOT truncated: %s"), | 918 | mailer_err ("write error", name, |
919 | _("Error writing to mailbox: %s. Mailbox NOT truncated: %s"), | ||
897 | mu_strerror (status), mu_strerror (rc)); | 920 | mu_strerror (status), mu_strerror (rc)); |
898 | else | 921 | else |
899 | mailer_err (_("Error writing to mailbox: %s"), | 922 | mailer_err ("write error", name, |
923 | _("Error writing to mailbox: %s"), | ||
900 | mu_strerror (status)); | 924 | mu_strerror (status)); |
901 | } | 925 | } |
902 | } | 926 | } |
... | @@ -950,16 +974,22 @@ notify_biff (mu_mailbox_t mbox, char *name, size_t size) | ... | @@ -950,16 +974,22 @@ notify_biff (mu_mailbox_t mbox, char *name, size_t size) |
950 | } | 974 | } |
951 | 975 | ||
952 | void | 976 | void |
953 | mailer_err (char *fmt, ...) | 977 | mailer_err (char *msg, char *arg, char *fmt, ...) |
954 | { | 978 | { |
955 | va_list ap; | 979 | va_list ap; |
956 | 980 | ||
957 | guess_retval (errno); | 981 | guess_retval (errno); |
958 | va_start (ap, fmt); | 982 | if (arg) |
959 | vfprintf (stderr, fmt, ap); | 983 | fprintf (stderr, "<%s>: %s", arg, msg); |
960 | fprintf (stderr, "\n"); | 984 | else |
961 | mu_verror (fmt, ap); | 985 | fputs (msg, stderr); |
962 | va_end (ap); | 986 | fputc ('\n', stderr); |
987 | if (fmt) | ||
988 | { | ||
989 | va_start (ap, fmt); | ||
990 | mu_verror (fmt, ap); | ||
991 | va_end (ap); | ||
992 | } | ||
963 | } | 993 | } |
964 | 994 | ||
965 | int temp_errors[] = { | 995 | int temp_errors[] = { | ... | ... |
-
Please register or sign in to post a comment