Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/nfsd Expose debugging
details: https://anonhg.NetBSD.org/src/rev/32515815e9cb
branches: trunk
changeset: 344234:32515815e9cb
user: christos <christos%NetBSD.org@localhost>
date: Thu Mar 17 15:25:46 2016 +0000
description:
Expose debugging
diffstat:
usr.sbin/nfsd/nfsd.8 | 8 ++++--
usr.sbin/nfsd/nfsd.c | 60 +++++++++++++++++++++++++++++----------------------
2 files changed, 39 insertions(+), 29 deletions(-)
diffs (251 lines):
diff -r 6973370af23c -r 32515815e9cb usr.sbin/nfsd/nfsd.8
--- a/usr.sbin/nfsd/nfsd.8 Thu Mar 17 15:23:21 2016 +0000
+++ b/usr.sbin/nfsd/nfsd.8 Thu Mar 17 15:25:46 2016 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: nfsd.8,v 1.23 2012/08/13 08:39:28 wiz Exp $
+.\" $NetBSD: nfsd.8,v 1.24 2016/03/17 15:25:46 christos Exp $
.\"
.\" Copyright (c) 1989, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -29,7 +29,7 @@
.\"
.\" @(#)nfsd.8 8.4 (Berkeley) 3/29/95
.\"
-.Dd August 12, 2012
+.Dd March 17, 2016
.Dt NFSD 8
.Os
.Sh NAME
@@ -39,7 +39,7 @@
server
.Sh SYNOPSIS
.Nm
-.Op Fl 46rut
+.Op Fl 46drut
.Op Fl n Ar num_threads
.Sh DESCRIPTION
.Nm
@@ -56,6 +56,8 @@
.Pp
The following options are available:
.Bl -tag -width Ds
+.It Fl d
+Turn on debugging, don't fork and log to stderr.
.It Fl r
Register the
.Tn NFS
diff -r 6973370af23c -r 32515815e9cb usr.sbin/nfsd/nfsd.c
--- a/usr.sbin/nfsd/nfsd.c Thu Mar 17 15:23:21 2016 +0000
+++ b/usr.sbin/nfsd/nfsd.c Thu Mar 17 15:25:46 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nfsd.c,v 1.65 2015/12/23 18:41:54 christos Exp $ */
+/* $NetBSD: nfsd.c,v 1.66 2016/03/17 15:25:46 christos Exp $ */
/*
* Copyright (c) 1989, 1993, 1994
@@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)nfsd.c 8.9 (Berkeley) 3/29/95";
#else
-__RCSID("$NetBSD: nfsd.c,v 1.65 2015/12/23 18:41:54 christos Exp $");
+__RCSID("$NetBSD: nfsd.c,v 1.66 2016/03/17 15:25:46 christos Exp $");
#endif
#endif /* not lint */
@@ -100,16 +100,21 @@
/* Global defs */
#if defined(DEBUG) || defined(NFSD_RUMP)
-#define syslog(e, s, args...) \
-do { \
- fprintf(stderr,(s), ## args); \
- fprintf(stderr, "\n"); \
-} while (/*CONSTCOND*/0)
static int debug = 1;
#else
static int debug = 0;
#endif
+#define logit(e, s, args...) \
+do { \
+ if (debug) { \
+ fprintf(stderr,(s), ## args); \
+ fprintf(stderr, "\n"); \
+ } else { \
+ syslog(e, s, ## args); \
+ } \
+} while (/*CONSTCOND*/0)
+
static void nonfs(int);
__dead static void usage(void);
@@ -124,7 +129,7 @@
memset(&nsd, 0, sizeof(nsd));
while (nfssvc(nfssvc_flag, &nsd) < 0) {
if (errno != ENEEDAUTH) {
- syslog(LOG_ERR, "nfssvc: %s", strerror(errno));
+ logit(LOG_ERR, "nfssvc: %s", strerror(errno));
exit(1);
}
nfssvc_flag = NFSSVC_NFSD | NFSSVC_AUTHINFAIL;
@@ -166,7 +171,7 @@
ecode = getaddrinfo(NULL, "nfs", &hints, &cfg->ai);
if (ecode != 0) {
- syslog(LOG_ERR, "getaddrinfo %s: %s", cfg_netconf[t],
+ logit(LOG_ERR, "getaddrinfo %s: %s", cfg_netconf[t],
gai_strerror(ecode));
return -1;
}
@@ -174,7 +179,7 @@
cfg->nc = getnetconfigent(cfg_netconf[t]);
if (cfg->nc == NULL) {
- syslog(LOG_ERR, "getnetconfigent %s failed: %s",
+ logit(LOG_ERR, "getnetconfigent %s failed: %s",
cfg_netconf[t], strerror(errno));
goto out;
}
@@ -183,7 +188,7 @@
cfg->nb.len = cfg->nb.maxlen = cfg->ai->ai_addrlen;
if (reregister)
if (!rpcb_set(RPCPROG_NFS, 2, cfg->nc, &cfg->nb)) {
- syslog(LOG_ERR, "rpcb_set %s failed", cfg_netconf[t]);
+ logit(LOG_ERR, "rpcb_set %s failed", cfg_netconf[t]);
goto out1;
}
return 0;
@@ -207,14 +212,14 @@
sock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
if (sock == -1) {
- syslog(LOG_ERR, "can't create %s socket: %s", cfg_netconf[p],
+ logit(LOG_ERR, "can't create %s socket: %s", cfg_netconf[p],
strerror(errno));
return -1;
}
if (cfg_family[p] == PF_INET6) {
if (setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, &on,
sizeof(on)) == -1) {
- syslog(LOG_ERR, "can't set v6-only binding for %s "
+ logit(LOG_ERR, "can't set v6-only binding for %s "
"socket: %s", cfg_netconf[p], strerror(errno));
goto out;
}
@@ -223,28 +228,28 @@
if (cfg_protocol[p] == IPPROTO_TCP) {
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on,
sizeof(on)) == -1) {
- syslog(LOG_ERR, "setsockopt SO_REUSEADDR for %s: %s",
+ logit(LOG_ERR, "setsockopt SO_REUSEADDR for %s: %s",
cfg_netconf[p], strerror(errno));
goto out;
}
}
if (bind(sock, ai->ai_addr, ai->ai_addrlen) == -1) {
- syslog(LOG_ERR, "can't bind %s addr: %s", cfg_netconf[p],
+ logit(LOG_ERR, "can't bind %s addr: %s", cfg_netconf[p],
strerror(errno));
goto out;
}
if (cfg_protocol[p] == IPPROTO_TCP) {
if (listen(sock, 5) == -1) {
- syslog(LOG_ERR, "listen failed");
+ logit(LOG_ERR, "listen failed");
goto out;
}
}
if (!rpcb_set(RPCPROG_NFS, 2, cfg->nc, &cfg->nb) ||
!rpcb_set(RPCPROG_NFS, 3, cfg->nc, &cfg->nb)) {
- syslog(LOG_ERR, "can't register with %s portmap",
+ logit(LOG_ERR, "can't register with %s portmap",
cfg_netconf[p]);
goto out;
}
@@ -257,7 +262,7 @@
nfsdargs.name = NULL;
nfsdargs.namelen = 0;
if (nfssvc(NFSSVC_ADDSOCK, &nfsdargs) < 0) {
- syslog(LOG_ERR, "can't add %s socket: %s",
+ logit(LOG_ERR, "can't add %s socket: %s",
cfg_netconf[p], strerror(errno));
goto out;
}
@@ -425,8 +430,8 @@
compat = reregister = 0;
tcpflag = udpflag = 1;
ip6flag = ip4flag = 1;
-#define GETOPT "46n:rtu"
-#define USAGE "[-46rtu] [-n num_servers]"
+#define GETOPT "46dn:rtu"
+#define USAGE "[-46drtu] [-n num_servers]"
while ((ch = getopt(argc, argv, GETOPT)) != -1) {
switch (ch) {
case '6':
@@ -449,6 +454,9 @@
else
close(s);
break;
+ case 'd':
+ debug++;
+ break;
case 'n':
nfsdcnt = atoi(optarg);
if (nfsdcnt < 1) {
@@ -489,9 +497,9 @@
if (debug == 0) {
parent_fd = daemon2_fork();
+ openlog("nfsd", LOG_PID, LOG_DAEMON);
}
- openlog("nfsd", LOG_PID, LOG_DAEMON);
memset(cfg, 0, sizeof(cfg));
for (i = 0; i < __arraycount(cfg); i++) {
@@ -513,7 +521,7 @@
error = pthread_create(&t, NULL, worker, NULL);
if (error) {
errno = error;
- syslog(LOG_ERR, "pthread_create: %s", strerror(errno));
+ logit(LOG_ERR, "pthread_create: %s", strerror(errno));
exit(1);
}
}
@@ -552,7 +560,7 @@
*/
for (;;) {
if (poll(set, __arraycount(set), INFTIM) == -1) {
- syslog(LOG_ERR, "poll failed: %s", strerror(errno));
+ logit(LOG_ERR, "poll failed: %s", strerror(errno));
exit(1);
}
@@ -569,7 +577,7 @@
if ((msgsock = accept(set[i].fd,
(struct sockaddr *)&ss, &len)) == -1) {
int serrno = errno;
- syslog(LOG_ERR, "accept failed: %s",
+ logit(LOG_ERR, "accept failed: %s",
strerror(errno));
if (serrno == EINTR || serrno == ECONNABORTED)
continue;
@@ -577,7 +585,7 @@
}
if (setsockopt(msgsock, SOL_SOCKET, SO_KEEPALIVE, &on,
sizeof(on)) == -1)
- syslog(LOG_ERR, "setsockopt SO_KEEPALIVE: %s",
+ logit(LOG_ERR, "setsockopt SO_KEEPALIVE: %s",
strerror(errno));
nfsdargs.sock = msgsock;
nfsdargs.name = (void *)&ss;
@@ -598,5 +606,5 @@
static void
nonfs(int signo)
{
- syslog(LOG_ERR, "missing system call: NFS not available.");
+ logit(LOG_ERR, "missing system call: NFS not available.");
}
Home |
Main Index |
Thread Index |
Old Index