/*
* 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
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <pkglocs.h>
#include <locale.h>
#include <libintl.h>
#include <string.h>
#include <signal.h>
#include <pkglib.h>
#include "libadm.h"
extern int errno;
#define ST_OK 0
"database."
"in %s state."
static unsigned int lock_state;
/*
* This function writes the PID, effective utility name, package name,
* current progress of the utility and the exit state to the lockfile in
* support of post mortem operations.
*/
static int
{
return (0);
return (1);
else
return (0);
}
/*
* This function reads the lockfile to obtain the PID and name of the lock
* holder. Upon those rare circumstances that an older version of pkgadd
* created the lock, this detects that zero-length file and provides the
* appropriate data. Since this data is only used if an actual lock (from
* lockf()) is detected, a manually created .lockfile will not result in a
* message.
*/
static void
{
lock_pid = 0;
sizeof (lock_name));
sizeof (lock_pkg));
sizeof (lock_place));
lock_state = ST_OK;
} else {
/* LINTED format argument contains unbounded string specifier */
}
}
static void
do_alarm(int n)
{
#ifdef lint
int i = n;
n = i;
#endif /* lint */
}
/*
* This establishes a locked status file for a pkgadd, pkgrm or swmtool - any
* of the complex package processes. Since numerous packages currently use
* installf and removef in preinstall scripts, we can't enforce a contents
* file write lock throughout the install process. In 2.7 we will enforce the
* write lock and allow this lock to serve as a simple information carrier
* which can be used by installf and removef too.
* Arguments:
* util_name - the name of the utility that is claiming the lock
* pkg_name - the package that is being locked (or "all package")
* place - a string of ascii characters that defines the initial "place" where
* the current operation is - this is updated by lockupd() and is a string
* is used fr post mortem operations if the utility should quit improperly.
* Returns (int):
* == 0 - failure
* != 0 - success
*/
int
{
/* assume "initial" if no "place" during processing specified */
place = "initial";
}
/* If the exit file is not present, create it. */
/* LINTED O_CREAT without O_EXCL specified in call to open() */
return (0);
}
lock_is_applied = 0;
/*
* This tries to create the lock LOCKRETRY times waiting LOCKWAIT
* seconds between retries.
*/
do {
/*
* Try to read the status of the last (or current)
* utility.
*/
rdlockdata(fd);
} else { /* This process has the lock. */
rdlockdata(fd);
if (lock_state != 0) {
}
lock_is_applied = 1;
break;
}
} while (retry_cnt--);
if (!lock_is_applied) {
return (0);
}
return (1);
}
/*
* This function updates the utility progress data in the lock file. It is
* used for post mortem operations if the utility should quit improperly.
*/
void
{
ST_QUIT);
}
/*
* This clears the governing lock and closes the lock file. If this was
* called already, it just returns.
*/
void
unlockinst(void)
{
if (lock_is_applied) {
"finished", ST_OK);
/*
* If close() fails, we can't be sure the lock has been
* removed, so we assume the worst in case this function is
* called again.
*/
lock_is_applied = 0;
}
}