Skip to content

Commit 81d7ca3

Browse files
committed
Clean up potential subscription locking issues (Issue #1346)
1 parent 69550a0 commit 81d7ca3

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

scheduler/subscriptions.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ cupsdDeleteAllSubscriptions(void)
426426
for (sub = (cupsd_subscription_t *)cupsArrayFirst(Subscriptions);
427427
sub;
428428
sub = (cupsd_subscription_t *)cupsArrayNext(Subscriptions))
429-
cupsdDeleteSubscription(sub, 0);
429+
cupsdDeleteSubscription(sub, -1);
430430

431431
cupsArrayDelete(Subscriptions);
432432
Subscriptions = NULL;
@@ -442,7 +442,7 @@ cupsdDeleteAllSubscriptions(void)
442442
void
443443
cupsdDeleteSubscription(
444444
cupsd_subscription_t *sub, /* I - Subscription object */
445-
int update) /* I - 1 = update subscriptions.conf */
445+
int update) /* I - 1 = update subscriptions.conf, 0 = don't update, -1 = don't update and don't lock */
446446
{
447447
/*
448448
* Close the pipe to the notifier as needed...
@@ -455,11 +455,13 @@ cupsdDeleteSubscription(
455455
* Remove subscription from array...
456456
*/
457457

458-
_cupsRWLockWrite(&SubscriptionsLock);
458+
if (update >= 0)
459+
_cupsRWLockWrite(&SubscriptionsLock);
459460

460461
cupsArrayRemove(Subscriptions, sub);
461462

462-
_cupsRWUnlock(&SubscriptionsLock);
463+
if (update >= 0)
464+
_cupsRWUnlock(&SubscriptionsLock);
463465

464466
/*
465467
* Free memory...
@@ -478,7 +480,7 @@ cupsdDeleteSubscription(
478480
* Update the subscriptions as needed...
479481
*/
480482

481-
if (update)
483+
if (update > 0)
482484
cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS);
483485
}
484486

@@ -651,20 +653,26 @@ cupsdExpireSubscriptions(
651653

652654
cupsdLogMessage(CUPSD_LOG_DEBUG, "Expiring subscriptions...");
653655

656+
_cupsRWLockWrite(&SubscriptionsLock);
657+
654658
for (sub = (cupsd_subscription_t *)cupsArrayFirst(Subscriptions);
655659
sub;
656660
sub = (cupsd_subscription_t *)cupsArrayNext(Subscriptions))
661+
{
657662
if ((!sub->job && !dest && sub->expire && sub->expire <= curtime) ||
658663
(dest && sub->dest == dest) ||
659664
(job && sub->job == job))
660665
{
661666
cupsdLogMessage(CUPSD_LOG_INFO, "Subscription %d has expired...",
662667
sub->id);
663668

664-
cupsdDeleteSubscription(sub, 0);
669+
cupsdDeleteSubscription(sub, -1);
665670

666671
update = 1;
667672
}
673+
}
674+
675+
_cupsRWUnlock(&SubscriptionsLock);
668676

669677
if (update)
670678
cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS);

0 commit comments

Comments
 (0)