locker API modified.
using mu_errstring() instead of strerror().
Showing
3 changed files
with
23 additions
and
24 deletions
... | @@ -49,6 +49,7 @@ | ... | @@ -49,6 +49,7 @@ |
49 | # include <strings.h> | 49 | # include <strings.h> |
50 | #endif | 50 | #endif |
51 | 51 | ||
52 | #include <mailutils/errno.h> | ||
52 | #include <mailutils/message.h> | 53 | #include <mailutils/message.h> |
53 | #include <mailutils/stream.h> | 54 | #include <mailutils/stream.h> |
54 | #include <mailutils/body.h> | 55 | #include <mailutils/body.h> |
... | @@ -380,11 +381,8 @@ mbox_open (mailbox_t mailbox, int flags) | ... | @@ -380,11 +381,8 @@ mbox_open (mailbox_t mailbox, int flags) |
380 | MAILBOX_DEBUG2 (mailbox, MU_DEBUG_TRACE, "mbox_open(%s, 0x%x)\n", | 381 | MAILBOX_DEBUG2 (mailbox, MU_DEBUG_TRACE, "mbox_open(%s, 0x%x)\n", |
381 | mud->name, mailbox->flags); | 382 | mud->name, mailbox->flags); |
382 | 383 | ||
383 | /* Give an appropriate way to file lock. */ | ||
384 | /* FIXME: use dotlock external program: we may not be setgid. */ | ||
385 | if (mailbox->locker == NULL) | 384 | if (mailbox->locker == NULL) |
386 | status = locker_create (&(mailbox->locker), mud->name, strlen (mud->name), | 385 | status = locker_create (&(mailbox->locker), mud->name, 0); |
387 | MU_LOCKER_PID | MU_LOCKER_FCNTL); | ||
388 | return status; | 386 | return status; |
389 | } | 387 | } |
390 | 388 | ||
... | @@ -652,14 +650,14 @@ mbox_expunge0 (mailbox_t mailbox, int remove_deleted) | ... | @@ -652,14 +650,14 @@ mbox_expunge0 (mailbox_t mailbox, int remove_deleted) |
652 | } | 650 | } |
653 | 651 | ||
654 | /* Get the File lock. */ | 652 | /* Get the File lock. */ |
655 | if (locker_lock (mailbox->locker, MU_LOCKER_WRLOCK) != 0) | 653 | if ((status = locker_lock (mailbox->locker)) != 0) |
656 | { | 654 | { |
657 | mailbox_close (tmpmailbox); | 655 | mailbox_close (tmpmailbox); |
658 | mailbox_destroy (&tmpmailbox); | 656 | mailbox_destroy (&tmpmailbox); |
659 | remove (tmpmboxname); | 657 | remove (tmpmboxname); |
660 | free (tmpmboxname); | 658 | free (tmpmboxname); |
661 | mu_error ("Failed to grab the lock\n"); | 659 | mu_error ("Failed to grab the lock: %s\n", mu_errstring(status)); |
662 | return ENOLCK; | 660 | return status; |
663 | } | 661 | } |
664 | 662 | ||
665 | /* Critical section, we can not allowed signal here. */ | 663 | /* Critical section, we can not allowed signal here. */ |
... | @@ -711,7 +709,7 @@ mbox_expunge0 (mailbox_t mailbox, int remove_deleted) | ... | @@ -711,7 +709,7 @@ mbox_expunge0 (mailbox_t mailbox, int remove_deleted) |
711 | if (status != 0) | 709 | if (status != 0) |
712 | { | 710 | { |
713 | mu_error ("Error expunge:%d: %s", __LINE__, | 711 | mu_error ("Error expunge:%d: %s", __LINE__, |
714 | strerror (status)); | 712 | mu_errstring (status)); |
715 | goto bailout0; | 713 | goto bailout0; |
716 | } | 714 | } |
717 | } | 715 | } |
... | @@ -720,7 +718,7 @@ mbox_expunge0 (mailbox_t mailbox, int remove_deleted) | ... | @@ -720,7 +718,7 @@ mbox_expunge0 (mailbox_t mailbox, int remove_deleted) |
720 | if (status != 0) | 718 | if (status != 0) |
721 | { | 719 | { |
722 | mu_error ("Error expunge:%d: %s", __LINE__, | 720 | mu_error ("Error expunge:%d: %s", __LINE__, |
723 | strerror (status)); | 721 | mu_errstring (status)); |
724 | goto bailout0; | 722 | goto bailout0; |
725 | } | 723 | } |
726 | /* Clear the dirty bits. */ | 724 | /* Clear the dirty bits. */ |
... | @@ -743,7 +741,7 @@ mbox_expunge0 (mailbox_t mailbox, int remove_deleted) | ... | @@ -743,7 +741,7 @@ mbox_expunge0 (mailbox_t mailbox, int remove_deleted) |
743 | total, &n) != 0)) | 741 | total, &n) != 0)) |
744 | { | 742 | { |
745 | mu_error ("Error expunge:%d: %s", __LINE__, | 743 | mu_error ("Error expunge:%d: %s", __LINE__, |
746 | strerror (status)); | 744 | mu_errstring (status)); |
747 | goto bailout0; | 745 | goto bailout0; |
748 | } | 746 | } |
749 | len -= n; | 747 | len -= n; |
... | @@ -755,7 +753,7 @@ mbox_expunge0 (mailbox_t mailbox, int remove_deleted) | ... | @@ -755,7 +753,7 @@ mbox_expunge0 (mailbox_t mailbox, int remove_deleted) |
755 | if (status != 0) | 753 | if (status != 0) |
756 | { | 754 | { |
757 | mu_error ("Error expunge:%d: %s", __LINE__, | 755 | mu_error ("Error expunge:%d: %s", __LINE__, |
758 | strerror (status)); | 756 | mu_errstring (status)); |
759 | goto bailout0; | 757 | goto bailout0; |
760 | } | 758 | } |
761 | total++; | 759 | total++; |
... | @@ -785,7 +783,7 @@ mbox_expunge0 (mailbox_t mailbox, int remove_deleted) | ... | @@ -785,7 +783,7 @@ mbox_expunge0 (mailbox_t mailbox, int remove_deleted) |
785 | if (status != 0) | 783 | if (status != 0) |
786 | { | 784 | { |
787 | mu_error ("Error expunge:%d: %s", __LINE__, | 785 | mu_error ("Error expunge:%d: %s", __LINE__, |
788 | strerror (status)); | 786 | mu_errstring (status)); |
789 | goto bailout0; | 787 | goto bailout0; |
790 | } | 788 | } |
791 | total += n; | 789 | total += n; |
... | @@ -796,7 +794,7 @@ mbox_expunge0 (mailbox_t mailbox, int remove_deleted) | ... | @@ -796,7 +794,7 @@ mbox_expunge0 (mailbox_t mailbox, int remove_deleted) |
796 | { | 794 | { |
797 | /* Corrupted mailbox. */ | 795 | /* Corrupted mailbox. */ |
798 | mu_error ("Error expunge:%d: %s", __LINE__, | 796 | mu_error ("Error expunge:%d: %s", __LINE__, |
799 | strerror (status)); | 797 | mu_errstring (status)); |
800 | goto bailout0; | 798 | goto bailout0; |
801 | } | 799 | } |
802 | } | 800 | } |
... | @@ -817,7 +815,7 @@ mbox_expunge0 (mailbox_t mailbox, int remove_deleted) | ... | @@ -817,7 +815,7 @@ mbox_expunge0 (mailbox_t mailbox, int remove_deleted) |
817 | if (status != 0) | 815 | if (status != 0) |
818 | { | 816 | { |
819 | mu_error ("Error expunge:%d: %s\n", __LINE__, | 817 | mu_error ("Error expunge:%d: %s\n", __LINE__, |
820 | strerror (status)); | 818 | mu_errstring (status)); |
821 | goto bailout; | 819 | goto bailout; |
822 | } | 820 | } |
823 | off += n; | 821 | off += n; |
... | @@ -831,7 +829,7 @@ mbox_expunge0 (mailbox_t mailbox, int remove_deleted) | ... | @@ -831,7 +829,7 @@ mbox_expunge0 (mailbox_t mailbox, int remove_deleted) |
831 | if (status != 0) | 829 | if (status != 0) |
832 | { | 830 | { |
833 | mu_error ("Error expunging:%d: %s\n", __LINE__, | 831 | mu_error ("Error expunging:%d: %s\n", __LINE__, |
834 | strerror (status)); | 832 | mu_errstring (status)); |
835 | goto bailout; | 833 | goto bailout; |
836 | } | 834 | } |
837 | 835 | ||
... | @@ -1399,6 +1397,7 @@ mbox_get_message (mailbox_t mailbox, size_t msgno, message_t *pmsg) | ... | @@ -1399,6 +1397,7 @@ mbox_get_message (mailbox_t mailbox, size_t msgno, message_t *pmsg) |
1399 | static int | 1397 | static int |
1400 | mbox_append_message (mailbox_t mailbox, message_t msg) | 1398 | mbox_append_message (mailbox_t mailbox, message_t msg) |
1401 | { | 1399 | { |
1400 | int status = 0; | ||
1402 | mbox_data_t mud = mailbox->data; | 1401 | mbox_data_t mud = mailbox->data; |
1403 | if (msg == NULL || mud == NULL) | 1402 | if (msg == NULL || mud == NULL) |
1404 | return EINVAL; | 1403 | return EINVAL; |
... | @@ -1409,11 +1408,12 @@ mbox_append_message (mailbox_t mailbox, message_t msg) | ... | @@ -1409,11 +1408,12 @@ mbox_append_message (mailbox_t mailbox, message_t msg) |
1409 | switch (mud->state) | 1408 | switch (mud->state) |
1410 | { | 1409 | { |
1411 | case MBOX_NO_STATE: | 1410 | case MBOX_NO_STATE: |
1412 | if (locker_lock (mailbox->locker, MU_LOCKER_WRLOCK) != 0) | 1411 | if ((status = locker_lock (mailbox->locker)) != 0) |
1413 | { | 1412 | { |
1414 | MAILBOX_DEBUG0 (mailbox, MU_DEBUG_TRACE, | 1413 | MAILBOX_DEBUG1 (mailbox, MU_DEBUG_TRACE, |
1415 | "mbox_append_message:lock failed\n"); | 1414 | "mbox_append_message: %s\n", |
1416 | return ENOLCK; | 1415 | mu_errstring(status)); |
1416 | return status; | ||
1417 | } | 1417 | } |
1418 | 1418 | ||
1419 | default: | 1419 | default: | ... | ... |
... | @@ -574,7 +574,7 @@ mbox_scan0 (mailbox_t mailbox, size_t msgno, size_t *pcount, int do_notif) | ... | @@ -574,7 +574,7 @@ mbox_scan0 (mailbox_t mailbox, size_t msgno, size_t *pcount, int do_notif) |
574 | return status; | 574 | return status; |
575 | } | 575 | } |
576 | 576 | ||
577 | locker_lock (mailbox->locker, MU_LOCKER_RDLOCK); | 577 | locker_lock (mailbox->locker); |
578 | 578 | ||
579 | /* Seek to the starting point. */ | 579 | /* Seek to the starting point. */ |
580 | if (mud->umessages && msgno > 0 && mud->messages_count > 0 | 580 | if (mud->umessages && msgno > 0 && mud->messages_count > 0 | ... | ... |
... | @@ -271,10 +271,9 @@ mh_open (mailbox_t mailbox, int flags) | ... | @@ -271,10 +271,9 @@ mh_open (mailbox_t mailbox, int flags) |
271 | 271 | ||
272 | mhd->mtime = st.st_mtime; | 272 | mhd->mtime = st.st_mtime; |
273 | 273 | ||
274 | /* FIXME: something else? */ | 274 | /* FIXME: is this the right kind of locking for mh folders? */ |
275 | if (mailbox->locker == NULL) | 275 | if (mailbox->locker == NULL) |
276 | status = locker_create (&mailbox->locker, mhd->name, strlen (mhd->name), | 276 | status = locker_create (&mailbox->locker, mhd->name, 0); |
277 | MU_LOCKER_PID | MU_LOCKER_FCNTL); | ||
278 | return 0; | 277 | return 0; |
279 | } | 278 | } |
280 | 279 | ||
... | @@ -954,7 +953,7 @@ mh_scan0 (mailbox_t mailbox, size_t msgno, size_t *pcount) | ... | @@ -954,7 +953,7 @@ mh_scan0 (mailbox_t mailbox, size_t msgno, size_t *pcount) |
954 | pthread_cleanup_push (mh_cleanup, (void *)mailbox); | 953 | pthread_cleanup_push (mh_cleanup, (void *)mailbox); |
955 | #endif | 954 | #endif |
956 | 955 | ||
957 | locker_lock (mailbox->locker, MU_LOCKER_RDLOCK); | 956 | locker_lock (mailbox->locker); |
958 | 957 | ||
959 | /* Do actual work */ | 958 | /* Do actual work */ |
960 | while ((entry = readdir (dir))) | 959 | while ((entry = readdir (dir))) | ... | ... |
-
Please register or sign in to post a comment