ftp.nice.ch/pub/next/unix/disk/vmount.0.6a.s.tar.gz#/vmount.0.6a.s/mtab_lock.c

This is mtab_lock.c in view mode; [Download] [Up]

/*
 * Name: mtab_lock.c
 * Description: Locking of mtab files
 * Author: Christian Starkjohann <cs@hal.kph.tuwien.ac.at>
 * Date: 1997-04-30
 * Copyright: GNU-GPL
 * Tabsize: 4
 */

#include <libc.h>
#include <errno.h>
#include <mntent.h>
#include "my_defines.h"

extern int	errno;

#define	MOUNTED_LOCK	(MOUNTED ".lock")

static int	lock = -1;

int		lock_mtab(void)
{
int		i;

	if(lock < 0){
		i = 0;
		while((lock = open(MOUNTED_LOCK, O_WRONLY|O_CREAT|O_EXCL, 0)) < 0){
			if(errno != EEXIST){
				return 0;
			}
			usleep(20000);	/* sleep for 100ms */
			if(i++ > 150)
				return 1;	/* wait for a maximum of about 3s */
		}
    }
	return 1;
}

void	unlock_mtab(void)
{
	if(lock >= -1){
		close(lock);
	}
	unlink(MOUNTED_LOCK);
}

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.