uucplock.c revision 94e1761e7fc32a474e3106beedc664ce987b96ec
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright (c) 1983 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* defs that come from uucp.h
*/
#define NAMESIZE 40
#define FAIL -1
#define SAME 0
#ifdef __STDC__
#define ASSERT(e, f, v) if (!(e)) {\
}
#else
#define ASSERT(e, f, v) if (!(e)) {\
}
#endif
#define LOCKPRE "LK"
/*
* This code is taken almost directly from uucp and follows the same
* conventions. This is important since uucp and tip should
* respect each others locks.
*/
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <utime.h>
static void stlock(char *);
static int onelock(char *, char *, char *);
static int checkLock(char *);
extern void finish(int);
/*
* ulockf(file, atime)
* char *file;
* time_t atime;
*
* ulockf - this routine will create a lock file (file).
* If one already exists, send a signal 0 to the process--if
* it fails, then unlink it and make a new one.
*
* input:
* file - name of the lock file
* atime - is unused, but we keep it for lint compatibility
* with non-ATTSVKILL
*
* return codes: 0 | FAIL
*/
/* ARGSUSED */
static int
{
if (pid[0] == '\0') {
(int)getpid());
}
/* lock file exists */
return (FAIL);
else {
return (FAIL);
}
}
}
return (0);
}
/*
* check to see if the lock file exists and is still active
* - use kill(pid, 0) - (this only works on ATTSV and some hacked
* BSD systems at this time)
* return:
* 0 -> success (lock file removed - no longer active)
* FAIL -> lock file still active
*/
static int
{
int ret;
int lpid = -1;
int fd;
if (fd == -1) {
return (0);
goto unlk;
}
goto unlk;
return (FAIL);
unlk:
return (FAIL);
return (0);
}
int Nlocks = 0;
/*
* stlock(name) put name in list of lock files
* char *name;
*
* return codes: none
*/
static void
{
char *p;
int i;
for (i = 0; i < Nlocks; i++) {
break;
}
if (i >= Nlocks)
i = Nlocks++;
Lockfile[i] = p;
}
/*
* rmlock(name) remove all lock files in list
* char *name; or name
*
* return codes: none
*/
static void
{
int i;
for (i = 0; i < Nlocks; i++) {
continue;
}
}
}
static int
{
int fd;
static int first = 1;
if (fd < 0) {
if (first) {
"tip: can't create files in lock file directory %s\n",
LOCKDIR);
"tip: lock file directory %s: ",
LOCKDIR);
perror("");
}
first = 0;
}
return (-1);
}
/* +1 for '\n' */
"tip: can't write to files in lock file directory %s: %s\n",
return (-1);
}
return (-1);
}
return (0);
}
/*
* delock(sys) remove a lock file
* char *sys;
*/
void
{
return;
}
/*
* tip_mlock(sys) create system lock
* char *sys;
*
* return codes: 0 | FAIL
*/
int
{
return (FAIL);
}