Use err(3). Add usage() and #includes.

This commit is contained in:
Philippe Charnier 1997-10-13 11:13:33 +00:00
parent 5dbfe9a138
commit df82e9ba02
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=30376
10 changed files with 107 additions and 104 deletions

View File

@ -31,7 +31,10 @@
*
*/
#ifndef lint
static const char rcsid[] =
"$Id$";
#endif /* not lint */
#include "nlm_prot.h"

View File

@ -31,19 +31,29 @@
*
*/
#ifndef lint
static const char rcsid[] =
"$Id$";
#endif /* not lint */
/* main() function for NFS lock daemon. Most of the code in this */
/* file was generated by running rpcgen /usr/include/rpcsvc/nlm_prot.x */
/* The actual program logic is in the file procs.c */
#include <err.h>
#include <stdlib.h>
#include <string.h>
#include <rpc/rpc.h>
#include <rpc/pmap_clnt.h>
#include "lockd.h"
void nlm_prog_1 __P((struct svc_req *, SVCXPRT *));
void nlm_prog_3 __P((struct svc_req *, SVCXPRT *));
static void usage __P((void));
int debug_level = 0; /* Zero means no debugging syslog() calls */
int
main(int argc, char **argv)
{
SVCXPRT *transp;
@ -51,10 +61,7 @@ main(int argc, char **argv)
if (argc > 1)
{
if (strncmp(argv[1], "-d", 2))
{
fprintf(stderr, "Usage: rpc.lockd [-d [<debuglevel>]]\n");
exit(1);
}
usage();
if (argc > 2) debug_level = atoi(argv[2]);
else debug_level = atoi(argv[1] + 2);
/* Ensure at least some debug if -d with no specified level */
@ -66,44 +73,24 @@ main(int argc, char **argv)
transp = svcudp_create(RPC_ANYSOCK);
if (transp == NULL)
{
(void)fprintf(stderr, "cannot create udp service.\n");
exit(1);
}
errx(1, "cannot create udp service");
if (!svc_register(transp, NLM_PROG, NLM_VERS, nlm_prog_1, IPPROTO_UDP))
{
(void)fprintf(stderr, "unable to register (NLM_PROG, NLM_VERS, udp).\n");
exit(1);
}
errx(1, "unable to register (NLM_PROG, NLM_VERS, udp)");
if (!svc_register(transp, NLM_PROG, NLM_VERSX, nlm_prog_3, IPPROTO_UDP))
{
(void)fprintf(stderr, "unable to register (NLM_PROG, NLM_VERSX, udp).\n");
exit(1);
}
errx(1, "unable to register (NLM_PROG, NLM_VERSX, udp)");
transp = svctcp_create(RPC_ANYSOCK, 0, 0);
if (transp == NULL)
{
(void)fprintf(stderr, "cannot create tcp service.\n");
exit(1);
}
errx(1, "cannot create tcp service");
if (!svc_register(transp, NLM_PROG, NLM_VERS, nlm_prog_1, IPPROTO_TCP))
{
(void)fprintf(stderr, "unable to register (NLM_PROG, NLM_VERS, tcp).\n");
exit(1);
}
errx(1, "unable to register (NLM_PROG, NLM_VERS, tcp)");
if (!svc_register(transp, NLM_PROG, NLM_VERSX, nlm_prog_3, IPPROTO_TCP))
{
(void)fprintf(stderr, "unable to register (NLM_PROG, NLM_VERSX, tcp).\n");
exit(1);
}
errx(1, "unable to register (NLM_PROG, NLM_VERSX, tcp)");
/* Note that it is NOT sensible to run this program from inetd - the */
/* protocol assumes that it will run immediately at boot time. */
if (daemon(0,0)) {
perror("cannot fork");
exit(1);
}
if (daemon(0,0))
err(1, "fork");
openlog("rpc.lockd", 0, LOG_DAEMON);
if (debug_level) syslog(LOG_INFO, "Starting, debug level %d", debug_level);
else syslog(LOG_INFO, "Starting");
@ -111,3 +98,10 @@ main(int argc, char **argv)
svc_run(); /* Should never return */
exit(1);
}
static void
usage()
{
fprintf(stderr, "usage: rpc.lockd [-d [debuglevel]]\n");
exit(1);
}

View File

@ -31,8 +31,12 @@
*
*/
#ifndef lint
static const char rcsid[] =
"$Id$";
#endif /* not lint */
#include <string.h>
#include "lockd.h"
#include <sys/param.h> /* for MAXHOSTNAMELEN */
@ -205,7 +209,7 @@ static void transmit_result(int opcode, nlm_res *result, struct svc_req *req)
struct timeval timeo;
addr = svc_getcaller(req->rq_xprt);
if (cli = get_client(addr))
if ((cli = get_client(addr)))
{
timeo.tv_sec = 0; /* No timeout - not expecting response */
timeo.tv_usec = 0;
@ -284,7 +288,7 @@ void *nlm_test_msg_1_svc(nlm_testargs *arg, struct svc_req *rqstp)
/* nlm_test has different result type to the other operations, so */
/* can't use transmit_result() in this case */
addr = svc_getcaller(rqstp->rq_xprt);
if (cli = get_client(addr))
if ((cli = get_client(addr)))
{
timeo.tv_sec = 0; /* No timeout - not expecting response */
timeo.tv_usec = 0;

View File

@ -42,17 +42,14 @@
.Nm rpc.lockd
.Op Fl d Op Ar debug_level
.Sh DESCRIPTION
.Nm rpc.lockd
.Nm Rpc.lockd
is a daemon which provides file- and record-locking services in an NFS
environment.
.Pp
Options and operands available for
.Nm rpc.lockd :
.Bl -tag -width Ds
The following option is available:
.Bl -tag -width indent
.It Fl d
The
.Fl d
option causes debugging information to be written to syslog, recording
Cause debugging information to be written to syslog, recording
all RPC transactions to the daemon. These messages are logged with level
LOG_DEBUG and facility LOG_DAEMON. If debug_level is not specified,
level 1 is assumed, giving one log line per protocol operation. Higher
@ -64,7 +61,7 @@ Error conditions are logged to syslog, irrespective of the debug level,
using log level LOG_ERR and facility LOG_DAEMON.
.Pp
The
.Nm rpc.lockd
.Nm
daemon must NOT be invoked by
.Xr inetd 8
because the protocol assumes that the daemon will run from system start time.
@ -82,8 +79,12 @@ RPC protocol specification for the network lock manager protocol.
.Xr rpc.statd 8
.Sh BUGS
The current implementation provides only the server side of the protocol
(ie. clients running other OS types can establish locks on a FreeBSD fileserver,
but there is currently no means for a FreeBSD client to establish locks).
(ie. clients running other OS types can establish locks on a
.Bx Free
fileserver,
but there is currently no means for a
.Bx Free
client to establish locks).
.Pp
Versions 1, 2 and 3 of the protocol are supported. However, only versions
2 (Unix systems) and 3 (PC-NFS clients) seem to be in common use - the version

View File

@ -1,10 +1,14 @@
#ifndef lint
#if 0
static char sccsid[] = "from: @(#)nlm_prot.x 1.8 87/09/21 Copyr 1987 Sun Micro";
static char sccsid[] = "from: * @(#)nlm_prot.x 2.1 88/08/01 4.0 RPCSRC";
#endif
static const char rcsid[] =
"$Id$";
#endif /* not lint */
#include <rpc/rpc.h>
#include <rpcsvc/nlm_prot.h>
#ifndef lint
/*static char sccsid[] = "from: @(#)nlm_prot.x 1.8 87/09/21 Copyr 1987 Sun Micro";*/
/*static char sccsid[] = "from: * @(#)nlm_prot.x 2.1 88/08/01 4.0 RPCSRC";*/
static char rcsid[] = "nlm_prot.x,v 1.1 1994/08/04 19:01:48 wollman Exp";
#endif /* not lint */
/* Default timeout can be changed using clnt_control() */
static struct timeval TIMEOUT = { 0, 0 };

View File

@ -31,11 +31,12 @@
*
*/
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/mman.h> /* For mmap() */
#include <rpc/rpc.h>
@ -147,11 +148,7 @@ void init_file(char *filename)
new_file = TRUE;
}
if (status_fd < 0)
{
perror("rpc.statd");
fprintf(stderr, "Unable to open status file %s\n", filename);
exit(1);
}
errx(1, "unable to open status file %s", filename);
/* File now open. mmap() it, with a generous size to allow for */
/* later growth, where we will extend the file but not re-map it. */
@ -159,10 +156,7 @@ void init_file(char *filename)
mmap(NULL, 0x10000000, PROT_READ | PROT_WRITE, MAP_SHARED, status_fd, 0);
if (status_info == (FileLayout *) MAP_FAILED)
{
perror("rpc.statd");
fprintf(stderr, "Unable to mmap() status file\n");
}
warn("unable to mmap() status file");
status_file_len = lseek(status_fd, 0L, SEEK_END);
@ -173,7 +167,7 @@ void init_file(char *filename)
if ((status_file_len < HEADER_LEN) || (status_file_len
< (HEADER_LEN + sizeof(HostInfo) * status_info->noOfHosts)) )
{
fprintf(stderr, "rpc.statd: status file is corrupt\n");
warnx("status file is corrupt");
new_file = TRUE;
}
}

View File

@ -31,11 +31,16 @@
*
*/
#ifndef lint
static const char rcsid[] =
"$Id$";
#endif /* not lint */
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <rpc/rpc.h>
#include <syslog.h>
#include <netdb.h> /* for gethostbyname() */
@ -99,7 +104,7 @@ struct sm_stat_res *sm_mon_1_svc(mon *arg, struct svc_req *req)
{
syslog(LOG_ERR, "Invalid hostname to sm_mon: %s", arg->mon_id.mon_name);
}
else if (hp = find_host(arg->mon_id.mon_name, TRUE))
else if ((hp = find_host(arg->mon_id.mon_name, TRUE)))
{
lp = (MonList *)malloc(sizeof(MonList));
if (!lp)
@ -185,7 +190,7 @@ struct sm_stat *sm_unmon_1_svc(mon_id *arg, struct svc_req *req)
arg->my_id.my_vers, arg->my_id.my_proc);
}
if (hp = find_host(arg->mon_name, FALSE))
if ((hp = find_host(arg->mon_name, FALSE)))
{
if (do_unmon(hp, &arg->my_id)) sync_file();
else
@ -214,7 +219,6 @@ struct sm_stat *sm_unmon_all_1_svc(my_id *arg, struct svc_req *req)
{
static sm_stat res;
HostInfo *hp;
MonList *lp;
int i;
if (debug)
@ -349,4 +353,3 @@ void *sm_notify_1_svc(stat_chge *arg, struct svc_req *req)
exit (0); /* Child quits */
}

View File

@ -42,7 +42,7 @@
.Nm rpc.statd
.Op Fl d
.Sh DESCRIPTION
.Nm rpc.statd
.Nm Rpc.statd
is a daemon which co-operates with rpc.statd daemons on other hosts to provide
a status monitoring service. The daemon accepts requests from
programs running on the local host (typically,
@ -52,24 +52,21 @@ hosts. If a monitored host crashes and restarts, the remote daemon will
notify the local daemon, which in turn will notify the local program(s)
which requested the monitoring service. Conversely, if this host crashes
and re-starts, when the
.Nm rpc.statd
.Nm
re-starts, it will notify all of the hosts which were being monitored
at the time of the crash.
.Pp
Options and operands available for
.Nm rpc.statd :
.Bl -tag -width Ds
The following option is available:
.Bl -tag -width indent
.It Fl d
The
.Fl d
option causes debugging information to be written to syslog, recording
Cause debugging information to be written to syslog, recording
all RPC transactions to the daemon. These messages are logged with level
LOG_DEBUG and facility LOG_DAEMON. Error conditions are logged irrespective
of this option, using level LOG_ERR.
.El
.Pp
The
.Nm rpc.statd
.Nm
daemon must NOT be invoked by
.Xr inetd 8
because the protocol assumes that the daemon will run from system start time.

View File

@ -31,28 +31,33 @@
*
*/
#ifndef lint
static const char rcsid[] =
"$Id$";
#endif /* not lint */
/* main() function for status monitor daemon. Some of the code in this */
/* file was generated by running rpcgen /usr/include/rpcsvc/sm_inter.x */
/* The actual program logic is in the file procs.c */
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <rpc/rpc.h>
#include <rpc/pmap_clnt.h>
#include <syslog.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#include "statd.h"
#ifndef lint
static char rcsid[] = "$id: $";
#endif /* not lint */
int debug = 0; /* Controls syslog() calls for debug messages */
extern void sm_prog_1(struct svc_req *rqstp, SVCXPRT *transp);
static void handle_sigchld();
static void usage __P((void));
int
main(int argc, char **argv)
{
SVCXPRT *transp;
@ -61,10 +66,7 @@ main(int argc, char **argv)
if (argc > 1)
{
if (strcmp(argv[1], "-d"))
{
fprintf(stderr, "Usage: rpc.statd [-d]\n");
exit(1);
}
usage();
debug = 1;
}
@ -72,26 +74,15 @@ main(int argc, char **argv)
transp = svcudp_create(RPC_ANYSOCK);
if (transp == NULL)
{
fprintf(stderr, "cannot create udp service.\n");
exit(1);
}
errx(1, "cannot create udp service");
if (!svc_register(transp, SM_PROG, SM_VERS, sm_prog_1, IPPROTO_UDP))
{
fprintf(stderr, "unable to register (SM_PROG, SM_VERS, udp).\n");
exit(1);
}
errx(1, "unable to register (SM_PROG, SM_VERS, udp)");
transp = svctcp_create(RPC_ANYSOCK, 0, 0);
if (transp == NULL)
{
fprintf(stderr, "cannot create tcp service.\n");
exit(1);
}
if (!svc_register(transp, SM_PROG, SM_VERS, sm_prog_1, IPPROTO_TCP)) {
fprintf(stderr, "unable to register (SM_PROG, SM_VERS, tcp).\n");
exit(1);
}
errx(1, "cannot create tcp service");
if (!svc_register(transp, SM_PROG, SM_VERS, sm_prog_1, IPPROTO_TCP))
errx(1, "unable to register (SM_PROG, SM_VERS, tcp)");
init_file("/var/db/statd.status");
/* Note that it is NOT sensible to run this program from inetd - the */
@ -116,6 +107,12 @@ main(int argc, char **argv)
exit(1);
}
static void
usage()
{
fprintf(stderr, "usage: rpc.statd [-d]\n");
exit(1);
}
/* handle_sigchld ---------------------------------------------------------- */
/*

View File

@ -1,3 +1,9 @@
#ifndef lint
static const char rcsid[] =
"$Id$";
#endif /* not lint */
#include <stdio.h>
#include <rpc/rpc.h>
#include <rpcsvc/sm_inter.h>
@ -91,7 +97,7 @@ int main(int argc, char **argv)
if (argc < 2)
{
fprintf(stderr, "usage: test <hostname> | crash\n");
fprintf(stderr, "Always talks to statd at localhost\n");
fprintf(stderr, "always talks to statd at localhost\n");
exit(1);
}