Use err(3). Add usage and prototypes. Remove Xref: Diskless(8) does not

exist. Use An/Aq macros for Author.
This commit is contained in:
Philippe Charnier 1997-09-04 11:50:37 +00:00
parent 4b15a65e1f
commit 112eace26d
5 changed files with 108 additions and 109 deletions

View file

@ -9,9 +9,9 @@
.Nm
.Op Fl ds
.Op Fl r Ar router
.Op Fl f file
.Op Fl f Ar file
.Sh DESCRIPTION
.Nm bootparamd
.Nm Bootparamd
is a server process that provides information to diskless clients
necessary for booting. It consults the
.Pa /etc/bootparams
@ -44,4 +44,5 @@ The file to use as boot parameter file instead of
.Sh BUGS
You may find the syslog loggings to be verbose.
.Sh AUTHOR
Written by Klas Heggemann <klas@nada.kth.se>
Written by
.An Klas Heggemann Aq klas@nada.kth.se

View file

@ -5,22 +5,26 @@ use and modify. Please send modifications and/or suggestions + bug fixes to
Klas Heggemann <klas@nada.kth.se>
$Id$
*/
#ifndef lint
static const char rcsid[] =
"$Id$";
#endif /* not lint */
#include <rpc/rpc.h>
#include <rpcsvc/yp_prot.h>
#include <rpcsvc/ypclnt.h>
#include "bootparam_prot.h"
#include <ctype.h>
#include <err.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
#include <syslog.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <ctype.h>
#include <syslog.h>
extern int debug, dolog;
extern unsigned long route_addr;
extern char *bootpfile;
@ -34,6 +38,8 @@ static char askname[MAX_MACHINE_NAME];
static char path[MAX_PATH_LEN];
static char domain_name[MAX_MACHINE_NAME];
int getthefile __P((char *, char *, char *));
int checkhost __P((char *, char *));
bp_whoami_res *
bootparamproc_whoami_1(whoami)
@ -59,7 +65,7 @@ bp_whoami_arg *whoami;
he = gethostbyaddr((char *)&haddr,sizeof(haddr),AF_INET);
if ( ! he ) goto failed;
if (debug) fprintf(stderr,"This is host %s\n", he->h_name);
if (debug) warnx("this is host %s", he->h_name);
if (dolog) syslog(LOG_NOTICE,"This is host %s\n", he->h_name);
strcpy(askname, he->h_name);
@ -92,7 +98,7 @@ bp_whoami_arg *whoami;
return(&res);
}
failed:
if (debug) fprintf(stderr,"whoami failed\n");
if (debug) warnx("whoami failed");
if (dolog) syslog(LOG_NOTICE,"whoami failed\n");
return(NULL);
}
@ -106,7 +112,7 @@ bp_getfile_arg *getfile;
static bp_getfile_res res;
if (debug)
fprintf(stderr,"getfile got question for \"%s\" and file \"%s\"\n",
warnx("getfile got question for \"%s\" and file \"%s\"",
getfile->client_name, getfile->file_id);
if (dolog)
@ -119,7 +125,7 @@ bp_getfile_arg *getfile;
strcpy(askname,he->h_name);
if (getthefile(askname, getfile->file_id,buffer)) {
if ( where = index(buffer,':')) {
if ( (where = index(buffer,':')) ) {
/* buffer is re-written to contain the name of the info of file */
strncpy(hostname, buffer, where - buffer);
hostname[where - buffer] = '\0';
@ -157,7 +163,7 @@ bp_getfile_arg *getfile;
return(&res);
}
failed:
if (debug) fprintf(stderr, "getfile failed for %s\n", getfile->client_name);
if (debug) warnx("getfile failed for %s", getfile->client_name);
if (dolog) syslog(LOG_NOTICE,
"getfile failed for %s\n", getfile->client_name);
return(NULL);
@ -169,6 +175,7 @@ bp_getfile_arg *getfile;
will be empty. (This makes it possible to give the special
empty answer for the file "dump") */
int
getthefile(askname,fileid,buffer)
char *askname;
char *fileid, *buffer;
@ -184,10 +191,8 @@ char *fileid, *buffer;
char info[MAX_FILEID + MAX_PATH_LEN+MAX_MACHINE_NAME + 3];
bpf = fopen(bootpfile, "r");
if ( ! bpf ) {
fprintf(stderr, "No %s\n", bootpfile);
exit(1);
}
if ( ! bpf )
errx(1, "no %s", bootpfile);
while ( fscanf(bpf, "%s", hostname) > 0 && !match ) {
if ( *hostname != '#' ) { /* comment */
@ -200,7 +205,7 @@ char *fileid, *buffer;
}
if (*hostname == '+' ) { /* NIS */
if (yp_get_default_domain(&yp_domain)) {
if (debug) perror("NIS");
if (debug) warn("NIS");
return(0);
}
if (yp_match(yp_domain, "bootparams", askname, strlen(askname),
@ -214,7 +219,7 @@ char *fileid, *buffer;
*(char *)(strchr(buffer, ' ')) = '\0';
}
if (fclose(bpf))
fprintf(stderr,"Could not close %s\n", bootpfile);
warnx("could not close %s", bootpfile);
return(1);
}
/* skip to next entry */
@ -254,7 +259,7 @@ char *fileid, *buffer;
} else break; /* a commented rest-of-line */
}
}
if (fclose(bpf)) { fprintf(stderr,"Could not close %s\n", bootpfile); }
if (fclose(bpf)) { warnx("could not close %s", bootpfile); }
if ( res == -1) buffer[0] = '\0'; /* host found, file not */
return(match);
}
@ -263,6 +268,7 @@ char *fileid, *buffer;
the hostname-variable and returns 1, if askname is a valid
name for a host in the database */
int
checkhost(askname, hostname)
char *askname;
char *hostname;
@ -277,10 +283,8 @@ char *hostname;
/* struct hostent *cmp_he;*/
bpf = fopen(bootpfile, "r");
if ( ! bpf ) {
fprintf(stderr, "No %s\n", bootpfile);
exit(1);
}
if ( ! bpf )
errx(1, "no %s", bootpfile);
while ( fscanf(bpf, "%s", hostname) > 0 ) {
if ( *hostname != '#' ) { /* comment */
@ -300,7 +304,7 @@ char *hostname;
}
if (*hostname == '+' ) { /* NIS */
if (yp_get_default_domain(&yp_domain)) {
if (debug) perror("NIS");
if (debug) warn("NIS");
return(0);
}
if (!yp_match(yp_domain, "bootparams", askname, strlen(askname),
@ -314,7 +318,7 @@ char *hostname;
}
}
if (fclose(bpf))
fprintf(stderr,"Could not close %s\n", bootpfile);
warnx("could not close %s", bootpfile);
return(res);
}
/* skip to next entry */
@ -323,6 +327,6 @@ char *hostname;
pch = ch; ch = getc(bpf);
}
}
if (fclose(bpf)) { fprintf(stderr,"Could not close %s\n", bootpfile); }
if (fclose(bpf)) { warnx("could not close %s", bootpfile); }
return(res);
}

View file

@ -25,7 +25,7 @@
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.\" from: Id: bootparams.5,v 1.2 1994/10/03 19:26:13 gwr Exp
.\" $Id$
.\" $Id: bootparams.5,v 1.6 1997/02/22 16:04:23 peter Exp $
.\"
.Dd October 2, 1994
.Dt BOOTPARAMS 5
@ -37,12 +37,12 @@
.Nm /etc/bootparams
.Sh DESCRIPTION
The
.Nm bootparams
.Nm
file specifies the boot parameters that
.Xr diskless
diskless
clients may request when booting over the network.
Each client supported by this server must have an entry in the
.Nm bootparams
.Nm
file containing the pathnames for its
.Nm root
and (optionally)
@ -74,6 +74,5 @@ request. The "host:" component must be supplied.
.It Pa /etc/bootparams
default configuration file
.El
.Sh "SEE ALSO"
.Xr bootparamd 8 ,
.Xr diskless 8
.Sh SEE ALSO
.Xr bootparamd 8

View file

@ -5,35 +5,39 @@ use and modify. Please send modifications and/or suggestions + bug fixes to
Klas Heggemann <klas@nada.kth.se>
$Id: main.c,v 1.5 1997/02/22 16:04:24 peter Exp $
*/
#ifndef lint
static const char rcsid[] =
"$Id$";
#endif /* not lint */
#include <ctype.h>
#include <err.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <rpc/rpc.h>
#include "bootparam_prot.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <rpc/pmap_clnt.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <netdb.h>
#include <ctype.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "bootparam_prot.h"
int debug = 0;
int dolog = 0;
unsigned long route_addr = -1, inet_addr();
struct sockaddr_in my_addr;
char *progname;
char *bootpfile = "/etc/bootparams";
extern void bootparamprog_1();
static void usage __P((void));
extern char *optarg;
extern int optind;
int
main(argc, argv)
int argc;
char **argv;
@ -42,13 +46,8 @@ char **argv;
int i;
struct hostent *he;
struct stat buf;
char *optstring;
char c;
progname = rindex(argv[0],'/');
if ( progname ) progname++;
else progname = argv[0];
while ((c = getopt(argc, argv,"dsr:f:")) != -1)
switch (c) {
case 'd':
@ -63,10 +62,9 @@ char **argv;
if (he) {
bcopy(he->h_addr, (char *)&route_addr, sizeof(route_addr));
break;
} else {
fprintf(stderr,"%s: No such host %s\n", progname, argv[i]);
exit(1);
}
} else {
errx(1, "no such host %s", argv[i]);
}
}
case 'f':
bootpfile = optarg;
@ -74,24 +72,18 @@ char **argv;
case 's':
dolog = 1;
#ifndef LOG_DAEMON
openlog(progname, 0 , 0);
openlog("bootparamd", 0 , 0);
#else
openlog(progname, 0 , LOG_DAEMON);
openlog("bootparamd", 0 , LOG_DAEMON);
setlogmask(LOG_UPTO(LOG_NOTICE));
#endif
break;
default:
fprintf(stderr,
"Usage: %s [-d ] [ -s ] [ -r router ] [ -f bootparmsfile ]\n", progname);
exit(1);
usage();
}
if ( stat(bootpfile, &buf ) ) {
fprintf(stderr,"%s: ", progname);
perror(bootpfile);
exit(1);
}
if ( stat(bootpfile, &buf ) )
err(1, "%s", bootpfile);
if (route_addr == -1) {
get_myaddress(&my_addr);
@ -99,28 +91,27 @@ char **argv;
}
if (!debug) {
if (daemon(0,0)) {
perror("bootparamd: fork");
exit(1);
}
if (daemon(0,0))
err(1, "fork");
}
(void)pmap_unset(BOOTPARAMPROG, BOOTPARAMVERS);
transp = svcudp_create(RPC_ANYSOCK);
if (transp == NULL) {
(void)fprintf(stderr, "cannot create udp service.\n");
exit(1);
}
if (!svc_register(transp, BOOTPARAMPROG, BOOTPARAMVERS, bootparamprog_1, IPPROTO_UDP)) {
(void)fprintf(stderr, "unable to register (BOOTPARAMPROG, BOOTPARAMVERS, udp).\n");
exit(1);
}
if (transp == NULL)
errx(1, "cannot create udp service");
if (!svc_register(transp, BOOTPARAMPROG, BOOTPARAMVERS, bootparamprog_1, IPPROTO_UDP))
errx(1, "unable to register (BOOTPARAMPROG, BOOTPARAMVERS, udp)");
svc_run();
(void)fprintf(stderr, "svc_run returned\n");
exit(1);
errx(1, "svc_run returned");
}
static void
usage()
{
fprintf(stderr,
"usage: bootparamd [-d] [-s] [-r router] [-f bootparmsfile]\n");
exit(1);
}

View file

@ -5,19 +5,24 @@ use and modify. Please send modifications and/or suggestions + bug fixes to
Klas Heggemann <klas@nada.kth.se>
$Id$
*/
#ifndef lint
static const char rcsid[] =
"$Id$";
#endif /* not lint */
#include "bootparam_prot.h"
#include <rpc/rpc.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <err.h>
#include <netdb.h>
/* #define bp_address_u bp_address */
#include <stdio.h>
#include <string.h>
int broadcast;
@ -25,7 +30,11 @@ char cln[MAX_MACHINE_NAME+1];
char dmn[MAX_MACHINE_NAME+1];
char path[MAX_PATH_LEN+1];
extern char *inet_ntoa();
static void usage __P((void));
int printgetfile __P((bp_getfile_res *));
int printwhoami __P((bp_whoami_res *));
int
eachres_whoami(resultp, raddr)
bp_whoami_res *resultp;
struct sockaddr_in *raddr;
@ -53,11 +62,11 @@ struct sockaddr_in *raddr;
}
int
main(argc, argv)
int argc;
char **argv;
{
int stat;
char *server;
bp_whoami_arg whoami_arg;
@ -76,12 +85,8 @@ char **argv;
stat_getfile_res.server_name = cln;
stat_getfile_res.server_path = path;
if (argc < 3) {
fprintf(stderr,
"Usage: %s server procnum (IP-addr | host fileid)\n", argv[0]);
exit(1);
}
if (argc < 3)
usage();
server = argv[1];
if ( ! strcmp(server , "all") ) broadcast = 1;
@ -90,28 +95,22 @@ char **argv;
clnt = clnt_create(server,BOOTPARAMPROG, BOOTPARAMVERS, "udp");
}
if ( clnt == NULL ) {
fprintf (stderr, "%s: could not contact bootparam server on host %s\n",
argv[0], server);
exit (1);
}
if ( clnt == NULL )
errx(1, "could not contact bootparam server on host %s", server);
switch (argc) {
case 3:
whoami_arg.client_address.address_type = IP_ADDR_TYPE;
the_inet_addr = inet_addr(argv[2]);
if ( the_inet_addr == -1) {
fprintf(stderr, "bogus addr %s\n", argv[2]);
exit(1);
}
if ( the_inet_addr == -1)
errx(2, "bogus addr %s", argv[2]);
bcopy(&the_inet_addr,&whoami_arg.client_address.bp_address_u.ip_addr,4);
if (! broadcast ) {
whoami_res = bootparamproc_whoami_1(&whoami_arg, clnt);
printf("Whoami returning:\n");
if (printwhoami(whoami_res)) {
fprintf(stderr, "Bad answer returned from server %s\n", server);
exit(1);
errx(1, "bad answer returned from server %s", server);
} else
exit(0);
} else {
@ -131,8 +130,7 @@ char **argv;
getfile_res = bootparamproc_getfile_1(&getfile_arg,clnt);
printf("getfile returning:\n");
if (printgetfile(getfile_res)) {
fprintf(stderr, "Bad answer returned from server %s\n", server);
exit(1);
errx(1, "bad answer returned from server %s", server);
} else
exit(0);
} else {
@ -145,16 +143,22 @@ char **argv;
default:
fprintf(stderr,
"Usage: %s server procnum (IP-addr | host fileid)\n", argv[0]);
exit(1);
usage();
}
}
static void
usage()
{
fprintf(stderr,
"usage: callbootd server procnum (IP-addr | host fileid)\n");
exit(1);
}
int printwhoami(res)
int
printwhoami(res)
bp_whoami_res *res;
{
if ( res) {
@ -167,7 +171,7 @@ bp_whoami_res *res;
255 & res->router_address.bp_address_u.ip_addr.impno);
return(0);
} else {
fprintf(stderr,"Null answer!!!\n");
warnx("null answer!!!");
return(1);
}
}
@ -186,7 +190,7 @@ bp_getfile_res *res;
res->server_path);
return(0);
} else {
fprintf(stderr,"Null answer!!!\n");
warnx("null answer!!!");
return(1);
}
}