diff options
author | charnier <charnier@FreeBSD.org> | 1997-10-13 11:13:33 +0000 |
---|---|---|
committer | charnier <charnier@FreeBSD.org> | 1997-10-13 11:13:33 +0000 |
commit | 8f640499e9439317b5c4c86c9e29cebdf7d2fcbd (patch) | |
tree | 8551f6336b076c1eac810d9b3c0620185755588a /usr.sbin/rpc.statd | |
parent | 5b323e1a4836fcfb03b1e09ee91f62997da87f09 (diff) | |
download | FreeBSD-src-8f640499e9439317b5c4c86c9e29cebdf7d2fcbd.zip FreeBSD-src-8f640499e9439317b5c4c86c9e29cebdf7d2fcbd.tar.gz |
Use err(3). Add usage() and #includes.
Diffstat (limited to 'usr.sbin/rpc.statd')
-rw-r--r-- | usr.sbin/rpc.statd/file.c | 20 | ||||
-rw-r--r-- | usr.sbin/rpc.statd/procs.c | 13 | ||||
-rw-r--r-- | usr.sbin/rpc.statd/rpc.statd.8 | 15 | ||||
-rw-r--r-- | usr.sbin/rpc.statd/statd.c | 45 | ||||
-rw-r--r-- | usr.sbin/rpc.statd/test.c | 8 |
5 files changed, 49 insertions, 52 deletions
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 <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; } } 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 <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 */ } - 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 <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 ---------------------------------------------------------- */ /* 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 <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); } |