Do not try to lock "/dev/null" mailboxes. These are used in several
programs (namely, comsat, imap4d, pop3d).
Showing
1 changed file
with
36 additions
and
19 deletions
... | @@ -97,15 +97,17 @@ locker_create (locker_t *plocker, const char *filename, int flags) | ... | @@ -97,15 +97,17 @@ locker_create (locker_t *plocker, const char *filename, int flags) |
97 | l->dotlock = malloc(strlen(l->file) + 5 /*strlen(".lock")*/ + 1); | 97 | l->dotlock = malloc(strlen(l->file) + 5 /*strlen(".lock")*/ + 1); |
98 | 98 | ||
99 | if(!l->dotlock) | 99 | if(!l->dotlock) |
100 | { | 100 | { |
101 | free(l->file); | 101 | free (l->file); |
102 | free(l); | 102 | free (l); |
103 | return ENOMEM; | 103 | return ENOMEM; |
104 | } | 104 | } |
105 | 105 | ||
106 | sprintf(l->dotlock, "%s.lock", l->file); | 106 | sprintf(l->dotlock, "%s.lock", l->file); |
107 | 107 | ||
108 | if (flags) | 108 | if (strcmp (filename, "/dev/null") == 0) |
109 | l->flags = MU_LOCKER_NULL; | ||
110 | else if (flags) | ||
109 | l->flags = flags; | 111 | l->flags = flags; |
110 | else | 112 | else |
111 | l->flags = MU_LOCKER_DEFAULT; | 113 | l->flags = MU_LOCKER_DEFAULT; |
... | @@ -344,9 +346,11 @@ locker_lock (locker_t lock) | ... | @@ -344,9 +346,11 @@ locker_lock (locker_t lock) |
344 | if (lock == NULL) | 346 | if (lock == NULL) |
345 | return EINVAL; | 347 | return EINVAL; |
346 | 348 | ||
347 | INVARIANT (lock); | 349 | if (lock->flags == MU_LOCKER_NULL) |
348 | 350 | return 0; | |
349 | /* Is the lock already applied? */ | 351 | |
352 | INVARIANT (lock) | ||
353 | /* Is the lock already applied? */ | ||
350 | if (lock->refcnt > 0) | 354 | if (lock->refcnt > 0) |
351 | { | 355 | { |
352 | assert (lock->fd != -1); | 356 | assert (lock->fd != -1); |
... | @@ -511,6 +515,9 @@ locker_touchlock (locker_t lock) | ... | @@ -511,6 +515,9 @@ locker_touchlock (locker_t lock) |
511 | if (!lock) | 515 | if (!lock) |
512 | return MU_ERR_LOCKER_NULL; | 516 | return MU_ERR_LOCKER_NULL; |
513 | 517 | ||
518 | if (lock->flags == MU_LOCKER_NULL) | ||
519 | return 0; | ||
520 | |||
514 | assert(lock->dotlock); | 521 | assert(lock->dotlock); |
515 | 522 | ||
516 | INVARIANT(lock); | 523 | INVARIANT(lock); |
... | @@ -524,6 +531,12 @@ locker_touchlock (locker_t lock) | ... | @@ -524,6 +531,12 @@ locker_touchlock (locker_t lock) |
524 | int | 531 | int |
525 | locker_unlock (locker_t lock) | 532 | locker_unlock (locker_t lock) |
526 | { | 533 | { |
534 | if (!lock) | ||
535 | return MU_ERR_LOCKER_NULL; | ||
536 | |||
537 | if (lock->flags == MU_LOCKER_NULL) | ||
538 | return 0; | ||
539 | |||
527 | assert(lock->refcnt >= 0); | 540 | assert(lock->refcnt >= 0); |
528 | 541 | ||
529 | if (!lock) | 542 | if (!lock) |
... | @@ -549,6 +562,7 @@ locker_unlock (locker_t lock) | ... | @@ -549,6 +562,7 @@ locker_unlock (locker_t lock) |
549 | 562 | ||
550 | return 0; | 563 | return 0; |
551 | } | 564 | } |
565 | |||
552 | int | 566 | int |
553 | locker_remove_lock (locker_t lock) | 567 | locker_remove_lock (locker_t lock) |
554 | { | 568 | { |
... | @@ -557,26 +571,29 @@ locker_remove_lock (locker_t lock) | ... | @@ -557,26 +571,29 @@ locker_remove_lock (locker_t lock) |
557 | if (!lock) | 571 | if (!lock) |
558 | return MU_ERR_LOCKER_NULL; | 572 | return MU_ERR_LOCKER_NULL; |
559 | 573 | ||
574 | if (lock->flags == MU_LOCKER_NULL) | ||
575 | return 0; | ||
576 | |||
560 | INVARIANT(lock); | 577 | INVARIANT(lock); |
561 | 578 | ||
562 | /* If we hold the lock, do an unlock... */ | 579 | /* If we hold the lock, do an unlock... */ |
563 | if(lock->refcnt > 0) | 580 | if(lock->refcnt > 0) |
564 | { | 581 | { |
565 | /* Force the reference count to 1 to unlock the file. */ | 582 | /* Force the reference count to 1 to unlock the file. */ |
566 | lock->refcnt = 1; | 583 | lock->refcnt = 1; |
567 | return locker_unlock(lock); | 584 | return locker_unlock(lock); |
568 | } | 585 | } |
569 | 586 | ||
570 | /* ... if we don't, unlink the lockfile. */ | 587 | /* ... if we don't, unlink the lockfile. */ |
571 | err = unlink (lock->dotlock); | 588 | err = unlink (lock->dotlock); |
572 | 589 | ||
573 | if(err == -1) | 590 | if(err == -1) |
574 | { | 591 | { |
575 | err = errno; | 592 | err = errno; |
576 | 593 | ||
577 | if(err == ENOENT) | 594 | if(err == ENOENT) |
578 | err = MU_ERR_LOCK_NOT_HELD; | 595 | err = MU_ERR_LOCK_NOT_HELD; |
579 | } | 596 | } |
580 | 597 | ||
581 | INVARIANT(lock); | 598 | INVARIANT(lock); |
582 | 599 | ... | ... |
-
Please register or sign in to post a comment