/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <errno.h>
#include <malloc.h>
#include <string.h>
#ifdef TDRPC
#include <sysent.h>
#endif
#include <unistd.h>
#include "db_headers.h"
#include "db_log.h"
#include "nisdb_mt.h"
static void
{
db_query *q;
if (lentry) {
delete q;
}
}
delete lentry;
}
}
/*
* Execute given function 'func' on log.
* function takes as arguments: pointer to log entry, character pointer to
* another argument, and pointer to an integer, which is used as a counter.
* 'func' should increment this value for each successful application.
* The log is traversed until either 'func' returns FALSE, or when the log
* is exhausted. The second argument to 'execute_on_log' is passed as the
* second argument to 'func'. The third argument, 'clean' determines whether
* the log entry is deleted after the function has been applied.
* Returns the number of times that 'func' incremented its third argument.
*/
int
{
db_log_entry *j;
int count = 0;
WRITELOCK(this, 0, "w db_log::execute_on_log");
while (!done) {
j = get();
if (j == NULL)
break;
if (clean) delete_log_entry(j);
}
sync_log();
close();
}
return (count);
}
static bool_t
{
j->print();
++ *count;
return (TRUE);
}
/* Print contents of log file to stdout */
int
{
}
/* Make copy of current log to log pointed to by 'f'. */
int
{
db_log_entry *j;
int l, ret = 0;
if ((l = acqnonexcl()) != 0) {
WRITEUNLOCK(f, l, "wu f db_log::copy");
return (l);
}
for (;;) {
j = get();
if (j == NULL)
break;
if (f->append(j) < 0) {
"db_log::copy: could not append to log file: ");
ret = -1;
break;
}
delete_log_entry(j);
}
if ((l = relnonexcl()) != 0) {
ret = l;
}
return (ret);
}
/* Rewinds current log */
int
{
}
/*
* Return the next element in current log; return NULL if end of log or error.
* Log must have been opened for READ.
*/
{
db_log_entry *j;
if (mode != PICKLE_READ) {
return (NULL);
}
j = new db_log_entry;
if (j == NULL) {
return (NULL);
}
delete_log_entry (j);
/* WARNING("Could not sucessfully finish reading log"); */
return (NULL);
}
if (! j->sane()) {
WARNING("truncated log entry found");
delete_log_entry(j);
j = NULL;
}
READUNLOCK(this, j, "ru db_log::get");
return (j);
}
/* Append given log entry to log. */
int
{
int status;
if (mode != PICKLE_APPEND) {
return (-1);
}
/* xdr returns TRUE if successful, FALSE otherwise */
if (status < 0) {
WARNING("db_log: could not write log entry");
} else {
syncstate++;
}
return (status);
}
int
return (0);
} else {
return (errno);
}
}
return (ret);
}
b = 0;
while (size > 0) {
if (w < 0) {
size == -1;
break;
}
size -= w;
b += w;
}
if (size != 0) {
break;
}
}
if (ret != 0) {
WARNING_M("db_log: error copying log file")
return (ret);
}
WARNING_M("db_log: error syncing log file");
}
return (ret);
}
/*
* Return value is expected to be the usual C convention of non-zero
* for success, 0 for failure.
*/
int
{
if (status < 0) {
WARNING("db_log: could not flush log entry to disk");
return (status);
}
if (status < 0) {
WARNING("db_log: could not sync log entry to disk");
} else if (tmplog != 0) {
if (syncstate == 0) {
/* Log already stable; nothing to do */
err = 0;
WARNING_M("db_log: could not mv stable log");
} else {
syncstate = 0;
}
} else {
WARNING_M("db_log: could not stabilize log");
}
} else {
/*
* Successful sync of file, but no tmplog to sync
* so we make sure we return 'success'.
*/
status = 1;
}
return (status);
}
int
int ret;
if (syncstate != 0) {
WARNING("db_log: closing unstable tmp log");
}
oldlog = 0;
}
if (tmplog != 0) {
delete tmplog;
tmplog = 0;
}
if (stablelog != 0) {
delete stablelog;
stablelog = 0;
}
return (ret);
}
return (ret);
}
if (tmplog == 0) {
WARNING("db_log: could not allocate tmp log name");
return (ret);
}
if (stablelog == 0) {
WARNING("db_log: could not allocate stable log name");
delete tmplog;
tmplog = 0;
return (ret);
}
} else {
"db_log: Error copying \"%s\" to \"%s\": %s",
delete tmplog;
tmplog = 0;
delete stablelog;
stablelog = 0;
}
return (ret);
}