/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
#include "mt.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <wait.h>
#include <fcntl.h>
#include <thread.h>
#include <unistd.h>
#include <errno.h>
#include <ucontext.h>
#include <syslog.h>
#include <rpcsvc/daemon_utils.h>
static int open_daemon_lock(const char *, int);
/*
* Use an advisory lock to ensure that only one daemon process is
* active in the system at any point in time. If the lock is held
* by another process, do not block but return the pid owner of
* the lock to the caller immediately. The lock is cleared if the
* holding daemon process exits for any reason even if the lock
* file remains, so the daemon can be restarted if necessary.
*/
/*
* check if another process is holding lock on the lock file.
*
* return: 0 if file is not locked, else,
* 1 if file is locked by another process, else,
* -1 on any error.
*/
int
{
return (0);
return (-1);
}
if (err == -1)
return (-1);
}
static int
{
int fd;
char *p;
/*
* Our args look like this:
* We want to create a lock file named like this:
* i.e., we want the last two path components in the name.
*/
/* First, strip off ":<instance>", if present. */
if (p != NULL)
*p = '\0';
/* Next, find final '/' and replace it with a dash */
if (p == NULL)
p = buf;
else {
*p = '-';
/* Now find the start of what we want our name to be */
if (p == NULL)
p = buf;
else
p++;
}
return (-1);
return (fd);
}
/*
* lock the file, write caller's pid to the lock file
* return: 0 if caller can establish lock, else,
* pid of the current lock holder, else,
* -1 on any printable error.
*/
{
int fd;
return ((pid_t)-1);
return ((pid_t)-1);
}
}
return ((pid_t)-1);
}
return ((pid_t)0);
}
int
{
int ret;
if (fd < 0)
return (-1);
return (ret);
}