void
fail(const char *message)
{
	perror(message);
	exit(1);
}


static char *ooi_path;

void
ooi_unlink(void)
{
	unlink(ooi_path);
}


void
only_one_instance(void)
{
	struct flock fl;
	size_t dirlen;
	int fd;
	char *dir;

	
	dir = getenv();
	if (dir == NULL || dir[0] != '/') {
		fputs(, stderr);
		exit(1);
	}
	dirlen = strlen(dir);

	ooi_path = malloc(dirlen + sizeof( INSTANCE_LOCK));
	if (ooi_path == NULL)
		fail();
	memcpy(ooi_path, dir, dirlen);
	memcpy(ooi_path + dirlen,  INSTANCE_LOCK,
	    sizeof( INSTANCE_LOCK));  

	fd = open(ooi_path, O_RDWR | O_CREAT, 0600);
	if (fd < 0)
		fail(ooi_path);

	fl.l_start = 0;
	fl.l_len = 0;
	fl.l_type = F_WRLCK;
	fl.l_whence = SEEK_SET;
	if (fcntl(fd, F_SETLK, &fl) < 0) {
		fputs(,
		    stderr);
		exit(1);
	}

	
	atexit(ooi_unlink);
}


int
main()
{
	int i;

	only_one_instance();

	
	for(i = 10; i > 0; i--) {
		printf(, i, i % 5 == 1 ?  : );
		fflush(stdout);
		sleep(1);
	}
	puts();
	return 0;
}