17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*458cf4d6Sek110237 * Common Development and Distribution License (the "License"). 6*458cf4d6Sek110237 * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*458cf4d6Sek110237 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 23*458cf4d6Sek110237 * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate #include <strings.h> 297c478bd9Sstevel@tonic-gate #include <string.h> 307c478bd9Sstevel@tonic-gate #include <syslog.h> 317c478bd9Sstevel@tonic-gate #include <locale.h> 327c478bd9Sstevel@tonic-gate #include <nfs/nfs.h> 337c478bd9Sstevel@tonic-gate #include <nfs/export.h> 347c478bd9Sstevel@tonic-gate #include <nfs/nfssys.h> 357c478bd9Sstevel@tonic-gate #include <nfs/nfs_log.h> 367c478bd9Sstevel@tonic-gate #include <sys/types.h> 377c478bd9Sstevel@tonic-gate #include <sys/stat.h> 387c478bd9Sstevel@tonic-gate #include <stdio.h> 397c478bd9Sstevel@tonic-gate #include <errno.h> 407c478bd9Sstevel@tonic-gate #include <assert.h> 417c478bd9Sstevel@tonic-gate #include <stdlib.h> 427c478bd9Sstevel@tonic-gate #include <unistd.h> 437c478bd9Sstevel@tonic-gate #include <nfs/nfs_log.h> 447c478bd9Sstevel@tonic-gate #include "../lib/nfslog_config.h" 457c478bd9Sstevel@tonic-gate #include "buffer_list.h" 467c478bd9Sstevel@tonic-gate #include "nfslogd.h" 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate extern int _nfssys(int, void *); 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate /* 517c478bd9Sstevel@tonic-gate * simple list used to keep track of bad tag messages syslogged. 527c478bd9Sstevel@tonic-gate */ 53*458cf4d6Sek110237 struct nfs_log_list { 547c478bd9Sstevel@tonic-gate char *l_name; 55*458cf4d6Sek110237 struct nfs_log_list *l_next; 567c478bd9Sstevel@tonic-gate }; 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate static void badtag_notify(char *tag); 59*458cf4d6Sek110237 static struct nfs_log_list *badtag_list = NULL; 607c478bd9Sstevel@tonic-gate 617c478bd9Sstevel@tonic-gate static void cleanup_elf_state(nfsl_config_t *); 627c478bd9Sstevel@tonic-gate static void cleanup_trans_state(nfsl_config_t *); 637c478bd9Sstevel@tonic-gate 647c478bd9Sstevel@tonic-gate /* 657c478bd9Sstevel@tonic-gate * Read the contents of the 'bufferpath', process them and store the 667c478bd9Sstevel@tonic-gate * user-readable log in 'elfpath', updating the 'fhpath' filehandle 677c478bd9Sstevel@tonic-gate * table. 687c478bd9Sstevel@tonic-gate * The contents of the configuration list (*config_list) may be 697c478bd9Sstevel@tonic-gate * modified if the configuration file has been updated and we can not 707c478bd9Sstevel@tonic-gate * find the configuration entry in the currently loaded list. 717c478bd9Sstevel@tonic-gate * 727c478bd9Sstevel@tonic-gate * Returns 0 on success and sets *buffer_processed to 1. 737c478bd9Sstevel@tonic-gate * non zero error on failure and *buffer_processed set to 0. 747c478bd9Sstevel@tonic-gate */ 757c478bd9Sstevel@tonic-gate int 767c478bd9Sstevel@tonic-gate process_buffer( 777c478bd9Sstevel@tonic-gate struct buffer_ent *bep, 787c478bd9Sstevel@tonic-gate nfsl_config_t **config_list, 797c478bd9Sstevel@tonic-gate int min_size, 807c478bd9Sstevel@tonic-gate int idle_time, 817c478bd9Sstevel@tonic-gate int *buffer_processed) 827c478bd9Sstevel@tonic-gate { 837c478bd9Sstevel@tonic-gate struct stat st; 847c478bd9Sstevel@tonic-gate struct nfsl_flush_args nfa; 857c478bd9Sstevel@tonic-gate struct nfslog_buf *lbp = NULL; 867c478bd9Sstevel@tonic-gate struct nfslog_lr *lrp; 877c478bd9Sstevel@tonic-gate char *path1 = NULL; 887c478bd9Sstevel@tonic-gate char *path2 = NULL; 897c478bd9Sstevel@tonic-gate char *buffer_inprog = NULL; 907c478bd9Sstevel@tonic-gate int buffer_inprog_len; 917c478bd9Sstevel@tonic-gate int error = 0; 927c478bd9Sstevel@tonic-gate nfsl_config_t *ncp = NULL, *last_good_ncp; 937c478bd9Sstevel@tonic-gate char *bufferpath = bep->be_name; 947c478bd9Sstevel@tonic-gate char *tag; 957c478bd9Sstevel@tonic-gate boolean_t elf_checked = B_FALSE; 967c478bd9Sstevel@tonic-gate boolean_t trans_checked = B_FALSE; 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate assert(buffer_processed != NULL); 997c478bd9Sstevel@tonic-gate assert(bufferpath != NULL); 1007c478bd9Sstevel@tonic-gate 1017c478bd9Sstevel@tonic-gate if (stat(bufferpath, &st) == -1) { 1027c478bd9Sstevel@tonic-gate error = errno; 1037c478bd9Sstevel@tonic-gate if (error == ENOENT) { 1047c478bd9Sstevel@tonic-gate error = 0; 1057c478bd9Sstevel@tonic-gate buffer_inprog_len = strlen(bufferpath) + 1067c478bd9Sstevel@tonic-gate strlen(LOG_INPROG_STRING) + 1; 1077c478bd9Sstevel@tonic-gate buffer_inprog = (char *)malloc(buffer_inprog_len); 1087c478bd9Sstevel@tonic-gate if (buffer_inprog == NULL) { 1097c478bd9Sstevel@tonic-gate syslog(LOG_ERR, gettext( 1107c478bd9Sstevel@tonic-gate "process_buffer: malloc failed")); 1117c478bd9Sstevel@tonic-gate return (ENOMEM); 1127c478bd9Sstevel@tonic-gate } 1137c478bd9Sstevel@tonic-gate (void) sprintf(buffer_inprog, "%s%s", bufferpath, 1147c478bd9Sstevel@tonic-gate LOG_INPROG_STRING); 1157c478bd9Sstevel@tonic-gate 1167c478bd9Sstevel@tonic-gate if (stat(buffer_inprog, &st) == -1) { 1177c478bd9Sstevel@tonic-gate error = errno; 1187c478bd9Sstevel@tonic-gate if (bep->be_error != error) { 1197c478bd9Sstevel@tonic-gate syslog(LOG_ERR, gettext( 1207c478bd9Sstevel@tonic-gate "Can not stat %s: %s"), 1217c478bd9Sstevel@tonic-gate buffer_inprog, strerror(error)); 1227c478bd9Sstevel@tonic-gate } 1237c478bd9Sstevel@tonic-gate free(buffer_inprog); 1247c478bd9Sstevel@tonic-gate return (error); 1257c478bd9Sstevel@tonic-gate } 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate free(buffer_inprog); 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate /* 1307c478bd9Sstevel@tonic-gate * Does the buffer in progress meet our minimum 1317c478bd9Sstevel@tonic-gate * processing requirements? or has it been around 1327c478bd9Sstevel@tonic-gate * longer than we're willing to wait for more 1337c478bd9Sstevel@tonic-gate * data to be logged? 1347c478bd9Sstevel@tonic-gate */ 1357c478bd9Sstevel@tonic-gate if ((st.st_size < min_size) && 1367c478bd9Sstevel@tonic-gate ((time(0) - bep->be_lastprocessed) < idle_time)) { 1377c478bd9Sstevel@tonic-gate /* 1387c478bd9Sstevel@tonic-gate * The buffer does not meet the minimum 1397c478bd9Sstevel@tonic-gate * size processing requirements, and it has not 1407c478bd9Sstevel@tonic-gate * been around longer than we're willing to 1417c478bd9Sstevel@tonic-gate * wait for more data collection. 1427c478bd9Sstevel@tonic-gate * We return now without processing it. 1437c478bd9Sstevel@tonic-gate */ 1447c478bd9Sstevel@tonic-gate return (0); 1457c478bd9Sstevel@tonic-gate } 1467c478bd9Sstevel@tonic-gate 1477c478bd9Sstevel@tonic-gate /* 1487c478bd9Sstevel@tonic-gate * Issue the LOG_FLUSH system call to flush the 1497c478bd9Sstevel@tonic-gate * buffer and process it. 1507c478bd9Sstevel@tonic-gate */ 1517c478bd9Sstevel@tonic-gate (void) memset((void *)&nfa, 0, sizeof (nfa)); 1527c478bd9Sstevel@tonic-gate nfa.version = NFSL_FLUSH_ARGS_VERS; 1537c478bd9Sstevel@tonic-gate nfa.directive = NFSL_RENAME | NFSL_SYNC; 1547c478bd9Sstevel@tonic-gate nfa.buff = bufferpath; 1557c478bd9Sstevel@tonic-gate nfa.buff_len = strlen(bufferpath) + 1; 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate if (_nfssys(LOG_FLUSH, &nfa) < 0) { 1587c478bd9Sstevel@tonic-gate error = errno; 1597c478bd9Sstevel@tonic-gate if (bep->be_error != error) { 1607c478bd9Sstevel@tonic-gate syslog(LOG_ERR, gettext( 1617c478bd9Sstevel@tonic-gate "_nfssys(%s) failed: %s"), 1627c478bd9Sstevel@tonic-gate nfa.buff, strerror(error)); 1637c478bd9Sstevel@tonic-gate } 1647c478bd9Sstevel@tonic-gate return (error); 1657c478bd9Sstevel@tonic-gate } 1667c478bd9Sstevel@tonic-gate } else { 1677c478bd9Sstevel@tonic-gate if (bep->be_error != error) { 1687c478bd9Sstevel@tonic-gate syslog(LOG_ERR, gettext("Can not stat %s: %s"), 1697c478bd9Sstevel@tonic-gate bufferpath, strerror(error)); 1707c478bd9Sstevel@tonic-gate } 1717c478bd9Sstevel@tonic-gate return (error); 1727c478bd9Sstevel@tonic-gate } 1737c478bd9Sstevel@tonic-gate } 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gate /* 1767c478bd9Sstevel@tonic-gate * Open and lock input buffer. 1777c478bd9Sstevel@tonic-gate * Passes in the value of the last error so that it will not 1787c478bd9Sstevel@tonic-gate * print it again if it is still hitting the same error condition. 1797c478bd9Sstevel@tonic-gate */ 1807c478bd9Sstevel@tonic-gate error = bep->be_error; 1817c478bd9Sstevel@tonic-gate if ((lbp = nfslog_open_buf(bufferpath, &error)) == NULL) 1827c478bd9Sstevel@tonic-gate goto done; 1837c478bd9Sstevel@tonic-gate 1847c478bd9Sstevel@tonic-gate if ((ncp = last_good_ncp = 1857c478bd9Sstevel@tonic-gate nfsl_findconfig(*config_list, "global", &error)) == NULL) { 1867c478bd9Sstevel@tonic-gate assert(error != 0); 1877c478bd9Sstevel@tonic-gate nfsl_freeconfig_list(config_list); 1887c478bd9Sstevel@tonic-gate if (error != bep->be_error) { 1897c478bd9Sstevel@tonic-gate syslog(LOG_ERR, gettext( 1907c478bd9Sstevel@tonic-gate "Could not search config list: %s"), 1917c478bd9Sstevel@tonic-gate strerror(error)); 1927c478bd9Sstevel@tonic-gate } 1937c478bd9Sstevel@tonic-gate goto done; 1947c478bd9Sstevel@tonic-gate } 1957c478bd9Sstevel@tonic-gate 1967c478bd9Sstevel@tonic-gate assert(error == 0); 1977c478bd9Sstevel@tonic-gate while ((lrp = nfslog_get_logrecord(lbp)) != NULL && keep_running) { 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate if (*buffer_processed == 0) 2007c478bd9Sstevel@tonic-gate (*buffer_processed)++; 2017c478bd9Sstevel@tonic-gate 2027c478bd9Sstevel@tonic-gate /* 2037c478bd9Sstevel@tonic-gate * Get the matching config entry. 2047c478bd9Sstevel@tonic-gate */ 2057c478bd9Sstevel@tonic-gate tag = lrp->log_record.re_tag; 2067c478bd9Sstevel@tonic-gate if (strcmp(tag, last_good_ncp->nc_name) != 0) { 2077c478bd9Sstevel@tonic-gate ncp = nfsl_findconfig(*config_list, tag, &error); 2087c478bd9Sstevel@tonic-gate if (error) { 2097c478bd9Sstevel@tonic-gate if (error != bep->be_error) { 2107c478bd9Sstevel@tonic-gate syslog(LOG_ERR, gettext( 2117c478bd9Sstevel@tonic-gate "Could not search config list: %s"), 2127c478bd9Sstevel@tonic-gate strerror(error)); 2137c478bd9Sstevel@tonic-gate } 2147c478bd9Sstevel@tonic-gate nfsl_freeconfig_list(config_list); 2157c478bd9Sstevel@tonic-gate goto done; 2167c478bd9Sstevel@tonic-gate } 2177c478bd9Sstevel@tonic-gate if (ncp == NULL) { 2187c478bd9Sstevel@tonic-gate badtag_notify(tag); 2197c478bd9Sstevel@tonic-gate ncp = last_good_ncp; 2207c478bd9Sstevel@tonic-gate goto skip; 2217c478bd9Sstevel@tonic-gate } 2227c478bd9Sstevel@tonic-gate last_good_ncp = ncp; 2237c478bd9Sstevel@tonic-gate } 2247c478bd9Sstevel@tonic-gate 2257c478bd9Sstevel@tonic-gate if (ncp->nc_flags & NC_UPDATED) { 2267c478bd9Sstevel@tonic-gate /* 2277c478bd9Sstevel@tonic-gate * The location of the log files may have changed, 2287c478bd9Sstevel@tonic-gate * we need to close transactions and invalidate 2297c478bd9Sstevel@tonic-gate * cookies so that the log files can be reopened 2307c478bd9Sstevel@tonic-gate * further down. 2317c478bd9Sstevel@tonic-gate */ 2327c478bd9Sstevel@tonic-gate cleanup_elf_state(ncp); 2337c478bd9Sstevel@tonic-gate cleanup_trans_state(ncp); 2347c478bd9Sstevel@tonic-gate 2357c478bd9Sstevel@tonic-gate ncp->nc_flags &= ~NC_UPDATED; 2367c478bd9Sstevel@tonic-gate 2377c478bd9Sstevel@tonic-gate /* 2387c478bd9Sstevel@tonic-gate * Force cookies to be recreated if necessary. 2397c478bd9Sstevel@tonic-gate */ 2407c478bd9Sstevel@tonic-gate elf_checked = trans_checked = B_FALSE; 2417c478bd9Sstevel@tonic-gate } 2427c478bd9Sstevel@tonic-gate 2437c478bd9Sstevel@tonic-gate /* 2447c478bd9Sstevel@tonic-gate * Open output files. 2457c478bd9Sstevel@tonic-gate */ 2467c478bd9Sstevel@tonic-gate if (ncp->nc_rpclogpath != NULL) { 2477c478bd9Sstevel@tonic-gate /* 2487c478bd9Sstevel@tonic-gate * Log rpc requests in W3C-ELF format. 2497c478bd9Sstevel@tonic-gate */ 2507c478bd9Sstevel@tonic-gate if (!elf_checked && ncp->nc_elfcookie != NULL) { 2517c478bd9Sstevel@tonic-gate /* 2527c478bd9Sstevel@tonic-gate * Make sure file still exists. 2537c478bd9Sstevel@tonic-gate * Do this once per buffer. 2547c478bd9Sstevel@tonic-gate */ 2557c478bd9Sstevel@tonic-gate if (stat(ncp->nc_rpclogpath, &st) == -1 && 2567c478bd9Sstevel@tonic-gate errno == ENOENT) { 2577c478bd9Sstevel@tonic-gate /* 2587c478bd9Sstevel@tonic-gate * The open rpclogfile has been 2597c478bd9Sstevel@tonic-gate * deleted. Get new one below. 2607c478bd9Sstevel@tonic-gate */ 2617c478bd9Sstevel@tonic-gate cleanup_elf_state(ncp); 2627c478bd9Sstevel@tonic-gate } 2637c478bd9Sstevel@tonic-gate elf_checked = B_TRUE; 2647c478bd9Sstevel@tonic-gate } 2657c478bd9Sstevel@tonic-gate if (ncp->nc_elfcookie == NULL) { 2667c478bd9Sstevel@tonic-gate error = bep->be_error; 2677c478bd9Sstevel@tonic-gate ncp->nc_elfcookie = nfslog_open_elf_file( 268*458cf4d6Sek110237 ncp->nc_rpclogpath, &lbp->bh, &error); 2697c478bd9Sstevel@tonic-gate if (ncp->nc_elfcookie == NULL) { 2707c478bd9Sstevel@tonic-gate bep->be_error = error; 2717c478bd9Sstevel@tonic-gate goto done; 2727c478bd9Sstevel@tonic-gate } 2737c478bd9Sstevel@tonic-gate } 2747c478bd9Sstevel@tonic-gate } 2757c478bd9Sstevel@tonic-gate 2767c478bd9Sstevel@tonic-gate if (ncp->nc_logpath != NULL) { 2777c478bd9Sstevel@tonic-gate /* 2787c478bd9Sstevel@tonic-gate * Log rpc reqs in trans/ftp format. 2797c478bd9Sstevel@tonic-gate */ 2807c478bd9Sstevel@tonic-gate if (!trans_checked && ncp->nc_transcookie != NULL) { 2817c478bd9Sstevel@tonic-gate /* 2827c478bd9Sstevel@tonic-gate * Do this once per buffer. 2837c478bd9Sstevel@tonic-gate */ 2847c478bd9Sstevel@tonic-gate if (stat(ncp->nc_logpath, &st) == -1 && 2857c478bd9Sstevel@tonic-gate errno == ENOENT) { 2867c478bd9Sstevel@tonic-gate /* 2877c478bd9Sstevel@tonic-gate * The open transaction file has been 2887c478bd9Sstevel@tonic-gate * deleted. Close pending transaction 2897c478bd9Sstevel@tonic-gate * work. A new transaction log will be 2907c478bd9Sstevel@tonic-gate * opened by nfslog_open_trans_file() 2917c478bd9Sstevel@tonic-gate * below. 2927c478bd9Sstevel@tonic-gate */ 2937c478bd9Sstevel@tonic-gate cleanup_trans_state(ncp); 2947c478bd9Sstevel@tonic-gate } 2957c478bd9Sstevel@tonic-gate trans_checked = B_TRUE; 2967c478bd9Sstevel@tonic-gate } 2977c478bd9Sstevel@tonic-gate if (ncp->nc_transcookie == NULL) { 2987c478bd9Sstevel@tonic-gate int transtolog; 2997c478bd9Sstevel@tonic-gate 3007c478bd9Sstevel@tonic-gate transtolog = 3017c478bd9Sstevel@tonic-gate (ncp->nc_logformat == TRANSLOG_BASIC) ? 302*458cf4d6Sek110237 TRANSTOLOG_OPER_READWRITE : TRANSTOLOG_ALL; 3037c478bd9Sstevel@tonic-gate error = bep->be_error; 3047c478bd9Sstevel@tonic-gate ncp->nc_transcookie = nfslog_open_trans_file( 305*458cf4d6Sek110237 ncp->nc_logpath, ncp->nc_logformat, 3067c478bd9Sstevel@tonic-gate transtolog, &error); 3077c478bd9Sstevel@tonic-gate if (ncp->nc_transcookie == NULL) { 3087c478bd9Sstevel@tonic-gate bep->be_error = error; 3097c478bd9Sstevel@tonic-gate goto done; 3107c478bd9Sstevel@tonic-gate } 3117c478bd9Sstevel@tonic-gate } 3127c478bd9Sstevel@tonic-gate } 3137c478bd9Sstevel@tonic-gate 3147c478bd9Sstevel@tonic-gate assert(ncp->nc_fhpath != NULL); 3157c478bd9Sstevel@tonic-gate 3167c478bd9Sstevel@tonic-gate if (nfslog_process_fh_rec(lrp, ncp->nc_fhpath, &path1, &path2, 3177c478bd9Sstevel@tonic-gate ncp->nc_elfcookie != NULL)) { 3187c478bd9Sstevel@tonic-gate /* 3197c478bd9Sstevel@tonic-gate * Make sure there is room. 3207c478bd9Sstevel@tonic-gate */ 3217c478bd9Sstevel@tonic-gate if (ncp->nc_elfcookie != NULL) { 3227c478bd9Sstevel@tonic-gate (void) nfslog_process_elf_rec(ncp->nc_elfcookie, 3237c478bd9Sstevel@tonic-gate &lrp->log_record, path1, path2); 3247c478bd9Sstevel@tonic-gate } 3257c478bd9Sstevel@tonic-gate 3267c478bd9Sstevel@tonic-gate if (ncp->nc_transcookie != NULL) { 3277c478bd9Sstevel@tonic-gate (void) nfslog_process_trans_rec( 3287c478bd9Sstevel@tonic-gate ncp->nc_transcookie, 3297c478bd9Sstevel@tonic-gate &lrp->log_record, ncp->nc_fhpath, 3307c478bd9Sstevel@tonic-gate path1, path2); 3317c478bd9Sstevel@tonic-gate } 3327c478bd9Sstevel@tonic-gate } 3337c478bd9Sstevel@tonic-gate 3347c478bd9Sstevel@tonic-gate skip: if (path1 != NULL) 3357c478bd9Sstevel@tonic-gate free(path1); 3367c478bd9Sstevel@tonic-gate if (path2 != NULL) 3377c478bd9Sstevel@tonic-gate free(path2); 3387c478bd9Sstevel@tonic-gate 3397c478bd9Sstevel@tonic-gate path1 = path2 = NULL; 3407c478bd9Sstevel@tonic-gate nfslog_free_logrecord(lrp, TRUE); 3417c478bd9Sstevel@tonic-gate } /* while */ 3427c478bd9Sstevel@tonic-gate 3437c478bd9Sstevel@tonic-gate if (!error && keep_running) { 3447c478bd9Sstevel@tonic-gate /* 3457c478bd9Sstevel@tonic-gate * Keep track of when this buffer was last processed. 3467c478bd9Sstevel@tonic-gate */ 3477c478bd9Sstevel@tonic-gate bep->be_lastprocessed = time(0); 3487c478bd9Sstevel@tonic-gate 3497c478bd9Sstevel@tonic-gate if (test && *buffer_processed != 0) { 3507c478bd9Sstevel@tonic-gate /* 3517c478bd9Sstevel@tonic-gate * Save the buffer for future debugging. We do this 3527c478bd9Sstevel@tonic-gate * by following the log cycling policy, with a maximum 3537c478bd9Sstevel@tonic-gate * of 'max_logs_preserve' to save. 3547c478bd9Sstevel@tonic-gate */ 3557c478bd9Sstevel@tonic-gate if (cycle_log(bufferpath, max_logs_preserve)) { 3567c478bd9Sstevel@tonic-gate syslog(LOG_ERR, gettext( 3577c478bd9Sstevel@tonic-gate "could not save copy of buffer \"%s\""), 3587c478bd9Sstevel@tonic-gate bufferpath); 3597c478bd9Sstevel@tonic-gate } 3607c478bd9Sstevel@tonic-gate } else { 3617c478bd9Sstevel@tonic-gate /* 3627c478bd9Sstevel@tonic-gate * Remove buffer since it has been processed. 3637c478bd9Sstevel@tonic-gate */ 3647c478bd9Sstevel@tonic-gate if (unlink(bufferpath)) { 3657c478bd9Sstevel@tonic-gate error = errno; 3667c478bd9Sstevel@tonic-gate syslog(LOG_ERR, gettext( 3677c478bd9Sstevel@tonic-gate "could not unlink %s: %s"), 3687c478bd9Sstevel@tonic-gate bufferpath, strerror(error)); 3697c478bd9Sstevel@tonic-gate /* 3707c478bd9Sstevel@tonic-gate * Buffer was processed correctly. 3717c478bd9Sstevel@tonic-gate */ 3727c478bd9Sstevel@tonic-gate error = 0; 3737c478bd9Sstevel@tonic-gate } 3747c478bd9Sstevel@tonic-gate } 3757c478bd9Sstevel@tonic-gate } 3767c478bd9Sstevel@tonic-gate 3777c478bd9Sstevel@tonic-gate done: 3787c478bd9Sstevel@tonic-gate if (lbp != NULL) 3797c478bd9Sstevel@tonic-gate nfslog_close_buf(lbp, quick_cleaning); 3807c478bd9Sstevel@tonic-gate if (ncp && !quick_cleaning) 3817c478bd9Sstevel@tonic-gate cleanup_elf_state(ncp); 3827c478bd9Sstevel@tonic-gate 3837c478bd9Sstevel@tonic-gate return (error); 3847c478bd9Sstevel@tonic-gate } 3857c478bd9Sstevel@tonic-gate 3867c478bd9Sstevel@tonic-gate static void 3877c478bd9Sstevel@tonic-gate cleanup_elf_state(nfsl_config_t *ncp) 3887c478bd9Sstevel@tonic-gate { 3897c478bd9Sstevel@tonic-gate if (ncp->nc_elfcookie != NULL) { 3907c478bd9Sstevel@tonic-gate nfslog_close_elf_file(&ncp->nc_elfcookie); 3917c478bd9Sstevel@tonic-gate assert(ncp->nc_elfcookie == NULL); 3927c478bd9Sstevel@tonic-gate } 3937c478bd9Sstevel@tonic-gate } 3947c478bd9Sstevel@tonic-gate 3957c478bd9Sstevel@tonic-gate static void 3967c478bd9Sstevel@tonic-gate cleanup_trans_state(nfsl_config_t *ncp) 3977c478bd9Sstevel@tonic-gate { 3987c478bd9Sstevel@tonic-gate if (ncp->nc_transcookie != NULL) { 3997c478bd9Sstevel@tonic-gate nfslog_close_transactions(&ncp->nc_transcookie); 4007c478bd9Sstevel@tonic-gate assert(ncp->nc_transcookie == NULL); 4017c478bd9Sstevel@tonic-gate } 4027c478bd9Sstevel@tonic-gate } 4037c478bd9Sstevel@tonic-gate 4047c478bd9Sstevel@tonic-gate /* 4057c478bd9Sstevel@tonic-gate * Searches the list of previously seen bad tags. Note that this 4067c478bd9Sstevel@tonic-gate * list is never pruned. This should not be a problem since the 4077c478bd9Sstevel@tonic-gate * list of bad tags should be fairl small. New entries are inserted 4087c478bd9Sstevel@tonic-gate * at the beginning of the list assuming it will be accessed more 4097c478bd9Sstevel@tonic-gate * frequently since we have just seen it. 4107c478bd9Sstevel@tonic-gate */ 4117c478bd9Sstevel@tonic-gate static void 4127c478bd9Sstevel@tonic-gate badtag_notify(char *tag) 4137c478bd9Sstevel@tonic-gate { 414*458cf4d6Sek110237 struct nfs_log_list *lp, *p; 4157c478bd9Sstevel@tonic-gate int error; 4167c478bd9Sstevel@tonic-gate 4177c478bd9Sstevel@tonic-gate for (p = badtag_list; p != NULL; p = p->l_next) { 4187c478bd9Sstevel@tonic-gate if (strcmp(tag, p->l_name) == 0) { 4197c478bd9Sstevel@tonic-gate /* 4207c478bd9Sstevel@tonic-gate * We've seen this before, nothing to do. 4217c478bd9Sstevel@tonic-gate */ 4227c478bd9Sstevel@tonic-gate return; 4237c478bd9Sstevel@tonic-gate } 4247c478bd9Sstevel@tonic-gate } 4257c478bd9Sstevel@tonic-gate 4267c478bd9Sstevel@tonic-gate /* 4277c478bd9Sstevel@tonic-gate * Not on the list, add it. 4287c478bd9Sstevel@tonic-gate */ 429*458cf4d6Sek110237 syslog(LOG_ERR, gettext("tag \"%s\" not found in %s - " 4307c478bd9Sstevel@tonic-gate "ignoring records referencing such tag."), 4317c478bd9Sstevel@tonic-gate tag, NFSL_CONFIG_FILE_PATH); 4327c478bd9Sstevel@tonic-gate 433*458cf4d6Sek110237 if ((lp = (struct nfs_log_list *)malloc(sizeof (*lp))) != NULL) { 4347c478bd9Sstevel@tonic-gate if ((lp->l_name = strdup(tag)) != NULL) { 4357c478bd9Sstevel@tonic-gate lp->l_next = badtag_list; 4367c478bd9Sstevel@tonic-gate badtag_list = lp; 4377c478bd9Sstevel@tonic-gate return; /* done */ 4387c478bd9Sstevel@tonic-gate } 4397c478bd9Sstevel@tonic-gate } 4407c478bd9Sstevel@tonic-gate 4417c478bd9Sstevel@tonic-gate if (lp->l_name != NULL) 4427c478bd9Sstevel@tonic-gate free(lp->l_name); 4437c478bd9Sstevel@tonic-gate if (lp) 4447c478bd9Sstevel@tonic-gate free(lp); 4457c478bd9Sstevel@tonic-gate error = errno; 4467c478bd9Sstevel@tonic-gate syslog(LOG_ERR, gettext( 4477c478bd9Sstevel@tonic-gate "Cannot add \"%s\" to bad tag list: %s"), tag, strerror(error)); 4487c478bd9Sstevel@tonic-gate } 449