diff options
author | wpaul <wpaul@FreeBSD.org> | 1995-03-31 05:45:23 +0000 |
---|---|---|
committer | wpaul <wpaul@FreeBSD.org> | 1995-03-31 05:45:23 +0000 |
commit | 05513f22548c71dae8f8917421ec27c1b7b1bd14 (patch) | |
tree | 2c881580fb17586a61d645e7abf725533dbeb63c /gnu/libexec | |
parent | 256869e2ccd101dbeaa858a22b8ed9a10d99ac9a (diff) | |
download | FreeBSD-src-05513f22548c71dae8f8917421ec27c1b7b1bd14.zip FreeBSD-src-05513f22548c71dae8f8917421ec27c1b7b1bd14.tar.gz |
Rework error reporting/logging: although the SunOS documentation says
that ypxfr is supposed to log messages to /var/yp/ypxfr.log if it exists,
using syslog() makes more sense, especially since ypserv does the same
thing already. Try to use stderr by default, and use syslog() if stderr
is not a tty.
Also update the man page to reflect this change.
Diffstat (limited to 'gnu/libexec')
-rw-r--r-- | gnu/libexec/ypxfr/Makefile | 4 | ||||
-rw-r--r-- | gnu/libexec/ypxfr/log.c | 84 | ||||
-rw-r--r-- | gnu/libexec/ypxfr/yp_svc.c | 26 | ||||
-rw-r--r-- | gnu/libexec/ypxfr/yp_xdr.c | 4 | ||||
-rw-r--r-- | gnu/libexec/ypxfr/ypclnt.c | 13 | ||||
-rw-r--r-- | gnu/libexec/ypxfr/ypxfr.8 | 9 | ||||
-rw-r--r-- | gnu/libexec/ypxfr/ypxfr.c | 44 |
7 files changed, 140 insertions, 44 deletions
diff --git a/gnu/libexec/ypxfr/Makefile b/gnu/libexec/ypxfr/Makefile index 9aedf2f..460d070 100644 --- a/gnu/libexec/ypxfr/Makefile +++ b/gnu/libexec/ypxfr/Makefile @@ -1,8 +1,8 @@ -# $Id: Makefile,v 1.1 1995/01/31 09:28:38 wpaul Exp $ +# $Id: Makefile,v 1.2 1995/02/06 22:15:20 wpaul Exp $ PROG= ypxfr MAN8= ypxfr.8 -SRCS= ypxfr.c ypclnt.c yp_clnt.c yp_xdr.c +SRCS= ypxfr.c ypclnt.c yp_clnt.c yp_xdr.c log.c .include <bsd.prog.mk> diff --git a/gnu/libexec/ypxfr/log.c b/gnu/libexec/ypxfr/log.c new file mode 100644 index 0000000..7b76a2a --- /dev/null +++ b/gnu/libexec/ypxfr/log.c @@ -0,0 +1,84 @@ +/* + * Copyright (c) 1995 + * Bill Paul <wpaul@ctr.columbia.edu>. 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 Bill Paul. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``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. + * + */ +/* + * error logging/reporting facilities + * stolen from /usr/libexec/mail.local via ypserv + * + * $Id$ + */ + +#include <stdio.h> +#include <sys/types.h> +#include <syslog.h> + +extern int logflag; +extern char *progname; + +#if __STDC__ +#include <stdarg.h> +#else +#include <varargs.h> +#endif + +void verr(fmt, ap) + const char *fmt; + _BSD_VA_LIST_ ap; + +{ + if (logflag) + vsyslog(LOG_NOTICE, fmt, ap); + else + { + fprintf(stderr,"%s: ",progname); + vfprintf(stderr, fmt, ap); + } +} + +void +#ifdef __STDC__ +Perror(const char *fmt, ...) +#else +Perror(fmt, va_list) + const char *fmt; + va_dcl +#endif +{ + va_list ap; +#ifdef __STDC__ + va_start(ap, fmt); +#else + va_start(ap); +#endif + verr(fmt,ap); + va_end(ap); +} diff --git a/gnu/libexec/ypxfr/yp_svc.c b/gnu/libexec/ypxfr/yp_svc.c index 12f26c9..a8638f2 100644 --- a/gnu/libexec/ypxfr/yp_svc.c +++ b/gnu/libexec/ypxfr/yp_svc.c @@ -1,4 +1,5 @@ #include <stdio.h> +#include <sys/types.h> #include <rpc/rpc.h> #include "yp.h" #ifndef lint @@ -9,6 +10,7 @@ static char rcsid[] = "yp.x,v 1.1 1994/08/04 19:01:55 wollman Exp"; static void ypprog_2(); static void yppush_xfrrespprog_1(); static void ypbindprog_2(); +extern void Perror __P((const char *, ...)); main() { @@ -20,41 +22,41 @@ main() transp = svcudp_create(RPC_ANYSOCK); if (transp == NULL) { - (void)fprintf(stderr, "cannot create udp service.\n"); + Perror("cannot create udp service.\n"); exit(1); } if (!svc_register(transp, YPPROG, YPVERS, ypprog_2, IPPROTO_UDP)) { - (void)fprintf(stderr, "unable to register (YPPROG, YPVERS, udp).\n"); + Perror("unable to register (YPPROG, YPVERS, udp).\n"); exit(1); } if (!svc_register(transp, YPPUSH_XFRRESPPROG, YPPUSH_XFRRESPVERS, yppush_xfrrespprog_1, IPPROTO_UDP)) { - (void)fprintf(stderr, "unable to register (YPPUSH_XFRRESPPROG, YPPUSH_XFRRESPVERS, udp).\n"); + Perror("unable to register (YPPUSH_XFRRESPPROG, YPPUSH_XFRRESPVERS, udp).\n"); exit(1); } if (!svc_register(transp, YPBINDPROG, YPBINDVERS, ypbindprog_2, IPPROTO_UDP)) { - (void)fprintf(stderr, "unable to register (YPBINDPROG, YPBINDVERS, udp).\n"); + Perror("unable to register (YPBINDPROG, YPBINDVERS, udp).\n"); exit(1); } transp = svctcp_create(RPC_ANYSOCK, 0, 0); if (transp == NULL) { - (void)fprintf(stderr, "cannot create tcp service.\n"); + Perror("cannot create tcp service.\n"); exit(1); } if (!svc_register(transp, YPPROG, YPVERS, ypprog_2, IPPROTO_TCP)) { - (void)fprintf(stderr, "unable to register (YPPROG, YPVERS, tcp).\n"); + Perror("unable to register (YPPROG, YPVERS, tcp).\n"); exit(1); } if (!svc_register(transp, YPPUSH_XFRRESPPROG, YPPUSH_XFRRESPVERS, yppush_xfrrespprog_1, IPPROTO_TCP)) { - (void)fprintf(stderr, "unable to register (YPPUSH_XFRRESPPROG, YPPUSH_XFRRESPVERS, tcp).\n"); + Perror("unable to register (YPPUSH_XFRRESPPROG, YPPUSH_XFRRESPVERS, tcp).\n"); exit(1); } if (!svc_register(transp, YPBINDPROG, YPBINDVERS, ypbindprog_2, IPPROTO_TCP)) { - (void)fprintf(stderr, "unable to register (YPBINDPROG, YPBINDVERS, tcp).\n"); + Perror("unable to register (YPBINDPROG, YPBINDVERS, tcp).\n"); exit(1); } svc_run(); - (void)fprintf(stderr, "svc_run returned\n"); + Perror("svc_run returned\n"); exit(1); } @@ -166,7 +168,7 @@ ypprog_2(rqstp, transp) svcerr_systemerr(transp); } if (!svc_freeargs(transp, xdr_argument, &argument)) { - (void)fprintf(stderr, "unable to free arguments\n"); + Perror("unable to free arguments\n"); exit(1); } } @@ -211,7 +213,7 @@ yppush_xfrrespprog_1(rqstp, transp) svcerr_systemerr(transp); } if (!svc_freeargs(transp, xdr_argument, &argument)) { - (void)fprintf(stderr, "unable to free arguments\n"); + Perror("unable to free arguments\n"); exit(1); } } @@ -263,7 +265,7 @@ ypbindprog_2(rqstp, transp) svcerr_systemerr(transp); } if (!svc_freeargs(transp, xdr_argument, &argument)) { - (void)fprintf(stderr, "unable to free arguments\n"); + Perror("unable to free arguments\n"); exit(1); } } diff --git a/gnu/libexec/ypxfr/yp_xdr.c b/gnu/libexec/ypxfr/yp_xdr.c index a39acae..7eea70f 100644 --- a/gnu/libexec/ypxfr/yp_xdr.c +++ b/gnu/libexec/ypxfr/yp_xdr.c @@ -5,6 +5,8 @@ static char rcsid[] = "yp.x,v 1.1 1994/08/04 19:01:55 wollman Exp"; #endif /* not lint */ +extern void Perror __P((const char *, ...)); + struct { union { int (*encoder)(char *, int, char **, int *, char **, int *); @@ -197,7 +199,7 @@ __xdr_ypresp_all(XDR *xdrs, ypresp_all *objp) return (FALSE); } if (!__xdr_ypresp_key_val(xdrs, &objp->ypresp_all_u.val)) { - printf("__xdr_ypresp_key_val failed\n"); + Perror("__xdr_ypresp_key_val failed\n"); return (FALSE); } if (objp->ypresp_all_u.val.stat!=YP_TRUE) { diff --git a/gnu/libexec/ypxfr/ypclnt.c b/gnu/libexec/ypxfr/ypclnt.c index cefc58f..9f8a316 100644 --- a/gnu/libexec/ypxfr/ypclnt.c +++ b/gnu/libexec/ypxfr/ypclnt.c @@ -18,7 +18,7 @@ Modified for use with FreeBSD 2.x by Bill Paul (wpaul@ctr.columbia.edu) - $Id: ypclnt.c,v 1.1 1995/01/31 09:28:45 wpaul Exp $ + $Id: ypclnt.c,v 1.2 1995/02/06 23:35:48 wpaul Exp $ */ #include <stdio.h> @@ -43,7 +43,8 @@ struct dom_binding { static struct sockaddr_in ServerAddress; static CLIENT *UdpClient=NULL, *TcpClient=NULL; - +extern void Perror __P((const char *, ...)); + #ifdef YPBROADCAST static bool_t eachresult( caddr_t resultsp, struct sockaddr_in *raddr) @@ -84,16 +85,16 @@ __do_ypbind(domainname d) case YPBIND_FAIL_VAL: switch(r.ypbind_resp_u.ypbind_error) { case YPBIND_ERR_ERR: - fprintf(stderr, "YPBINDPROC_DOMAIN: Internal error\n"); + Perror("YPBINDPROC_DOMAIN: Internal error\n"); break; case YPBIND_ERR_NOSERV: - fprintf(stderr, "YPBINDPROC_DOMAIN: No bound server for passed domain\n"); + Perror("YPBINDPROC_DOMAIN: No bound server for passed domain\n"); break; case YPBIND_ERR_RESC: - fprintf(stderr, "YPBINDPROC_DOMAIN: System resource allocation failure\n"); + Perror("YPBINDPROC_DOMAIN: System resource allocation failure\n"); break; default: - fprintf(stderr, "YPBINDPROC_DOMAIN: Unknown error\n"); + Perror("YPBINDPROC_DOMAIN: Unknown error\n"); break; } return NULL; diff --git a/gnu/libexec/ypxfr/ypxfr.8 b/gnu/libexec/ypxfr/ypxfr.8 index 1e7ae62..9b021e5 100644 --- a/gnu/libexec/ypxfr/ypxfr.8 +++ b/gnu/libexec/ypxfr/ypxfr.8 @@ -29,7 +29,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $Id: ypxfr.8,v 1.1 1995/02/06 22:15:21 wpaul Exp $ +.\" $Id: ypxfr.8,v 1.2 1995/03/30 04:14:45 wpaul Exp $ .\" .Dd February 5, 1995 .Dt YPXFR 8 @@ -119,10 +119,11 @@ When .Nm ypxfr is invoked without a controlling terminal, e.g. from inside .Xr ypserv 8 , -it logs all its output to -.Pa /var/yp/ypxfr.log . +it logs all its output using the +.Xr syslog 3 +facility. .Sh OPTIONS -The following options are supported by +The following options and flags are supported by .Nm ypxfr : .Bl -tag -width flag .It Fl f diff --git a/gnu/libexec/ypxfr/ypxfr.c b/gnu/libexec/ypxfr/ypxfr.c index 292ff98..2c24550 100644 --- a/gnu/libexec/ypxfr/ypxfr.c +++ b/gnu/libexec/ypxfr/ypxfr.c @@ -18,7 +18,7 @@ Modified for use with FreeBSD 2.x by Bill Paul (wpaul@ctr.columbia.edu) - $Id: ypxfr.c,v 1.3 1995/03/30 04:14:46 wpaul Exp $ + $Id: ypxfr.c,v 1.2 1995/02/06 23:35:49 wpaul Exp $ */ #include <stdio.h> @@ -70,6 +70,11 @@ struct dom_binding { */ extern int _yp_bind(struct sockaddr_in *, char *); extern int _yp_clear( char *); +extern void Perror __P((const char *, ...)); +int logflag = 0; +char *progname; +#include <errno.h> +#include <syslog.h> #include <netdb.h> #include <fcntl.h> #include <ctype.h> @@ -115,7 +120,7 @@ ypxfr_foreach(int status, char *key, int keylen, char *val, int vallen, return 0; if (status!=YP_TRUE) { int s=ypprot_err(status); - fprintf(stderr, "%s\n", yperr_string(s)); + Perror("%s\n",yperr_string(s)); return 1; } @@ -194,8 +199,8 @@ ypxfr(char *mapName) { sprintf(dbName, "%s%s/%s", _PATH_YP, TargetDomain, mapName); if ((db = dbopen(dbName,O_RDWR|O_EXCL, PERM_SECURE, DB_HASH, &openinfo)) == NULL) { - perror("dbopen"); - fprintf(stderr, "%s: cannot open - ignored.\n", dbName); + Perror("dbopen: %s\n", strerror(errno)); + Perror("%s: cannot open - ignored.\n", dbName); localOrderNum=0; } else { inKey.data="YP_LAST_MODIFIED"; inKey.size=strlen(inKey.data); @@ -219,7 +224,7 @@ ypxfr(char *mapName) { sprintf(dbName, "%s%s/%s~", _PATH_YP, TargetDomain, mapName); if ((db = dbopen(dbName,O_RDWR|O_EXCL|O_CREAT, PERM_SECURE, DB_HASH, &openinfo)) == NULL) { - fprintf(stderr, "%s: Cannot open\n", dbName); + Perror("%s: Cannot open\n", dbName); return YPXFR_DBM; } @@ -238,6 +243,13 @@ ypxfr(char *mapName) { callback.foreach = ypxfr_foreach; callback.data = NULL; + + /* + * We have to use our own private version of yp_all() here since + * the yp_all() in libc doesn't allow us to specify the server that + * we want to talk to: it's imperative that we transfer data from + * the NIS master server and no one else. + */ y=__yp_all(SourceDomain, mapName, &callback); (void)(db->close)(db); @@ -259,7 +271,7 @@ ypxfr(char *mapName) { void usage(progname) char *progname; { - fprintf(stderr, "usage: %s [-f] [-c] [-d target domain] \ + fprintf(stderr,"usage: %s [-f] [-c] [-d target domain] \ [-h source host]\n [-s source domain] \ [-C taskid program-number ipaddr port] mapname\n", progname); } @@ -267,18 +279,12 @@ char *progname; void main (int argc, char **argv) { - if (!isatty(0)) { - int fd; - char logfile[MAXPATHLEN]; - sprintf (logfile, "%sypxfr.log", _PATH_YP); - if ((fd = open(logfile, O_CREAT|O_WRONLY|O_APPEND, 0644))) { - close(0); - dup(fd); - close(1); - dup(fd); - close(2); - dup(fd); - } + + progname = argv[0]; + + if (!isatty(2)) { + openlog(argv[0], LOG_PID, LOG_DAEMON); + logflag = 1; } if (argc < 2) @@ -330,7 +336,7 @@ main (int argc, char **argv) for (; *argv; argv++) { enum ypxfrstat y; if ((y=ypxfr(*argv))!=YPXFR_SUCC) { - fprintf(stderr, "%s\n", ypxfr_err_string(y)); + Perror("%s\n", ypxfr_err_string(y)); } if (TaskId) { struct sockaddr_in addr; |