/[mailutils]/mailutils/mailbox/locker.c
ViewVC logotype

Diff of /mailutils/mailbox/locker.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.12 by sroberts, Tue Mar 19 02:20:59 2002 UTC revision 1.13 by gray, Thu Mar 21 10:17:44 2002 UTC
# Line 97  locker_create (locker_t *plocker, const Line 97  locker_create (locker_t *plocker, const
97    l->dotlock = malloc(strlen(l->file) + 5 /*strlen(".lock")*/ + 1);    l->dotlock = malloc(strlen(l->file) + 5 /*strlen(".lock")*/ + 1);
98    
99    if(!l->dotlock)    if(!l->dotlock)
100    {      {
101      free(l->file);        free (l->file);
102      free(l);        free (l);
103      return ENOMEM;        return ENOMEM;
104    }      }
105    
106    sprintf(l->dotlock, "%s.lock", l->file);    sprintf(l->dotlock, "%s.lock", l->file);
107    
108    if (flags)    if (strcmp (filename, "/dev/null") == 0)
109        l->flags = MU_LOCKER_NULL;
110      else if (flags)
111      l->flags = flags;      l->flags = flags;
112    else    else
113      l->flags = MU_LOCKER_DEFAULT;      l->flags = MU_LOCKER_DEFAULT;
# Line 344  locker_lock (locker_t lock) Line 346  locker_lock (locker_t lock)
346    if (lock == NULL)    if (lock == NULL)
347      return EINVAL;      return EINVAL;
348    
349    INVARIANT (lock);    if (lock->flags == MU_LOCKER_NULL)
350        return 0;
351    /* Is the lock already applied? */    
352      INVARIANT (lock)
353        /* Is the lock already applied? */
354    if (lock->refcnt > 0)    if (lock->refcnt > 0)
355      {      {
356        assert (lock->fd != -1);        assert (lock->fd != -1);
# Line 511  locker_touchlock (locker_t lock) Line 515  locker_touchlock (locker_t lock)
515    if (!lock)    if (!lock)
516      return MU_ERR_LOCKER_NULL;      return MU_ERR_LOCKER_NULL;
517    
518      if (lock->flags == MU_LOCKER_NULL)
519        return 0;
520      
521    assert(lock->dotlock);    assert(lock->dotlock);
522    
523    INVARIANT(lock);    INVARIANT(lock);
# Line 524  locker_touchlock (locker_t lock) Line 531  locker_touchlock (locker_t lock)
531  int  int
532  locker_unlock (locker_t lock)  locker_unlock (locker_t lock)
533  {  {
534      if (!lock)
535        return MU_ERR_LOCKER_NULL;
536    
537      if (lock->flags == MU_LOCKER_NULL)
538        return 0;
539      
540    assert(lock->refcnt >= 0);    assert(lock->refcnt >= 0);
541    
542    if (!lock)    if (!lock)
# Line 549  locker_unlock (locker_t lock) Line 562  locker_unlock (locker_t lock)
562    
563    return 0;    return 0;
564  }  }
565    
566  int  int
567  locker_remove_lock (locker_t lock)  locker_remove_lock (locker_t lock)
568  {  {
# Line 557  locker_remove_lock (locker_t lock) Line 571  locker_remove_lock (locker_t lock)
571    if (!lock)    if (!lock)
572      return MU_ERR_LOCKER_NULL;      return MU_ERR_LOCKER_NULL;
573    
574      if (lock->flags == MU_LOCKER_NULL)
575        return 0;
576      
577    INVARIANT(lock);    INVARIANT(lock);
578    
579    /* If we hold the lock, do an unlock... */    /* If we hold the lock, do an unlock... */
580    if(lock->refcnt > 0)    if(lock->refcnt > 0)
581    {      {
582      /* Force the reference count to 1 to unlock the file. */        /* Force the reference count to 1 to unlock the file. */
583      lock->refcnt = 1;        lock->refcnt = 1;
584      return locker_unlock(lock);        return locker_unlock(lock);
585    }      }
586    
587    /* ... if we don't, unlink the lockfile. */    /* ... if we don't, unlink the lockfile. */
588    err = unlink (lock->dotlock);    err = unlink (lock->dotlock);
589    
590    if(err == -1)    if(err == -1)
591    {      {
592      err = errno;        err = errno;
593            
594      if(err == ENOENT)        if(err == ENOENT)
595        err = MU_ERR_LOCK_NOT_HELD;          err = MU_ERR_LOCK_NOT_HELD;
596    }      }
597    
598    INVARIANT(lock);    INVARIANT(lock);
599    

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.13

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26