Skip to content

Commit 6d15d8e

Browse files
committed
Clean up potential subscription locking issues (Issue #1346)
1 parent 67de098 commit 6d15d8e

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
@@ -427,7 +427,7 @@ cupsdDeleteAllSubscriptions(void)
427427
for (sub = (cupsd_subscription_t *)cupsArrayFirst(Subscriptions);
428428
sub;
429429
sub = (cupsd_subscription_t *)cupsArrayNext(Subscriptions))
430-
cupsdDeleteSubscription(sub, 0);
430+
cupsdDeleteSubscription(sub, -1);
431431

432432
cupsArrayDelete(Subscriptions);
433433
Subscriptions = NULL;
@@ -443,7 +443,7 @@ cupsdDeleteAllSubscriptions(void)
443443
void
444444
cupsdDeleteSubscription(
445445
cupsd_subscription_t *sub, /* I - Subscription object */
446-
int update) /* I - 1 = update subscriptions.conf */
446+
int update) /* I - 1 = update subscriptions.conf, 0 = don't update, -1 = don't update and don't lock */
447447
{
448448
/*
449449
* Close the pipe to the notifier as needed...
@@ -456,11 +456,13 @@ cupsdDeleteSubscription(
456456
* Remove subscription from array...
457457
*/
458458

459-
cupsRWLockWrite(&SubscriptionsLock);
459+
if (update >= 0)
460+
cupsRWLockWrite(&SubscriptionsLock);
460461

461462
cupsArrayRemove(Subscriptions, sub);
462463

463-
cupsRWUnlock(&SubscriptionsLock);
464+
if (update >= 0)
465+
cupsRWUnlock(&SubscriptionsLock);
464466

465467
/*
466468
* Free memory...
@@ -479,7 +481,7 @@ cupsdDeleteSubscription(
479481
* Update the subscriptions as needed...
480482
*/
481483

482-
if (update)
484+
if (update > 0)
483485
cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS);
484486
}
485487

@@ -652,20 +654,26 @@ cupsdExpireSubscriptions(
652654

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

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

665-
cupsdDeleteSubscription(sub, 0);
670+
cupsdDeleteSubscription(sub, -1);
666671

667672
update = 1;
668673
}
674+
}
675+
676+
cupsRWUnlock(&SubscriptionsLock);
669677

670678
if (update)
671679
cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS);

0 commit comments

Comments
 (0)