From 8f640499e9439317b5c4c86c9e29cebdf7d2fcbd Mon Sep 17 00:00:00 2001 From: charnier Date: Mon, 13 Oct 1997 11:13:33 +0000 Subject: Use err(3). Add usage() and #includes. --- usr.sbin/rpc.statd/file.c | 20 +++++++------------ usr.sbin/rpc.statd/procs.c | 13 +++++++----- usr.sbin/rpc.statd/rpc.statd.8 | 15 ++++++-------- usr.sbin/rpc.statd/statd.c | 45 ++++++++++++++++++++---------------------- usr.sbin/rpc.statd/test.c | 8 +++++++- 5 files changed, 49 insertions(+), 52 deletions(-) (limited to 'usr.sbin/rpc.statd') diff --git a/usr.sbin/rpc.statd/file.c b/usr.sbin/rpc.statd/file.c index 5dbc1cac..b8fc5cc 100644 --- a/usr.sbin/rpc.statd/file.c +++ b/usr.sbin/rpc.statd/file.c @@ -31,11 +31,12 @@ * */ -#include -#include -#include +#include #include +#include +#include #include +#include #include #include /* For mmap() */ #include @@ -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; } } diff --git a/usr.sbin/rpc.statd/procs.c b/usr.sbin/rpc.statd/procs.c index c43f86b9..a33abd40 100644 --- a/usr.sbin/rpc.statd/procs.c +++ b/usr.sbin/rpc.statd/procs.c @@ -31,11 +31,16 @@ * */ +#ifndef lint +static const char rcsid[] = + "$Id$"; +#endif /* not lint */ +#include #include #include #include -#include +#include #include #include #include /* 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 */ } - diff --git a/usr.sbin/rpc.statd/rpc.statd.8 b/usr.sbin/rpc.statd/rpc.statd.8 index 34061be..9226b4f 100644 --- a/usr.sbin/rpc.statd/rpc.statd.8 +++ b/usr.sbin/rpc.statd/rpc.statd.8 @@ -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. diff --git a/usr.sbin/rpc.statd/statd.c b/usr.sbin/rpc.statd/statd.c index 915cab5..0c08892 100644 --- a/usr.sbin/rpc.statd/statd.c +++ b/usr.sbin/rpc.statd/statd.c @@ -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 #include +#include #include +#include #include #include #include #include #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 ---------------------------------------------------------- */ /* diff --git a/usr.sbin/rpc.statd/test.c b/usr.sbin/rpc.statd/test.c index e864485..6a6a2ff 100644 --- a/usr.sbin/rpc.statd/test.c +++ b/usr.sbin/rpc.statd/test.c @@ -1,3 +1,9 @@ + +#ifndef lint +static const char rcsid[] = + "$Id$"; +#endif /* not lint */ + #include #include #include @@ -91,7 +97,7 @@ int main(int argc, char **argv) if (argc < 2) { fprintf(stderr, "usage: test | crash\n"); - fprintf(stderr, "Always talks to statd at localhost\n"); + fprintf(stderr, "always talks to statd at localhost\n"); exit(1); } -- cgit v1.1