process_buffer.c revision 458cf4d67cff5ff99a68a866b7657f1b1d6fe61c
/*
* 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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <strings.h>
#include <string.h>
#include <syslog.h>
#include <locale.h>
#include <stdio.h>
#include <errno.h>
#include <assert.h>
#include <stdlib.h>
#include <unistd.h>
#include "../lib/nfslog_config.h"
#include "buffer_list.h"
#include "nfslogd.h"
extern int _nfssys(int, void *);
/*
* simple list used to keep track of bad tag messages syslogged.
*/
struct nfs_log_list {
char *l_name;
struct nfs_log_list *l_next;
};
static void badtag_notify(char *tag);
static void cleanup_elf_state(nfsl_config_t *);
static void cleanup_trans_state(nfsl_config_t *);
/*
* Read the contents of the 'bufferpath', process them and store the
* user-readable log in 'elfpath', updating the 'fhpath' filehandle
* table.
* The contents of the configuration list (*config_list) may be
* modified if the configuration file has been updated and we can not
* find the configuration entry in the currently loaded list.
*
* Returns 0 on success and sets *buffer_processed to 1.
* non zero error on failure and *buffer_processed set to 0.
*/
int
struct buffer_ent *bep,
int min_size,
int idle_time,
int *buffer_processed)
{
struct nfsl_flush_args nfa;
char *buffer_inprog = NULL;
int buffer_inprog_len;
int error = 0;
char *tag;
error = 0;
if (buffer_inprog == NULL) {
"process_buffer: malloc failed"));
return (ENOMEM);
}
"Can not stat %s: %s"),
}
return (error);
}
/*
* Does the buffer in progress meet our minimum
* processing requirements? or has it been around
* longer than we're willing to wait for more
* data to be logged?
*/
/*
* The buffer does not meet the minimum
* size processing requirements, and it has not
* been around longer than we're willing to
* wait for more data collection.
* We return now without processing it.
*/
return (0);
}
/*
* Issue the LOG_FLUSH system call to flush the
* buffer and process it.
*/
"_nfssys(%s) failed: %s"),
}
return (error);
}
} else {
}
return (error);
}
}
/*
* Open and lock input buffer.
* Passes in the value of the last error so that it will not
* print it again if it is still hitting the same error condition.
*/
goto done;
if ((ncp = last_good_ncp =
"Could not search config list: %s"),
}
goto done;
}
if (*buffer_processed == 0)
(*buffer_processed)++;
/*
* Get the matching config entry.
*/
if (error) {
"Could not search config list: %s"),
}
goto done;
}
ncp = last_good_ncp;
goto skip;
}
last_good_ncp = ncp;
}
/*
* The location of the log files may have changed,
* we need to close transactions and invalidate
* cookies so that the log files can be reopened
* further down.
*/
/*
* Force cookies to be recreated if necessary.
*/
}
/*
* Open output files.
*/
/*
* Log rpc requests in W3C-ELF format.
*/
/*
* Make sure file still exists.
* Do this once per buffer.
*/
/*
* The open rpclogfile has been
* deleted. Get new one below.
*/
}
}
goto done;
}
}
}
/*
*/
/*
* Do this once per buffer.
*/
/*
* The open transaction file has been
* deleted. Close pending transaction
* work. A new transaction log will be
* opened by nfslog_open_trans_file()
* below.
*/
}
}
int transtolog;
transtolog, &error);
goto done;
}
}
}
/*
* Make sure there is room.
*/
}
(void) nfslog_process_trans_rec(
}
}
} /* while */
if (!error && keep_running) {
/*
* Keep track of when this buffer was last processed.
*/
if (test && *buffer_processed != 0) {
/*
* Save the buffer for future debugging. We do this
* by following the log cycling policy, with a maximum
* of 'max_logs_preserve' to save.
*/
"could not save copy of buffer \"%s\""),
}
} else {
/*
* Remove buffer since it has been processed.
*/
if (unlink(bufferpath)) {
"could not unlink %s: %s"),
/*
* Buffer was processed correctly.
*/
error = 0;
}
}
}
done:
if (ncp && !quick_cleaning)
return (error);
}
static void
{
}
}
static void
{
}
}
/*
* Searches the list of previously seen bad tags. Note that this
* list is never pruned. This should not be a problem since the
* list of bad tags should be fairl small. New entries are inserted
* at the beginning of the list assuming it will be accessed more
* frequently since we have just seen it.
*/
static void
badtag_notify(char *tag)
{
struct nfs_log_list *lp, *p;
int error;
/*
* We've seen this before, nothing to do.
*/
return;
}
}
/*
* Not on the list, add it.
*/
"ignoring records referencing such tag."),
badtag_list = lp;
return; /* done */
}
}
if (lp)
}