10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*5006Sek110237 * Common Development and Distribution License (the "License").
6*5006Sek110237 * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*5006Sek110237 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23*5006Sek110237 * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
270Sstevel@tonic-gate
280Sstevel@tonic-gate #include <strings.h>
290Sstevel@tonic-gate #include <string.h>
300Sstevel@tonic-gate #include <syslog.h>
310Sstevel@tonic-gate #include <locale.h>
320Sstevel@tonic-gate #include <nfs/nfs.h>
330Sstevel@tonic-gate #include <nfs/export.h>
340Sstevel@tonic-gate #include <nfs/nfssys.h>
350Sstevel@tonic-gate #include <nfs/nfs_log.h>
360Sstevel@tonic-gate #include <sys/types.h>
370Sstevel@tonic-gate #include <sys/stat.h>
380Sstevel@tonic-gate #include <stdio.h>
390Sstevel@tonic-gate #include <errno.h>
400Sstevel@tonic-gate #include <assert.h>
410Sstevel@tonic-gate #include <stdlib.h>
420Sstevel@tonic-gate #include <unistd.h>
430Sstevel@tonic-gate #include <nfs/nfs_log.h>
440Sstevel@tonic-gate #include "../lib/nfslog_config.h"
450Sstevel@tonic-gate #include "buffer_list.h"
460Sstevel@tonic-gate #include "nfslogd.h"
470Sstevel@tonic-gate
480Sstevel@tonic-gate extern int _nfssys(int, void *);
490Sstevel@tonic-gate
500Sstevel@tonic-gate /*
510Sstevel@tonic-gate * simple list used to keep track of bad tag messages syslogged.
520Sstevel@tonic-gate */
53*5006Sek110237 struct nfs_log_list {
540Sstevel@tonic-gate char *l_name;
55*5006Sek110237 struct nfs_log_list *l_next;
560Sstevel@tonic-gate };
570Sstevel@tonic-gate
580Sstevel@tonic-gate static void badtag_notify(char *tag);
59*5006Sek110237 static struct nfs_log_list *badtag_list = NULL;
600Sstevel@tonic-gate
610Sstevel@tonic-gate static void cleanup_elf_state(nfsl_config_t *);
620Sstevel@tonic-gate static void cleanup_trans_state(nfsl_config_t *);
630Sstevel@tonic-gate
640Sstevel@tonic-gate /*
650Sstevel@tonic-gate * Read the contents of the 'bufferpath', process them and store the
660Sstevel@tonic-gate * user-readable log in 'elfpath', updating the 'fhpath' filehandle
670Sstevel@tonic-gate * table.
680Sstevel@tonic-gate * The contents of the configuration list (*config_list) may be
690Sstevel@tonic-gate * modified if the configuration file has been updated and we can not
700Sstevel@tonic-gate * find the configuration entry in the currently loaded list.
710Sstevel@tonic-gate *
720Sstevel@tonic-gate * Returns 0 on success and sets *buffer_processed to 1.
730Sstevel@tonic-gate * non zero error on failure and *buffer_processed set to 0.
740Sstevel@tonic-gate */
750Sstevel@tonic-gate int
process_buffer(struct buffer_ent * bep,nfsl_config_t ** config_list,int min_size,int idle_time,int * buffer_processed)760Sstevel@tonic-gate process_buffer(
770Sstevel@tonic-gate struct buffer_ent *bep,
780Sstevel@tonic-gate nfsl_config_t **config_list,
790Sstevel@tonic-gate int min_size,
800Sstevel@tonic-gate int idle_time,
810Sstevel@tonic-gate int *buffer_processed)
820Sstevel@tonic-gate {
830Sstevel@tonic-gate struct stat st;
840Sstevel@tonic-gate struct nfsl_flush_args nfa;
850Sstevel@tonic-gate struct nfslog_buf *lbp = NULL;
860Sstevel@tonic-gate struct nfslog_lr *lrp;
870Sstevel@tonic-gate char *path1 = NULL;
880Sstevel@tonic-gate char *path2 = NULL;
890Sstevel@tonic-gate char *buffer_inprog = NULL;
900Sstevel@tonic-gate int buffer_inprog_len;
910Sstevel@tonic-gate int error = 0;
920Sstevel@tonic-gate nfsl_config_t *ncp = NULL, *last_good_ncp;
930Sstevel@tonic-gate char *bufferpath = bep->be_name;
940Sstevel@tonic-gate char *tag;
950Sstevel@tonic-gate boolean_t elf_checked = B_FALSE;
960Sstevel@tonic-gate boolean_t trans_checked = B_FALSE;
970Sstevel@tonic-gate
980Sstevel@tonic-gate assert(buffer_processed != NULL);
990Sstevel@tonic-gate assert(bufferpath != NULL);
1000Sstevel@tonic-gate
1010Sstevel@tonic-gate if (stat(bufferpath, &st) == -1) {
1020Sstevel@tonic-gate error = errno;
1030Sstevel@tonic-gate if (error == ENOENT) {
1040Sstevel@tonic-gate error = 0;
1050Sstevel@tonic-gate buffer_inprog_len = strlen(bufferpath) +
106*5006Sek110237 strlen(LOG_INPROG_STRING) + 1;
1070Sstevel@tonic-gate buffer_inprog = (char *)malloc(buffer_inprog_len);
1080Sstevel@tonic-gate if (buffer_inprog == NULL) {
1090Sstevel@tonic-gate syslog(LOG_ERR, gettext(
110*5006Sek110237 "process_buffer: malloc failed"));
1110Sstevel@tonic-gate return (ENOMEM);
1120Sstevel@tonic-gate }
1130Sstevel@tonic-gate (void) sprintf(buffer_inprog, "%s%s", bufferpath,
114*5006Sek110237 LOG_INPROG_STRING);
1150Sstevel@tonic-gate
1160Sstevel@tonic-gate if (stat(buffer_inprog, &st) == -1) {
1170Sstevel@tonic-gate error = errno;
1180Sstevel@tonic-gate if (bep->be_error != error) {
1190Sstevel@tonic-gate syslog(LOG_ERR, gettext(
120*5006Sek110237 "Can not stat %s: %s"),
121*5006Sek110237 buffer_inprog, strerror(error));
1220Sstevel@tonic-gate }
1230Sstevel@tonic-gate free(buffer_inprog);
1240Sstevel@tonic-gate return (error);
1250Sstevel@tonic-gate }
1260Sstevel@tonic-gate
1270Sstevel@tonic-gate free(buffer_inprog);
1280Sstevel@tonic-gate
1290Sstevel@tonic-gate /*
1300Sstevel@tonic-gate * Does the buffer in progress meet our minimum
1310Sstevel@tonic-gate * processing requirements? or has it been around
1320Sstevel@tonic-gate * longer than we're willing to wait for more
1330Sstevel@tonic-gate * data to be logged?
1340Sstevel@tonic-gate */
1350Sstevel@tonic-gate if ((st.st_size < min_size) &&
1360Sstevel@tonic-gate ((time(0) - bep->be_lastprocessed) < idle_time)) {
1370Sstevel@tonic-gate /*
1380Sstevel@tonic-gate * The buffer does not meet the minimum
1390Sstevel@tonic-gate * size processing requirements, and it has not
1400Sstevel@tonic-gate * been around longer than we're willing to
1410Sstevel@tonic-gate * wait for more data collection.
1420Sstevel@tonic-gate * We return now without processing it.
1430Sstevel@tonic-gate */
1440Sstevel@tonic-gate return (0);
1450Sstevel@tonic-gate }
1460Sstevel@tonic-gate
1470Sstevel@tonic-gate /*
1480Sstevel@tonic-gate * Issue the LOG_FLUSH system call to flush the
1490Sstevel@tonic-gate * buffer and process it.
1500Sstevel@tonic-gate */
1510Sstevel@tonic-gate (void) memset((void *)&nfa, 0, sizeof (nfa));
1520Sstevel@tonic-gate nfa.version = NFSL_FLUSH_ARGS_VERS;
1530Sstevel@tonic-gate nfa.directive = NFSL_RENAME | NFSL_SYNC;
1540Sstevel@tonic-gate nfa.buff = bufferpath;
1550Sstevel@tonic-gate nfa.buff_len = strlen(bufferpath) + 1;
1560Sstevel@tonic-gate
1570Sstevel@tonic-gate if (_nfssys(LOG_FLUSH, &nfa) < 0) {
1580Sstevel@tonic-gate error = errno;
1590Sstevel@tonic-gate if (bep->be_error != error) {
1600Sstevel@tonic-gate syslog(LOG_ERR, gettext(
161*5006Sek110237 "_nfssys(%s) failed: %s"),
162*5006Sek110237 nfa.buff, strerror(error));
1630Sstevel@tonic-gate }
1640Sstevel@tonic-gate return (error);
1650Sstevel@tonic-gate }
1660Sstevel@tonic-gate } else {
1670Sstevel@tonic-gate if (bep->be_error != error) {
1680Sstevel@tonic-gate syslog(LOG_ERR, gettext("Can not stat %s: %s"),
169*5006Sek110237 bufferpath, strerror(error));
1700Sstevel@tonic-gate }
1710Sstevel@tonic-gate return (error);
1720Sstevel@tonic-gate }
1730Sstevel@tonic-gate }
1740Sstevel@tonic-gate
1750Sstevel@tonic-gate /*
1760Sstevel@tonic-gate * Open and lock input buffer.
1770Sstevel@tonic-gate * Passes in the value of the last error so that it will not
1780Sstevel@tonic-gate * print it again if it is still hitting the same error condition.
1790Sstevel@tonic-gate */
1800Sstevel@tonic-gate error = bep->be_error;
1810Sstevel@tonic-gate if ((lbp = nfslog_open_buf(bufferpath, &error)) == NULL)
1820Sstevel@tonic-gate goto done;
1830Sstevel@tonic-gate
1840Sstevel@tonic-gate if ((ncp = last_good_ncp =
1850Sstevel@tonic-gate nfsl_findconfig(*config_list, "global", &error)) == NULL) {
1860Sstevel@tonic-gate assert(error != 0);
1870Sstevel@tonic-gate nfsl_freeconfig_list(config_list);
1880Sstevel@tonic-gate if (error != bep->be_error) {
1890Sstevel@tonic-gate syslog(LOG_ERR, gettext(
190*5006Sek110237 "Could not search config list: %s"),
191*5006Sek110237 strerror(error));
1920Sstevel@tonic-gate }
1930Sstevel@tonic-gate goto done;
1940Sstevel@tonic-gate }
1950Sstevel@tonic-gate
1960Sstevel@tonic-gate assert(error == 0);
1970Sstevel@tonic-gate while ((lrp = nfslog_get_logrecord(lbp)) != NULL && keep_running) {
1980Sstevel@tonic-gate
1990Sstevel@tonic-gate if (*buffer_processed == 0)
2000Sstevel@tonic-gate (*buffer_processed)++;
2010Sstevel@tonic-gate
2020Sstevel@tonic-gate /*
2030Sstevel@tonic-gate * Get the matching config entry.
2040Sstevel@tonic-gate */
2050Sstevel@tonic-gate tag = lrp->log_record.re_tag;
2060Sstevel@tonic-gate if (strcmp(tag, last_good_ncp->nc_name) != 0) {
2070Sstevel@tonic-gate ncp = nfsl_findconfig(*config_list, tag, &error);
2080Sstevel@tonic-gate if (error) {
2090Sstevel@tonic-gate if (error != bep->be_error) {
2100Sstevel@tonic-gate syslog(LOG_ERR, gettext(
211*5006Sek110237 "Could not search config list: %s"),
212*5006Sek110237 strerror(error));
2130Sstevel@tonic-gate }
2140Sstevel@tonic-gate nfsl_freeconfig_list(config_list);
2150Sstevel@tonic-gate goto done;
2160Sstevel@tonic-gate }
2170Sstevel@tonic-gate if (ncp == NULL) {
2180Sstevel@tonic-gate badtag_notify(tag);
2190Sstevel@tonic-gate ncp = last_good_ncp;
2200Sstevel@tonic-gate goto skip;
2210Sstevel@tonic-gate }
2220Sstevel@tonic-gate last_good_ncp = ncp;
2230Sstevel@tonic-gate }
2240Sstevel@tonic-gate
2250Sstevel@tonic-gate if (ncp->nc_flags & NC_UPDATED) {
2260Sstevel@tonic-gate /*
2270Sstevel@tonic-gate * The location of the log files may have changed,
2280Sstevel@tonic-gate * we need to close transactions and invalidate
2290Sstevel@tonic-gate * cookies so that the log files can be reopened
2300Sstevel@tonic-gate * further down.
2310Sstevel@tonic-gate */
2320Sstevel@tonic-gate cleanup_elf_state(ncp);
2330Sstevel@tonic-gate cleanup_trans_state(ncp);
2340Sstevel@tonic-gate
2350Sstevel@tonic-gate ncp->nc_flags &= ~NC_UPDATED;
2360Sstevel@tonic-gate
2370Sstevel@tonic-gate /*
2380Sstevel@tonic-gate * Force cookies to be recreated if necessary.
2390Sstevel@tonic-gate */
2400Sstevel@tonic-gate elf_checked = trans_checked = B_FALSE;
2410Sstevel@tonic-gate }
2420Sstevel@tonic-gate
2430Sstevel@tonic-gate /*
2440Sstevel@tonic-gate * Open output files.
2450Sstevel@tonic-gate */
2460Sstevel@tonic-gate if (ncp->nc_rpclogpath != NULL) {
2470Sstevel@tonic-gate /*
2480Sstevel@tonic-gate * Log rpc requests in W3C-ELF format.
2490Sstevel@tonic-gate */
2500Sstevel@tonic-gate if (!elf_checked && ncp->nc_elfcookie != NULL) {
2510Sstevel@tonic-gate /*
2520Sstevel@tonic-gate * Make sure file still exists.
2530Sstevel@tonic-gate * Do this once per buffer.
2540Sstevel@tonic-gate */
2550Sstevel@tonic-gate if (stat(ncp->nc_rpclogpath, &st) == -1 &&
2560Sstevel@tonic-gate errno == ENOENT) {
2570Sstevel@tonic-gate /*
2580Sstevel@tonic-gate * The open rpclogfile has been
2590Sstevel@tonic-gate * deleted. Get new one below.
2600Sstevel@tonic-gate */
2610Sstevel@tonic-gate cleanup_elf_state(ncp);
2620Sstevel@tonic-gate }
2630Sstevel@tonic-gate elf_checked = B_TRUE;
2640Sstevel@tonic-gate }
2650Sstevel@tonic-gate if (ncp->nc_elfcookie == NULL) {
2660Sstevel@tonic-gate error = bep->be_error;
2670Sstevel@tonic-gate ncp->nc_elfcookie = nfslog_open_elf_file(
268*5006Sek110237 ncp->nc_rpclogpath, &lbp->bh, &error);
2690Sstevel@tonic-gate if (ncp->nc_elfcookie == NULL) {
2700Sstevel@tonic-gate bep->be_error = error;
2710Sstevel@tonic-gate goto done;
2720Sstevel@tonic-gate }
2730Sstevel@tonic-gate }
2740Sstevel@tonic-gate }
2750Sstevel@tonic-gate
2760Sstevel@tonic-gate if (ncp->nc_logpath != NULL) {
2770Sstevel@tonic-gate /*
2780Sstevel@tonic-gate * Log rpc reqs in trans/ftp format.
2790Sstevel@tonic-gate */
2800Sstevel@tonic-gate if (!trans_checked && ncp->nc_transcookie != NULL) {
2810Sstevel@tonic-gate /*
2820Sstevel@tonic-gate * Do this once per buffer.
2830Sstevel@tonic-gate */
2840Sstevel@tonic-gate if (stat(ncp->nc_logpath, &st) == -1 &&
2850Sstevel@tonic-gate errno == ENOENT) {
2860Sstevel@tonic-gate /*
2870Sstevel@tonic-gate * The open transaction file has been
2880Sstevel@tonic-gate * deleted. Close pending transaction
2890Sstevel@tonic-gate * work. A new transaction log will be
2900Sstevel@tonic-gate * opened by nfslog_open_trans_file()
2910Sstevel@tonic-gate * below.
2920Sstevel@tonic-gate */
2930Sstevel@tonic-gate cleanup_trans_state(ncp);
2940Sstevel@tonic-gate }
2950Sstevel@tonic-gate trans_checked = B_TRUE;
2960Sstevel@tonic-gate }
2970Sstevel@tonic-gate if (ncp->nc_transcookie == NULL) {
2980Sstevel@tonic-gate int transtolog;
2990Sstevel@tonic-gate
3000Sstevel@tonic-gate transtolog =
301*5006Sek110237 (ncp->nc_logformat == TRANSLOG_BASIC) ?
302*5006Sek110237 TRANSTOLOG_OPER_READWRITE : TRANSTOLOG_ALL;
3030Sstevel@tonic-gate error = bep->be_error;
3040Sstevel@tonic-gate ncp->nc_transcookie = nfslog_open_trans_file(
305*5006Sek110237 ncp->nc_logpath, ncp->nc_logformat,
306*5006Sek110237 transtolog, &error);
3070Sstevel@tonic-gate if (ncp->nc_transcookie == NULL) {
3080Sstevel@tonic-gate bep->be_error = error;
3090Sstevel@tonic-gate goto done;
3100Sstevel@tonic-gate }
3110Sstevel@tonic-gate }
3120Sstevel@tonic-gate }
3130Sstevel@tonic-gate
3140Sstevel@tonic-gate assert(ncp->nc_fhpath != NULL);
3150Sstevel@tonic-gate
3160Sstevel@tonic-gate if (nfslog_process_fh_rec(lrp, ncp->nc_fhpath, &path1, &path2,
3170Sstevel@tonic-gate ncp->nc_elfcookie != NULL)) {
3180Sstevel@tonic-gate /*
3190Sstevel@tonic-gate * Make sure there is room.
3200Sstevel@tonic-gate */
3210Sstevel@tonic-gate if (ncp->nc_elfcookie != NULL) {
3220Sstevel@tonic-gate (void) nfslog_process_elf_rec(ncp->nc_elfcookie,
323*5006Sek110237 &lrp->log_record, path1, path2);
3240Sstevel@tonic-gate }
3250Sstevel@tonic-gate
3260Sstevel@tonic-gate if (ncp->nc_transcookie != NULL) {
3270Sstevel@tonic-gate (void) nfslog_process_trans_rec(
328*5006Sek110237 ncp->nc_transcookie,
329*5006Sek110237 &lrp->log_record, ncp->nc_fhpath,
330*5006Sek110237 path1, path2);
3310Sstevel@tonic-gate }
3320Sstevel@tonic-gate }
3330Sstevel@tonic-gate
3340Sstevel@tonic-gate skip: if (path1 != NULL)
3350Sstevel@tonic-gate free(path1);
3360Sstevel@tonic-gate if (path2 != NULL)
3370Sstevel@tonic-gate free(path2);
3380Sstevel@tonic-gate
3390Sstevel@tonic-gate path1 = path2 = NULL;
3400Sstevel@tonic-gate nfslog_free_logrecord(lrp, TRUE);
3410Sstevel@tonic-gate } /* while */
3420Sstevel@tonic-gate
3430Sstevel@tonic-gate if (!error && keep_running) {
3440Sstevel@tonic-gate /*
3450Sstevel@tonic-gate * Keep track of when this buffer was last processed.
3460Sstevel@tonic-gate */
3470Sstevel@tonic-gate bep->be_lastprocessed = time(0);
3480Sstevel@tonic-gate
3490Sstevel@tonic-gate if (test && *buffer_processed != 0) {
3500Sstevel@tonic-gate /*
3510Sstevel@tonic-gate * Save the buffer for future debugging. We do this
3520Sstevel@tonic-gate * by following the log cycling policy, with a maximum
3530Sstevel@tonic-gate * of 'max_logs_preserve' to save.
3540Sstevel@tonic-gate */
3550Sstevel@tonic-gate if (cycle_log(bufferpath, max_logs_preserve)) {
3560Sstevel@tonic-gate syslog(LOG_ERR, gettext(
357*5006Sek110237 "could not save copy of buffer \"%s\""),
358*5006Sek110237 bufferpath);
3590Sstevel@tonic-gate }
3600Sstevel@tonic-gate } else {
3610Sstevel@tonic-gate /*
3620Sstevel@tonic-gate * Remove buffer since it has been processed.
3630Sstevel@tonic-gate */
3640Sstevel@tonic-gate if (unlink(bufferpath)) {
3650Sstevel@tonic-gate error = errno;
3660Sstevel@tonic-gate syslog(LOG_ERR, gettext(
367*5006Sek110237 "could not unlink %s: %s"),
368*5006Sek110237 bufferpath, strerror(error));
3690Sstevel@tonic-gate /*
3700Sstevel@tonic-gate * Buffer was processed correctly.
3710Sstevel@tonic-gate */
3720Sstevel@tonic-gate error = 0;
3730Sstevel@tonic-gate }
3740Sstevel@tonic-gate }
3750Sstevel@tonic-gate }
3760Sstevel@tonic-gate
3770Sstevel@tonic-gate done:
3780Sstevel@tonic-gate if (lbp != NULL)
3790Sstevel@tonic-gate nfslog_close_buf(lbp, quick_cleaning);
3800Sstevel@tonic-gate if (ncp && !quick_cleaning)
3810Sstevel@tonic-gate cleanup_elf_state(ncp);
3820Sstevel@tonic-gate
3830Sstevel@tonic-gate return (error);
3840Sstevel@tonic-gate }
3850Sstevel@tonic-gate
3860Sstevel@tonic-gate static void
cleanup_elf_state(nfsl_config_t * ncp)3870Sstevel@tonic-gate cleanup_elf_state(nfsl_config_t *ncp)
3880Sstevel@tonic-gate {
3890Sstevel@tonic-gate if (ncp->nc_elfcookie != NULL) {
3900Sstevel@tonic-gate nfslog_close_elf_file(&ncp->nc_elfcookie);
3910Sstevel@tonic-gate assert(ncp->nc_elfcookie == NULL);
3920Sstevel@tonic-gate }
3930Sstevel@tonic-gate }
3940Sstevel@tonic-gate
3950Sstevel@tonic-gate static void
cleanup_trans_state(nfsl_config_t * ncp)3960Sstevel@tonic-gate cleanup_trans_state(nfsl_config_t *ncp)
3970Sstevel@tonic-gate {
3980Sstevel@tonic-gate if (ncp->nc_transcookie != NULL) {
3990Sstevel@tonic-gate nfslog_close_transactions(&ncp->nc_transcookie);
4000Sstevel@tonic-gate assert(ncp->nc_transcookie == NULL);
4010Sstevel@tonic-gate }
4020Sstevel@tonic-gate }
4030Sstevel@tonic-gate
4040Sstevel@tonic-gate /*
4050Sstevel@tonic-gate * Searches the list of previously seen bad tags. Note that this
4060Sstevel@tonic-gate * list is never pruned. This should not be a problem since the
4070Sstevel@tonic-gate * list of bad tags should be fairl small. New entries are inserted
4080Sstevel@tonic-gate * at the beginning of the list assuming it will be accessed more
4090Sstevel@tonic-gate * frequently since we have just seen it.
4100Sstevel@tonic-gate */
4110Sstevel@tonic-gate static void
badtag_notify(char * tag)4120Sstevel@tonic-gate badtag_notify(char *tag)
4130Sstevel@tonic-gate {
414*5006Sek110237 struct nfs_log_list *lp, *p;
4150Sstevel@tonic-gate int error;
4160Sstevel@tonic-gate
4170Sstevel@tonic-gate for (p = badtag_list; p != NULL; p = p->l_next) {
4180Sstevel@tonic-gate if (strcmp(tag, p->l_name) == 0) {
4190Sstevel@tonic-gate /*
4200Sstevel@tonic-gate * We've seen this before, nothing to do.
4210Sstevel@tonic-gate */
4220Sstevel@tonic-gate return;
4230Sstevel@tonic-gate }
4240Sstevel@tonic-gate }
4250Sstevel@tonic-gate
4260Sstevel@tonic-gate /*
4270Sstevel@tonic-gate * Not on the list, add it.
4280Sstevel@tonic-gate */
429*5006Sek110237 syslog(LOG_ERR, gettext("tag \"%s\" not found in %s - "
430*5006Sek110237 "ignoring records referencing such tag."),
431*5006Sek110237 tag, NFSL_CONFIG_FILE_PATH);
4320Sstevel@tonic-gate
433*5006Sek110237 if ((lp = (struct nfs_log_list *)malloc(sizeof (*lp))) != NULL) {
4340Sstevel@tonic-gate if ((lp->l_name = strdup(tag)) != NULL) {
4350Sstevel@tonic-gate lp->l_next = badtag_list;
4360Sstevel@tonic-gate badtag_list = lp;
4370Sstevel@tonic-gate return; /* done */
4380Sstevel@tonic-gate }
4390Sstevel@tonic-gate }
4400Sstevel@tonic-gate
4410Sstevel@tonic-gate if (lp->l_name != NULL)
4420Sstevel@tonic-gate free(lp->l_name);
4430Sstevel@tonic-gate if (lp)
4440Sstevel@tonic-gate free(lp);
4450Sstevel@tonic-gate error = errno;
4460Sstevel@tonic-gate syslog(LOG_ERR, gettext(
4470Sstevel@tonic-gate "Cannot add \"%s\" to bad tag list: %s"), tag, strerror(error));
4480Sstevel@tonic-gate }
449