2007-10-12 20:34:37

by Kevin Coffman

[permalink] [raw]
Subject: [PATCH 0/9] nfs-utils logging and extra code clean-up

Hi Neil,

These patches clean up logging code and eliminate duplicate and
unused code.

01 svcgssd_fix_prototype_warning
Cleans up a new compiler warning that appeared after
-Wstrict-prototypes was added to the compile options

02 svcgssd_print_hexl_debug_stdout
Change debugging to use printf instead of logging
function. (In preparation of David's patches below.)

03 svcgssd_debug_downcall_info
Change svcgssd to print its own debug info rather
than relying on modified qword_ functions.

04 nfslib_cacheio_updates_for_svcgssd
Move local cacheio functions from svcgssd into the
common library.
Modify the library read function to use a bigger
buffer as needed by svcgssd.

05 svcgssd_use_common_cacheio_support
svcgssd now uses the common functions rather than
local modified copies.

06 svcgssd_remove_private_cacheio
Remove the private copies in svcgssd

07 xlog_logging_code_cleanup
08 idmapd_gssd_use_xlog
09 idmapd_remove_setproctitle

These patches are from David P. Quigley <[email protected]>
07 clean up the xlog code
08 modify idmapd and gssd to use the cleaned up code, and
09 remove unused code from idmapd.


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs


2007-10-12 20:35:21

by Kevin Coffman

[permalink] [raw]
Subject: [PATCH 9/9] Remove unnecessary code from idmapd.

From: Kevin Coffman <[email protected]>

This patch removes unnecessary code from idmapd. setproctitle is not used
anywhere and it can be removed. In addition the kernel section of the
nfs_idmap.h header is not used and is out of date and thus is removed.

Signed-off-by: David P. Quigley <[email protected]>
Signed-off-by: Kevin Coffman <[email protected]>
---

utils/idmapd/Makefile.am | 1
utils/idmapd/nfs_idmap.h | 7 ---
utils/idmapd/setproctitle.c | 110 -------------------------------------------
3 files changed, 0 insertions(+), 118 deletions(-)

diff --git a/utils/idmapd/Makefile.am b/utils/idmapd/Makefile.am
index 586ac9a..eb393df 100644
--- a/utils/idmapd/Makefile.am
+++ b/utils/idmapd/Makefile.am
@@ -16,7 +16,6 @@ idmapd_SOURCES = \
atomicio.c \
cfg.c \
idmapd.c \
- setproctitle.c \
strlcat.c \
strlcpy.c \
\
diff --git a/utils/idmapd/nfs_idmap.h b/utils/idmapd/nfs_idmap.h
index 5ec7cf1..59bced3 100644
--- a/utils/idmapd/nfs_idmap.h
+++ b/utils/idmapd/nfs_idmap.h
@@ -61,11 +61,4 @@ struct idmap_msg {
u_int8_t im_status;
};

-#ifdef __KERNEL__
-void *nfs_idmap_new(struct nfs_server *);
-void nfs_idmap_delete(struct nfs_server *);
-int nfs_idmap_id(struct nfs_server *, u_int8_t, char *, u_int, uid_t *);
-int nfs_idmap_name(struct nfs_server *, u_int8_t, uid_t, char *, u_int *);
-#endif /* __KERNEL__ */
-
#endif /* NFS_IDMAP_H */
diff --git a/utils/idmapd/setproctitle.c b/utils/idmapd/setproctitle.c
deleted file mode 100644
index 0679f4e..0000000
--- a/utils/idmapd/setproctitle.c
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Modified for OpenSSH by Kevin Steves
- * October 2000
- */
-
-/*
- * Copyright (c) 1994, 1995 Christopher G. Demetriou
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Christopher G. Demetriou
- * for the NetBSD Project.
- * 4. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: setproctitle.c,v 1.8 2001/11/06 19:21:40 art Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/types.h>
-
-#include <stdio.h>
-#include <string.h>
-#include <stdarg.h>
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#ifndef HAVE_SETPROCTITLE
-
-#define SPT_NONE 0
-#define SPT_PSTAT 1
-
-#ifndef SPT_TYPE
-#define SPT_TYPE SPT_NONE
-#endif
-
-#if SPT_TYPE == SPT_PSTAT
-#include <sys/param.h>
-#include <sys/pstat.h>
-#endif /* SPT_TYPE == SPT_PSTAT */
-
-#define MAX_PROCTITLE 2048
-
-extern char *__progname;
-
-/*
- * Set Process Title (SPT) defines. Modeled after sendmail's
- * SPT type definition strategy.
- *
- * SPT_TYPE:
- *
- * SPT_NONE: Don't set the process title. Default.
- * SPT_PSTAT: Use pstat(PSTAT_SETCMD). HP-UX specific.
- */
-
-void
-setproctitle(const char *fmt, ...)
-{
-#if SPT_TYPE != SPT_NONE
- va_list ap;
-
- char buf[MAX_PROCTITLE];
- size_t used;
-
-#if SPT_TYPE == SPT_PSTAT
- union pstun pst;
-#endif /* SPT_TYPE == SPT_PSTAT */
-
- va_start(ap, fmt);
- if (fmt != NULL) {
- used = snprintf(buf, MAX_PROCTITLE, "%s: ", __progname);
- if (used >= MAX_PROCTITLE)
- used = MAX_PROCTITLE - 1;
- (void)vsnprintf(buf + used, MAX_PROCTITLE - used, fmt, ap);
- } else
- (void)snprintf(buf, MAX_PROCTITLE, "%s", __progname);
- va_end(ap);
- used = strlen(buf);
-
-#if SPT_TYPE == SPT_PSTAT
- pst.pst_command = buf;
- pstat(PSTAT_SETCMD, pst, used, 0, 0);
-#endif /* SPT_TYPE == SPT_PSTAT */
-
-#endif /* SPT_TYPE != SPT_NONE */
-}
-#endif /* HAVE_SETPROCTITLE */


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

2007-10-12 20:35:06

by Kevin Coffman

[permalink] [raw]
Subject: [PATCH 6/9] Remove svcgssd's private version of cacheio.c

From: Kevin Coffman <[email protected]>

Now that svcgssd is using the qword_* functions in the
support library, remove the private version.

Signed-off-by: Kevin Coffman <[email protected]>
---

utils/gssd/cacheio.c | 297 --------------------------------------------------
utils/gssd/cacheio.h | 49 --------
2 files changed, 0 insertions(+), 346 deletions(-)

diff --git a/utils/gssd/cacheio.c b/utils/gssd/cacheio.c
deleted file mode 100644
index f47f1fa..0000000
--- a/utils/gssd/cacheio.c
+++ /dev/null
@@ -1,297 +0,0 @@
-/*
- Copyright (c) 2004 The Regents of the University of Michigan.
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions
- are met:
-
- 1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- 3. Neither the name of the University nor the names of its
- contributors may be used to endorse or promote products derived
- from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
- WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-/*
- * support/nfs/cacheio.c
- * support IO on the cache channel files in 2.5 and beyond.
- * These use 'qwords' which are like words, but with a little quoting.
- *
- */
-
-
-/*
- * Support routines for text-based upcalls.
- * Fields are separated by spaces.
- * Fields are either mangled to quote space tab newline slosh with slosh
- * or a hexified with a leading \x
- * Record is terminated with newline.
- *
- */
-
-#include "cacheio.h"
-#include <stdio.h>
-#include <ctype.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <time.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include "err_util.h"
-
-void qword_add(char **bpp, int *lp, char *str)
-{
- char *bp = *bpp;
- int len = *lp;
- char c;
-
- if (len < 0) return;
-
- while ((c=*str++) && len)
- switch(c) {
- case ' ':
- case '\t':
- case '\n':
- case '\\':
- if (len >= 4) {
- *bp++ = '\\';
- *bp++ = '0' + ((c & 0300)>>6);
- *bp++ = '0' + ((c & 0070)>>3);
- *bp++ = '0' + ((c & 0007)>>0);
- }
- len -= 4;
- break;
- default:
- *bp++ = c;
- len--;
- }
- if (c || len <1) len = -1;
- else {
- *bp++ = ' ';
- len--;
- }
- *bpp = bp;
- *lp = len;
-}
-
-void qword_addhex(char **bpp, int *lp, char *buf, int blen)
-{
- char *bp = *bpp;
- int len = *lp;
-
- if (len < 0) return;
-
- if (len > 2) {
- *bp++ = '\\';
- *bp++ = 'x';
- len -= 2;
- while (blen && len >= 2) {
- unsigned char c = *buf++;
- *bp++ = '0' + ((c&0xf0)>>4) + (c>=0xa0)*('a'-'9'-1);
- *bp++ = '0' + (c&0x0f) + ((c&0x0f)>=0x0a)*('a'-'9'-1);
- len -= 2;
- blen--;
- }
- }
- if (blen || len<1) len = -1;
- else {
- *bp++ = ' ';
- len--;
- }
- *bpp = bp;
- *lp = len;
-}
-
-void qword_addint(char **bpp, int *lp, int n)
-{
- int len;
-
- len = snprintf(*bpp, *lp, "%d ", n);
- if (len > *lp)
- len = *lp;
- *bpp += len;
- *lp -= len;
-}
-
-void qword_adduint(char **bpp, int *lp, unsigned int n)
-{
- int len;
-
- len = snprintf(*bpp, *lp, "%u ", n);
- if (len > *lp)
- len = *lp;
- *bpp += len;
- *lp -= len;
-}
-
-void qword_addeol(char **bpp, int *lp)
-{
- if (*lp <= 0)
- return;
- **bpp = '\n';
- (*bpp)++;
- (*lp)--;
-}
-
-static char qword_buf[8192];
-void qword_print(FILE *f, char *str)
-{
- char *bp = qword_buf;
- int len = sizeof(qword_buf);
- qword_add(&bp, &len, str);
- fwrite(qword_buf, bp-qword_buf, 1, f);
-}
-
-void qword_printhex(FILE *f, char *str, int slen)
-{
- char *bp = qword_buf;
- int len = sizeof(qword_buf);
- qword_addhex(&bp, &len, str, slen);
- fwrite(qword_buf, bp-qword_buf, 1, f);
-}
-
-void qword_printint(FILE *f, int num)
-{
- fprintf(f, "%d ", num);
-}
-
-int qword_eol(FILE *f)
-{
- int err;
- fprintf(f,"\n");
- err = fflush(f);
- return err;
-}
-
-
-
-#define isodigit(c) (isdigit(c) && c <= '7')
-int qword_get(char **bpp, char *dest, int bufsize)
-{
- /* return bytes copied, or -1 on error */
- char *bp = *bpp;
- int len = 0;
-
- while (*bp == ' ') bp++;
-
- if (bp[0] == '\\' && bp[1] == 'x') {
- /* HEX STRING */
- bp += 2;
- while (isxdigit(bp[0]) && isxdigit(bp[1]) && len < bufsize) {
- int byte = isdigit(*bp) ? *bp-'0' : toupper(*bp)-'A'+10;
- bp++;
- byte <<= 4;
- byte |= isdigit(*bp) ? *bp-'0' : toupper(*bp)-'A'+10;
- *dest++ = byte;
- bp++;
- len++;
- }
- } else {
- /* text with \nnn octal quoting */
- while (*bp != ' ' && *bp != '\n' && *bp && len < bufsize-1) {
- if (*bp == '\\' &&
- isodigit(bp[1]) && (bp[1] <= '3') &&
- isodigit(bp[2]) &&
- isodigit(bp[3])) {
- int byte = (*++bp -'0');
- bp++;
- byte = (byte << 3) | (*bp++ - '0');
- byte = (byte << 3) | (*bp++ - '0');
- *dest++ = byte;
- len++;
- } else {
- *dest++ = *bp++;
- len++;
- }
- }
- }
-
- if (*bp != ' ' && *bp != '\n' && *bp != '\0')
- return -1;
- while (*bp == ' ') bp++;
- *bpp = bp;
- *dest = '\0';
- return len;
-}
-
-int qword_get_int(char **bpp, int *anint)
-{
- char buf[50];
- char *ep;
- int rv;
- int len = qword_get(bpp, buf, 50);
- if (len < 0) return -1;
- if (len ==0) return -1;
- rv = strtol(buf, &ep, 0);
- if (*ep) return -1;
- *anint = rv;
- return 0;
-}
-
-#define READLINE_BUFFER_INCREMENT 2048
-
-int readline(int fd, char **buf, int *lenp)
-{
- /* read a line into *buf, which is malloced *len long
- * realloc if needed until we find a \n
- * nul out the \n and return
- * 0 of eof, 1 of success
- */
- int len;
-
- if (*lenp == 0) {
- char *b = malloc(READLINE_BUFFER_INCREMENT);
- if (b == NULL)
- return 0;
- *buf = b;
- *lenp = READLINE_BUFFER_INCREMENT;
- }
- len = read(fd, *buf, *lenp);
- if (len <= 0) {
- printerr(0, "readline: read error: len %d errno %d (%s)\n",
- len, errno, strerror(errno));
- return 0;
- }
- while ((*buf)[len-1] != '\n') {
- /* now the less common case. There was no newline,
- * so we have to keep reading after re-alloc
- */
- char *new;
- int nl;
- *lenp += READLINE_BUFFER_INCREMENT;
- new = realloc(*buf, *lenp);
- if (new == NULL)
- return 0;
- *buf = new;
- nl = read(fd, *buf +len, *lenp - len);
- if (nl <= 0 ) {
- printerr(0, "readline: read error: len %d "
- "errno %d (%s)\n", nl, errno, strerror(errno));
- return 0;
- }
- len += nl;
- }
- (*buf)[len-1] = 0;
- printerr(3, "readline: read %d chars into buffer of size %d:\n%s\n",
- len, *lenp, *buf);
- return 1;
-}
diff --git a/utils/gssd/cacheio.h b/utils/gssd/cacheio.h
deleted file mode 100644
index 6585fc7..0000000
--- a/utils/gssd/cacheio.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- Copyright (c) 2004 The Regents of the University of Michigan.
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions
- are met:
-
- 1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- 3. Neither the name of the University nor the names of its
- contributors may be used to endorse or promote products derived
- from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
- WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-#ifndef _CACHEIO_H_
-#define _CACHEIO_H_
-
-#include <stdio.h>
-
-void qword_add(char **bpp, int *lp, char *str);
-void qword_addhex(char **bpp, int *lp, char *buf, int blen);
-void qword_addint(char **bpp, int *lp, int n);
-void qword_adduint(char **bpp, int *lp, unsigned int n);
-void qword_addeol(char **bpp, int *lp);
-void qword_print(FILE *f, char *str);
-void qword_printhex(FILE *f, char *str, int slen);
-void qword_printint(FILE *f, int num);
-int qword_eol(FILE *f);
-int readline(int fd, char **buf, int *lenp);
-int qword_get(char **bpp, char *dest, int bufsize);
-int qword_get_int(char **bpp, int *anint);
-
-#endif /* _CACHEIO_H_ */


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

2007-10-12 20:34:41

by Kevin Coffman

[permalink] [raw]
Subject: [PATCH 1/9] Fix new warning after strict prototype checking enabled

From: Kevin Coffman <[email protected]>

Fix function declaration to eliminate compiler warning about it
not being a prototype after -Wstrict-prototypes was added.

Signed-off-by: Kevin Coffman <[email protected]>
---

utils/gssd/svcgssd.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/utils/gssd/svcgssd.c b/utils/gssd/svcgssd.c
index 37e0407..4aa157d 100644
--- a/utils/gssd/svcgssd.c
+++ b/utils/gssd/svcgssd.c
@@ -125,7 +125,7 @@ mydaemon(int nochdir, int noclose)
}

static void
-release_parent()
+release_parent(void)
{
int status;



-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

2007-10-12 20:35:00

by Kevin Coffman

[permalink] [raw]
Subject: [PATCH 5/9] Use nfslib versions of cacheio functions

From: Kevin Coffman <[email protected]>

Now that the nfslib library has all the necessary functions and they
all operate as needed, use them instead of the private versions in
utils/gssd/cacheio.c.
The obsolete private versions are removed in the next patch.

Signed-off-by: Kevin Coffman <[email protected]>
---

utils/gssd/Makefile.am | 2 --
utils/gssd/svcgssd_proc.c | 2 +-
2 files changed, 1 insertions(+), 3 deletions(-)

diff --git a/utils/gssd/Makefile.am b/utils/gssd/Makefile.am
index 7c32597..c0ca8be 100644
--- a/utils/gssd/Makefile.am
+++ b/utils/gssd/Makefile.am
@@ -46,13 +46,11 @@ gssd_CFLAGS = $(AM_CFLAGS) $(CFLAGS) \

svcgssd_SOURCES = \
$(COMMON_SRCS) \
- cacheio.c \
svcgssd.c \
svcgssd_main_loop.c \
svcgssd_mech2file.c \
svcgssd_proc.c \
\
- cacheio.h \
svcgssd.h

svcgssd_LDADD = \
diff --git a/utils/gssd/svcgssd_proc.c b/utils/gssd/svcgssd_proc.c
index 2dffa83..794c2f4 100644
--- a/utils/gssd/svcgssd_proc.c
+++ b/utils/gssd/svcgssd_proc.c
@@ -45,12 +45,12 @@
#include <fcntl.h>
#include <errno.h>
#include <nfsidmap.h>
+#include <nfslib.h>

#include "svcgssd.h"
#include "gss_util.h"
#include "err_util.h"
#include "context.h"
-#include "cacheio.h"

extern char * mech2file(gss_OID mech);
#define SVCGSSD_CONTEXT_CHANNEL "/proc/net/rpc/auth.rpcsec.context/channel"


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

2007-10-12 20:34:45

by Kevin Coffman

[permalink] [raw]
Subject: [PATCH 2/9] Make print_hexl function write to stdout rather than using printerr

From: Kevin Coffman <[email protected]>

print_hexl() currently uses printerr, but is really only necessary
for local debugging and should simply write to stdout.
Also change it to print the description internally.
Wrap it and its use in #ifdef DEBUG.

Signed-off-by: Kevin Coffman <[email protected]>
---

utils/gssd/svcgssd_proc.c | 33 ++++++++++++++++++---------------
1 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/utils/gssd/svcgssd_proc.c b/utils/gssd/svcgssd_proc.c
index 7c58f7b..52c3aaf 100644
--- a/utils/gssd/svcgssd_proc.c
+++ b/utils/gssd/svcgssd_proc.c
@@ -250,42 +250,43 @@ out:
return res;
}

+#ifdef DEBUG
void
-print_hexl(int pri, unsigned char *cp, int length)
+print_hexl(const char *description, unsigned char *cp, int length)
{
int i, j, jm;
unsigned char c;

- printerr(pri, "length %d\n",length);
- printerr(pri, "\n");
+ printf("%s (length %d)\n", description, length);

for (i = 0; i < length; i += 0x10) {
- printerr(pri, " %04x: ", (u_int)i);
+ printf(" %04x: ", (u_int)i);
jm = length - i;
jm = jm > 16 ? 16 : jm;

for (j = 0; j < jm; j++) {
if ((j % 2) == 1)
- printerr(pri,"%02x ", (u_int)cp[i+j]);
+ printf("%02x ", (u_int)cp[i+j]);
else
- printerr(pri,"%02x", (u_int)cp[i+j]);
+ printf("%02x", (u_int)cp[i+j]);
}
for (; j < 16; j++) {
if ((j % 2) == 1)
- printerr(pri," ");
+ printf(" ");
else
- printerr(pri," ");
+ printf(" ");
}
- printerr(pri," ");
+ printf(" ");

for (j = 0; j < jm; j++) {
c = cp[i+j];
c = isprint(c) ? c : '.';
- printerr(pri,"%c", c);
+ printf("%c", c);
}
- printerr(pri,"\n");
+ printf("\n");
}
}
+#endif

void
handle_nullreq(FILE *f) {
@@ -326,13 +327,15 @@ handle_nullreq(FILE *f) {

in_handle.length = (size_t) qword_get(&cp, in_handle.value,
sizeof(in_handle_buf));
- printerr(2, "in_handle: \n");
- print_hexl(2, in_handle.value, in_handle.length);
+#ifdef DEBUG
+ print_hexl("in_handle", in_handle.value, in_handle.length);
+#endif

in_tok.length = (size_t) qword_get(&cp, in_tok.value,
sizeof(in_tok_buf));
- printerr(2, "in_tok: \n");
- print_hexl(2, in_tok.value, in_tok.length);
+#ifdef DEBUG
+ print_hexl("in_tok", in_tok.value, in_tok.length);
+#endif

if (in_tok.length < 0) {
printerr(0, "WARNING: handle_nullreq: "


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

2007-10-12 20:34:51

by Kevin Coffman

[permalink] [raw]
Subject: [PATCH 3/9] Use printerr to print svcgssd downcall debugging info

From: Kevin Coffman <[email protected]>

Rather than depending on modified qword_* functions to print
svcgssd debugging information, use printerr in the downcall
function.

And while we're at it, label things so we know what we're looking at!

Signed-off-by: Kevin Coffman <[email protected]>
---

utils/gssd/cacheio.c | 11 -----------
utils/gssd/svcgssd_proc.c | 8 +++++++-
2 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/utils/gssd/cacheio.c b/utils/gssd/cacheio.c
index e24ef56..f47f1fa 100644
--- a/utils/gssd/cacheio.c
+++ b/utils/gssd/cacheio.c
@@ -153,17 +153,12 @@ void qword_addeol(char **bpp, int *lp)
}

static char qword_buf[8192];
-static char tmp_buf[8192];
void qword_print(FILE *f, char *str)
{
char *bp = qword_buf;
int len = sizeof(qword_buf);
qword_add(&bp, &len, str);
fwrite(qword_buf, bp-qword_buf, 1, f);
- /* XXX: */
- memcpy(tmp_buf, qword_buf, bp-qword_buf);
- tmp_buf[bp-qword_buf] = '\0';
- printerr(2, "%s", tmp_buf);
}

void qword_printhex(FILE *f, char *str, int slen)
@@ -172,16 +167,11 @@ void qword_printhex(FILE *f, char *str, int slen)
int len = sizeof(qword_buf);
qword_addhex(&bp, &len, str, slen);
fwrite(qword_buf, bp-qword_buf, 1, f);
- /* XXX: */
- memcpy(tmp_buf, qword_buf, bp-qword_buf);
- tmp_buf[bp-qword_buf] = '\0';
- printerr(2, "%s", tmp_buf);
}

void qword_printint(FILE *f, int num)
{
fprintf(f, "%d ", num);
- printerr(2, "%d ", num);
}

int qword_eol(FILE *f)
@@ -189,7 +179,6 @@ int qword_eol(FILE *f)
int err;
fprintf(f,"\n");
err = fflush(f);
- printerr(2, "\n");
return err;
}

diff --git a/utils/gssd/svcgssd_proc.c b/utils/gssd/svcgssd_proc.c
index 52c3aaf..2dffa83 100644
--- a/utils/gssd/svcgssd_proc.c
+++ b/utils/gssd/svcgssd_proc.c
@@ -90,8 +90,14 @@ do_svc_downcall(gss_buffer_desc *out_handle, struct svc_cred *cred,
qword_printint(f, cred->cr_uid);
qword_printint(f, cred->cr_gid);
qword_printint(f, cred->cr_ngroups);
- for (i=0; i < cred->cr_ngroups; i++)
+ printerr(2, "mech: %s, hndl len: %d, ctx len %d, timeout: %d, "
+ "uid: %d, gid: %d, num aux grps: %d:\n",
+ fname, out_handle->length, context_token->length, 0x7fffffff,
+ cred->cr_uid, cred->cr_gid, cred->cr_ngroups);
+ for (i=0; i < cred->cr_ngroups; i++) {
qword_printint(f, cred->cr_groups[i]);
+ printerr(2, " (%4d) %d\n", i+1, cred->cr_groups[i]);
+ }
qword_print(f, fname);
qword_printhex(f, context_token->value, context_token->length);
err = qword_eol(f);


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

2007-10-12 20:34:56

by Kevin Coffman

[permalink] [raw]
Subject: [PATCH 4/9] Copy new cacheio functions used by svcgssd to nfslib

From: Kevin Coffman <[email protected]>

Copy private qword_ functions from the svcgssd version into
the general nfslib library. Add prototypes as needed.
Also, update readline to use a bigger buffer allocation as is
needed in the svcgssd version.

Signed-off-by: Kevin Coffman <[email protected]>
---

support/include/nfslib.h | 5 +++++
support/nfs/cacheio.c | 47 +++++++++++++++++++++++++++++++++++++++-------
2 files changed, 45 insertions(+), 7 deletions(-)

diff --git a/support/include/nfslib.h b/support/include/nfslib.h
index ffa2440..422b012 100644
--- a/support/include/nfslib.h
+++ b/support/include/nfslib.h
@@ -144,6 +144,11 @@ int qword_get(char **bpp, char *dest, int bufsize);
int qword_get_int(char **bpp, int *anint);
void cache_flush(int force);
int check_new_cache(void);
+void qword_add(char **bpp, int *lp, char *str);
+void qword_addhex(char **bpp, int *lp, char *buf, int blen);
+void qword_addint(char **bpp, int *lp, int n);
+void qword_adduint(char **bpp, int *lp, unsigned int n);
+void qword_addeol(char **bpp, int *lp);

void closeall(int min);

diff --git a/support/nfs/cacheio.c b/support/nfs/cacheio.c
index 9d271cd..48292f8 100644
--- a/support/nfs/cacheio.c
+++ b/support/nfs/cacheio.c
@@ -88,6 +88,37 @@ void qword_addhex(char **bpp, int *lp, char *buf, int blen)
*lp = len;
}

+void qword_addint(char **bpp, int *lp, int n)
+{
+ int len;
+
+ len = snprintf(*bpp, *lp, "%d ", n);
+ if (len > *lp)
+ len = *lp;
+ *bpp += len;
+ *lp -= len;
+}
+
+void qword_adduint(char **bpp, int *lp, unsigned int n)
+{
+ int len;
+
+ len = snprintf(*bpp, *lp, "%u ", n);
+ if (len > *lp)
+ len = *lp;
+ *bpp += len;
+ *lp -= len;
+}
+
+void qword_addeol(char **bpp, int *lp)
+{
+ if (*lp <= 0)
+ return;
+ **bpp = '\n';
+ (*bpp)++;
+ (*lp)--;
+}
+
static char qword_buf[8192];
void qword_print(FILE *f, char *str)
{
@@ -192,23 +223,25 @@ int qword_get_int(char **bpp, int *anint)
return 0;
}

+#define READLINE_BUFFER_INCREMENT 2048
+
int readline(int fd, char **buf, int *lenp)
{
/* read a line into *buf, which is malloced *len long
* realloc if needed until we find a \n
* nul out the \n and return
- * 0 of eof, 1 of success
+ * 0 on eof, 1 on success
*/
- int len = *lenp;
+ int len;

- if (len == 0) {
- char *b = malloc(128);
+ if (*lenp == 0) {
+ char *b = malloc(READLINE_BUFFER_INCREMENT);
if (b == NULL)
return 0;
*buf = b;
- *lenp = 128;
+ *lenp = READLINE_BUFFER_INCREMENT;
}
- len = read(fd, *buf, len);
+ len = read(fd, *buf, *lenp);
if (len <= 0)
return 0;
while ((*buf)[len-1] != '\n') {
@@ -217,7 +250,7 @@ int readline(int fd, char **buf, int *lenp)
*/
char *new;
int nl;
- *lenp *= 2;
+ *lenp += READLINE_BUFFER_INCREMENT;
new = realloc(*buf, *lenp);
if (new == NULL)
return 0;


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

2007-10-12 20:35:17

by Kevin Coffman

[permalink] [raw]
Subject: [PATCH 8/9] Remove old logging implementation for idmapd and rework gssd and idmapd to use the new xlog logging infrastructure.

From: Kevin Coffman <[email protected]>

This patch removes all of the old idmap_* logging functions and replaced them
with the corresponding xlog functions. In addition that that it also reworks
the gssd logging wrappers to use the new xlog_backend. Finally it makes
necessary changes to the build files to get the project compiling again.

Signed-off-by: David P. Quigley <[email protected]>
Signed-off-by: Kevin Coffman <[email protected]>
---

utils/gssd/Makefile.am | 3 +
utils/gssd/err_util.c | 43 ++-------------
utils/idmapd/idmapd.c | 142 +++++++++++++-----------------------------------
3 files changed, 46 insertions(+), 142 deletions(-)

diff --git a/utils/gssd/Makefile.am b/utils/gssd/Makefile.am
index c0ca8be..e42b339 100644
--- a/utils/gssd/Makefile.am
+++ b/utils/gssd/Makefile.am
@@ -38,7 +38,8 @@ gssd_SOURCES = \
krb5_util.h \
write_bytes.h

-gssd_LDADD = $(RPCSECGSS_LIBS) $(KRBLIBS)
+gssd_LDADD = ../../support/nfs/libnfs.a \
+ $(RPCSECGSS_LIBS) $(KRBLIBS)
gssd_LDFLAGS = $(KRBLDFLAGS)

gssd_CFLAGS = $(AM_CFLAGS) $(CFLAGS) \
diff --git a/utils/gssd/err_util.c b/utils/gssd/err_util.c
index f331432..5644db6 100644
--- a/utils/gssd/err_util.c
+++ b/utils/gssd/err_util.c
@@ -30,64 +30,33 @@

#include <stdio.h>
#include <stdarg.h>
-#include <syslog.h>
#include <string.h>
-#include "err_util.h"
+#include "xlog.h"

static int verbosity = 0;
static int fg = 0;

-static char message_buf[500];
-
void initerr(char *progname, int set_verbosity, int set_fg)
{
verbosity = set_verbosity;
fg = set_fg;
if (!fg)
- openlog(progname, LOG_PID, LOG_DAEMON);
+ xlog_open(progname);
}


void printerr(int priority, char *format, ...)
{
va_list args;
- int ret;
- int buf_used, buf_available;
- char *buf;

/* Don't bother formatting a message we're never going to print! */
if (priority > verbosity)
return;

- buf_used = strlen(message_buf);
- /* subtract 4 to leave room for "...\n" if necessary */
- buf_available = sizeof(message_buf) - buf_used - 4;
- buf = message_buf + buf_used;
-
- /*
- * Aggregate lines: only print buffer when we get to the
- * end of a line or run out of space
- */
va_start(args, format);
- ret = vsnprintf(buf, buf_available, format, args);
+ if (fg)
+ vfprintf(stderr, format, args);
+ else
+ xlog_backend(L_ERROR, format, args);
va_end(args);
-
- if (ret < 0)
- goto printit;
- if (ret >= buf_available) {
- /* Indicate we're truncating */
- strcat(message_buf, "...\n");
- goto printit;
- }
- if (message_buf[strlen(message_buf) - 1] == '\n')
- goto printit;
- return;
-printit:
- if (fg) {
- fprintf(stderr, "%s", message_buf);
- } else {
- syslog(LOG_ERR, "%s", message_buf);
- }
- /* reset the buffer */
- memset(message_buf, 0, sizeof(message_buf));
}
diff --git a/utils/idmapd/idmapd.c b/utils/idmapd/idmapd.c
index a82cd0b..355c6e1 100644
--- a/utils/idmapd/idmapd.c
+++ b/utils/idmapd/idmapd.c
@@ -55,7 +55,6 @@
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
-#include <syslog.h>
#include <pwd.h>
#include <grp.h>
#include <limits.h>
@@ -66,6 +65,7 @@
#include "config.h"
#endif /* HAVE_CONFIG_H */

+#include "xlog.h"
#include "cfg.h"
#include "queue.h"
#include "nfslib.h"
@@ -187,71 +187,6 @@ flush_nfsd_idmap_cache(void)
return ret;
}

-static void
-msg_format(char *rtnbuff, int rtnbuffsize, int errval,
- const char *fmt, va_list args)
-{
- char buff[1024];
- int n;
-
- vsnprintf(buff, sizeof(buff), fmt, args);
-
- if ((n = strlen(buff)) > 0 && buff[n-1] == '\n')
- buff[--n] = '\0';
-
- snprintf(rtnbuff, rtnbuffsize, "%s: %s", buff, strerror(errval));
-}
-
-static void
-idmapd_warn(const char *fmt, ...)
-{
- int errval = errno; /* save this! */
- char buff[1024];
- va_list args;
-
- va_start(args, fmt);
- msg_format(buff, sizeof(buff), errval, fmt, args);
- va_end(args);
-
- syslog(LOG_WARNING, "%s", buff);
-}
-
-static void
-idmapd_warnx(const char *fmt, ...)
-{
- va_list args;
-
- va_start(args, fmt);
- vsyslog(LOG_WARNING, fmt, args);
- va_end(args);
-}
-
-static void
-idmapd_err(int eval, const char *fmt, ...)
-{
- int errval = errno; /* save this! */
- char buff[1024];
- va_list args;
-
- va_start(args, fmt);
- msg_format(buff, sizeof(buff), errval, fmt, args);
- va_end(args);
-
- syslog(LOG_ERR, "%s", buff);
- exit(eval);
-}
-
-static void
-idmapd_errx(int eval, const char *fmt, ...)
-{
- va_list args;
-
- va_start(args, fmt);
- vsyslog(LOG_ERR, fmt, args);
- va_end(args);
- exit(eval);
-}
-
int
main(int argc, char **argv)
{
@@ -276,7 +211,7 @@ main(int argc, char **argv)
progname++;
else
progname = argv[0];
- openlog(progname, LOG_PID, LOG_DAEMON);
+ xlog_open(progname);

#define GETOPTSTR "vfd:p:U:G:c:CS"
opterr=0; /* Turn off error messages */
@@ -347,7 +282,7 @@ main(int argc, char **argv)
nobodygid = gr->gr_gid;

#ifdef HAVE_NFS4_SET_DEBUG
- nfs4_set_debug(verbose, idmapd_warnx);
+ nfs4_set_debug(verbose, xlog_warn);
#endif
if (conf_path == NULL)
conf_path = _PATH_IDMAPDCONF;
@@ -360,15 +295,14 @@ main(int argc, char **argv)
event_init();

if (verbose > 0)
- idmapd_warnx("Expiration time is %d seconds.",
+ xlog_warn("Expiration time is %d seconds.",
cache_entry_expiration);
if (serverstart) {
nfsdret = nfsdopen();
if (nfsdret == 0) {
ret = flush_nfsd_idmap_cache();
if (ret)
- idmapd_errx(1,
- "main: Failed to flush nfsd idmap cache\n");
+ xlog_err("main: Failed to flush nfsd idmap cache\n: %s", strerror(errno));
}
}

@@ -383,7 +317,7 @@ main(int argc, char **argv)
char timeout_buf[12];
if ((timeout_fd = open(CLIENT_CACHE_TIMEOUT_FILE,
O_RDWR)) == -1) {
- idmapd_warnx("Unable to open '%s' to set "
+ xlog_warn("Unable to open '%s' to set "
"client cache expiration time "
"to %d seconds\n",
CLIENT_CACHE_TIMEOUT_FILE,
@@ -392,7 +326,7 @@ main(int argc, char **argv)
len = snprintf(timeout_buf, sizeof(timeout_buf),
"%d", cache_entry_expiration);
if ((write(timeout_fd, timeout_buf, len)) != len)
- idmapd_warnx("Error writing '%s' to "
+ xlog_warn("Error writing '%s' to "
"'%s' to set client "
"cache expiration time\n",
timeout_buf,
@@ -402,14 +336,14 @@ main(int argc, char **argv)
}

if ((fd = open(pipefsdir, O_RDONLY)) == -1)
- idmapd_err(1, "main: open(%s)", pipefsdir);
+ xlog_err("main: open(%s): %s", pipefsdir, strerror(errno));

if (fcntl(fd, F_SETSIG, SIGUSR1) == -1)
- idmapd_err(1, "main: fcntl(%s)", pipefsdir);
+ xlog_err("main: fcntl(%s): %s", pipefsdir, strerror(errno));

if (fcntl(fd, F_NOTIFY,
DN_CREATE | DN_DELETE | DN_MODIFY | DN_MULTISHOT) == -1)
- idmapd_err(1, "main: fcntl(%s)", pipefsdir);
+ xlog_err("main: fcntl(%s): %s", pipefsdir, strerror(errno));

TAILQ_INIT(&icq);

@@ -429,12 +363,12 @@ main(int argc, char **argv)
}

if (nfsdret != 0 && fd == 0)
- idmapd_errx(1, "main: Neither NFS client nor NFSd found");
+ xlog_err("main: Neither NFS client nor NFSd found");

release_parent();

if (event_dispatch() < 0)
- idmapd_errx(1, "main: event_dispatch returns errno %d (%s)",
+ xlog_err("main: event_dispatch returns errno %d (%s)",
errno, strerror(errno));
/* NOTREACHED */
return 1;
@@ -451,7 +385,7 @@ dirscancb(int fd, short which, void *data)

nent = scandir(pipefsdir, &ents, NULL, alphasort);
if (nent == -1) {
- idmapd_warn("dirscancb: scandir(%s)", pipefsdir);
+ xlog_warn("dirscancb: scandir(%s): %s", pipefsdir, strerror(errno));
return;
}

@@ -473,7 +407,7 @@ dirscancb(int fd, short which, void *data)
pipefsdir, ents[i]->d_name);

if ((ic->ic_dirfd = open(path, O_RDONLY, 0)) == -1) {
- idmapd_warn("dirscancb: open(%s)", path);
+ xlog_warn("dirscancb: open(%s): %s", path, strerror(errno));
free(ic);
goto out;
}
@@ -482,7 +416,7 @@ dirscancb(int fd, short which, void *data)
strlcpy(ic->ic_path, path, sizeof(ic->ic_path));

if (verbose > 0)
- idmapd_warnx("New client: %s", ic->ic_clid);
+ xlog_warn("New client: %s", ic->ic_clid);

if (nfsopen(ic) == -1) {
close(ic->ic_dirfd);
@@ -508,8 +442,8 @@ dirscancb(int fd, short which, void *data)
close(ic->ic_dirfd);
TAILQ_REMOVE(icq, ic, ic_next);
if (verbose > 0) {
- idmapd_warnx("Stale client: %s", ic->ic_clid);
- idmapd_warnx("\t-> closed %s", ic->ic_path);
+ xlog_warn("Stale client: %s", ic->ic_clid);
+ xlog_warn("\t-> closed %s", ic->ic_path);
}
free(ic);
} else
@@ -560,7 +494,7 @@ nfsdcb(int fd, short which, void *data)
goto out;

if ((len = read(ic->ic_fd, buf, sizeof(buf))) <= 0) {
- idmapd_warnx("nfsdcb: read(%s) failed: errno %d (%s)",
+ xlog_warn("nfsdcb: read(%s) failed: errno %d (%s)",
ic->ic_path, len?errno:0,
len?strerror(errno):"End of File");
goto out;
@@ -574,15 +508,15 @@ nfsdcb(int fd, short which, void *data)

/* Authentication name -- ignored for now*/
if (getfield(&bp, authbuf, sizeof(authbuf)) == -1) {
- idmapd_warnx("nfsdcb: bad authentication name in upcall\n");
+ xlog_warn("nfsdcb: bad authentication name in upcall\n");
return;
}
if (getfield(&bp, typebuf, sizeof(typebuf)) == -1) {
- idmapd_warnx("nfsdcb: bad type in upcall\n");
+ xlog_warn("nfsdcb: bad type in upcall\n");
return;
}
if (verbose > 0)
- idmapd_warnx("nfsdcb: authbuf=%s authtype=%s",
+ xlog_warn("nfsdcb: authbuf=%s authtype=%s",
authbuf, typebuf);

im.im_type = strcmp(typebuf, "user") == 0 ?
@@ -592,26 +526,26 @@ nfsdcb(int fd, short which, void *data)
case IC_NAMEID:
im.im_conv = IDMAP_CONV_NAMETOID;
if (getfield(&bp, im.im_name, sizeof(im.im_name)) == -1) {
- idmapd_warnx("nfsdcb: bad name in upcall\n");
+ xlog_warn("nfsdcb: bad name in upcall\n");
return;
}
break;
case IC_IDNAME:
im.im_conv = IDMAP_CONV_IDTONAME;
if (getfield(&bp, buf1, sizeof(buf1)) == -1) {
- idmapd_warnx("nfsdcb: bad id in upcall\n");
+ xlog_warn("nfsdcb: bad id in upcall\n");
return;
}
tmp = strtoul(buf1, (char **)NULL, 10);
im.im_id = (u_int32_t)tmp;
if ((tmp == ULONG_MAX && errno == ERANGE)
|| (unsigned long)im.im_id != tmp) {
- idmapd_warnx("nfsdcb: id '%s' too big!\n", buf1);
+ xlog_warn("nfsdcb: id '%s' too big!\n", buf1);
return;
}
break;
default:
- idmapd_warnx("nfsdcb: Unknown which type %d", ic->ic_which);
+ xlog_warn("nfsdcb: Unknown which type %d", ic->ic_which);
return;
}

@@ -672,14 +606,14 @@ nfsdcb(int fd, short which, void *data)

break;
default:
- idmapd_warnx("nfsdcb: Unknown which type %d", ic->ic_which);
+ xlog_warn("nfsdcb: Unknown which type %d", ic->ic_which);
return;
}

bsiz = sizeof(buf) - bsiz;

if (atomicio((void*)write, ic->ic_fd, buf, bsiz) != bsiz)
- idmapd_warnx("nfsdcb: write(%s) failed: errno %d (%s)",
+ xlog_warn("nfsdcb: write(%s) failed: errno %d (%s)",
ic->ic_path, errno, strerror(errno));

out:
@@ -693,7 +627,7 @@ imconv(struct idmap_client *ic, struct idmap_msg *im)
case IDMAP_CONV_IDTONAME:
idtonameres(im);
if (verbose > 1)
- idmapd_warnx("%s %s: (%s) id \"%d\" -> name \"%s\"",
+ xlog_warn("%s %s: (%s) id \"%d\" -> name \"%s\"",
ic->ic_id, ic->ic_clid,
im->im_type == IDMAP_TYPE_USER ? "user" : "group",
im->im_id, im->im_name);
@@ -705,13 +639,13 @@ imconv(struct idmap_client *ic, struct idmap_msg *im)
}
nametoidres(im);
if (verbose > 1)
- idmapd_warnx("%s %s: (%s) name \"%s\" -> id \"%d\"",
+ xlog_warn("%s %s: (%s) name \"%s\" -> id \"%d\"",
ic->ic_id, ic->ic_clid,
im->im_type == IDMAP_TYPE_USER ? "user" : "group",
im->im_name, im->im_id);
break;
default:
- idmapd_warnx("imconv: Invalid conversion type (%d) in message",
+ xlog_warn("imconv: Invalid conversion type (%d) in message",
im->im_conv);
im->im_status |= IDMAP_STATUS_INVALIDMSG;
break;
@@ -729,7 +663,7 @@ nfscb(int fd, short which, void *data)

if (atomicio(read, ic->ic_fd, &im, sizeof(im)) != sizeof(im)) {
if (verbose > 0)
- idmapd_warn("nfscb: read(%s)", ic->ic_path);
+ xlog_warn("nfscb: read(%s): %s", ic->ic_path, strerror(errno));
if (errno == EPIPE)
return;
goto out;
@@ -745,7 +679,7 @@ nfscb(int fd, short which, void *data)
im.im_status = IDMAP_STATUS_SUCCESS;

if (atomicio((void*)write, ic->ic_fd, &im, sizeof(im)) != sizeof(im))
- idmapd_warn("nfscb: write(%s)", ic->ic_path);
+ xlog_warn("nfscb: write(%s): %s", ic->ic_path, strerror(errno));
out:
event_add(&ic->ic_event, NULL);
}
@@ -756,7 +690,7 @@ nfsdreopen_one(struct idmap_client *ic)
int fd;

if (verbose > 0)
- idmapd_warnx("ReOpening %s", ic->ic_path);
+ xlog_warn("ReOpening %s", ic->ic_path);

if ((fd = open(ic->ic_path, O_RDWR, 0)) != -1) {
if ((ic->ic_event.ev_flags & EVLIST_INIT))
@@ -768,7 +702,7 @@ nfsdreopen_one(struct idmap_client *ic)
event_set(&ic->ic_event, ic->ic_fd, EV_READ, nfsdcb, ic);
event_add(&ic->ic_event, NULL);
} else {
- idmapd_warnx("nfsdreopen: Opening '%s' failed: errno %d (%s)",
+ xlog_warn("nfsdreopen: Opening '%s' failed: errno %d (%s)",
ic->ic_path, errno, strerror(errno));
}
}
@@ -793,7 +727,7 @@ nfsdopenone(struct idmap_client *ic)
{
if ((ic->ic_fd = open(ic->ic_path, O_RDWR, 0)) == -1) {
if (verbose > 0)
- idmapd_warnx("nfsdopenone: Opening %s failed: "
+ xlog_warn("nfsdopenone: Opening %s failed: "
"errno %d (%s)",
ic->ic_path, errno, strerror(errno));
return (-1);
@@ -803,7 +737,7 @@ nfsdopenone(struct idmap_client *ic)
event_add(&ic->ic_event, NULL);

if (verbose > 0)
- idmapd_warnx("Opened %s", ic->ic_path);
+ xlog_warn("Opened %s", ic->ic_path);

return (0);
}
@@ -819,7 +753,7 @@ nfsopen(struct idmap_client *ic)
DN_CREATE | DN_DELETE | DN_MULTISHOT);
break;
default:
- idmapd_warn("nfsopen: open(%s)", ic->ic_path);
+ xlog_warn("nfsopen: open(%s): %s", ic->ic_path, strerror(errno));
return (-1);
}
} else {
@@ -828,7 +762,7 @@ nfsopen(struct idmap_client *ic)
fcntl(ic->ic_dirfd, F_SETSIG, 0);
fcntl(ic->ic_dirfd, F_NOTIFY, 0);
if (verbose > 0)
- idmapd_warnx("Opened %s", ic->ic_path);
+ xlog_warn("Opened %s", ic->ic_path);
}

return (0);


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

2007-10-12 20:35:16

by Kevin Coffman

[permalink] [raw]
Subject: [PATCH 7/9] Cleanup xlog logging code to be safe and usable for all

From: Kevin Coffman <[email protected]>

This patch reworks the xlog logging code to avoid rebuilding the message into a
fixed size buffer. It also adds two new logging functions xlog_warn and
xlog_err which are replacements for idmap_warn and idmap_err. There use to be
two different variates of these functions with the only difference being that
one flavor tacked on the error string to the end of the message. This
responsibility has been pushed to the called of the function since it
needlessly complicated the function and required us to rebuild the message
strings.

Signed-off-by: David P. Quigley <[email protected]>
Signed-off-by: Kevin Coffman <[email protected]>
---

support/include/xlog.h | 5 ++++
support/nfs/xlog.c | 64 ++++++++++++++++++++++++++++++++----------------
2 files changed, 48 insertions(+), 21 deletions(-)

diff --git a/support/include/xlog.h b/support/include/xlog.h
index cf9bc91..fd1a3f4 100644
--- a/support/include/xlog.h
+++ b/support/include/xlog.h
@@ -7,6 +7,8 @@
#ifndef XLOG_H
#define XLOG_H

+#include <stdarg.h>
+
/* These are logged always. L_FATAL also does exit(1) */
#define L_FATAL 0x0100
#define L_ERROR 0x0200
@@ -40,5 +42,8 @@ void xlog_config(int fac, int on);
void xlog_sconfig(char *, int on);
int xlog_enabled(int fac);
void xlog(int fac, const char *fmt, ...);
+void xlog_warn(const char *fmt, ...);
+void xlog_err(const char *fmt, ...);
+void xlog_backend(int fac, const char *fmt, va_list args);

#endif /* XLOG_H */
diff --git a/support/nfs/xlog.c b/support/nfs/xlog.c
index 1bbfd19..26123c5 100644
--- a/support/nfs/xlog.c
+++ b/support/nfs/xlog.c
@@ -131,39 +131,28 @@ xlog_enabled(int fac)

/* Write something to the system logfile and/or stderr */
void
-xlog(int kind, const char *fmt, ...)
+xlog_backend(int kind, const char *fmt, va_list args)
{
- char buff[1024];
- va_list args;
- int n;
-
if (!(kind & (L_ALL)) && !(logging && (kind & logmask)))
return;

- va_start(args, fmt);
- vsnprintf(buff, sizeof (buff), fmt, args);
- va_end(args);
-
- if ((n = strlen(buff)) > 0 && buff[n-1] == '\n')
- buff[--n] = '\0';
-
if (log_syslog) {
switch (kind) {
case L_FATAL:
- syslog(LOG_ERR, "%s", buff);
+ vsyslog(LOG_ERR, fmt, args);
break;
case L_ERROR:
- syslog(LOG_ERR, "%s", buff);
+ vsyslog(LOG_ERR, fmt, args);
break;
case L_WARNING:
- syslog(LOG_WARNING, "%s", buff);
+ vsyslog(LOG_WARNING, fmt, args);
break;
case L_NOTICE:
- syslog(LOG_NOTICE, "%s", buff);
+ vsyslog(LOG_NOTICE, fmt, args);
break;
default:
if (!log_stderr)
- syslog(LOG_INFO, "%s", buff);
+ vsyslog(LOG_INFO, fmt, args);
break;
}
}
@@ -175,16 +164,49 @@ xlog(int kind, const char *fmt, ...)

time(&now);
tm = localtime(&now);
- fprintf(stderr, "%s[%d] %04d-%02d-%02d %02d:%02d:%02d %s\n",
+ fprintf(stderr, "%s[%d] %04d-%02d-%02d %02d:%02d:%02d ",
log_name, log_pid,
tm->tm_year+1900, tm->tm_mon + 1, tm->tm_mday,
- tm->tm_hour, tm->tm_min, tm->tm_sec,
- buff);
+ tm->tm_hour, tm->tm_min, tm->tm_sec);
#else
- fprintf(stderr, "%s: %s\n", log_name, buff);
+ fprintf(stderr, "%s: ", log_name);
#endif
+
+ vfprintf(stderr, fmt, args);
+ fprintf(stderr, "\n");
}

if (kind == L_FATAL)
exit(1);
}
+
+void
+xlog(int kind, const char* fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ xlog_backend(kind, fmt, args);
+ va_end(args);
+}
+
+void
+xlog_warn(const char* fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ xlog_backend(L_WARNING, fmt, args);
+ va_end(args);
+}
+
+
+void
+xlog_err(const char* fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ xlog_backend(L_FATAL, fmt, args);
+ va_end(args);
+}


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

2007-10-14 23:53:43

by NeilBrown

[permalink] [raw]
Subject: Re: [PATCH 0/9] nfs-utils logging and extra code clean-up

On Friday October 12, [email protected] wrote:
> Hi Neil,
>
> These patches clean up logging code and eliminate duplicate and
> unused code.

All applied, thanks.

NeilBrown

>
> 01 svcgssd_fix_prototype_warning
> Cleans up a new compiler warning that appeared after
> -Wstrict-prototypes was added to the compile options
>
> 02 svcgssd_print_hexl_debug_stdout
> Change debugging to use printf instead of logging
> function. (In preparation of David's patches below.)
>
> 03 svcgssd_debug_downcall_info
> Change svcgssd to print its own debug info rather
> than relying on modified qword_ functions.
>
> 04 nfslib_cacheio_updates_for_svcgssd
> Move local cacheio functions from svcgssd into the
> common library.
> Modify the library read function to use a bigger
> buffer as needed by svcgssd.
>
> 05 svcgssd_use_common_cacheio_support
> svcgssd now uses the common functions rather than
> local modified copies.
>
> 06 svcgssd_remove_private_cacheio
> Remove the private copies in svcgssd
>
> 07 xlog_logging_code_cleanup
> 08 idmapd_gssd_use_xlog
> 09 idmapd_remove_setproctitle
>
> These patches are from David P. Quigley <[email protected]>
> 07 clean up the xlog code
> 08 modify idmapd and gssd to use the cleaned up code, and
> 09 remove unused code from idmapd.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs