BSD 3 development
[unix-history] / usr / src / cmd / net / setup.c
CommitLineData
91978b44
ES
1/*
2 setup.c
3
4 support procedures used in setting up the network
5
6*/
7
8# include "defs.h"
9
10char logfile[] = LOGFILE;
11
12/* global variables */
13int datasize = SIZE; /* best if mult of 512 */
14char vaxtovax = 0;
15int linkspeed = LINKS;
16char local;
17char device[];
18int debugflg;
19int maxbread,atime;
20int onlyuid;
21
22short masterseqno;
23FILE *readtty,*writetty;
24int readfd, writefd, pipesim;
25/*
26 called in netdaemon and debugging software
27 handles parameter lists to setup
28 remote machine and pipes
29*/
30setupdaemon(argc,argv)
31 char **argv; {
32 remote = argc > 1 ? lookup(argv[1]) : getremote(local);
33 if(argc == 4){ /* simulate using pipes */
34 readfd = atoi(argv[2]);
35 writefd = atoi(argv[3]);
36 pipesim++;
37 }
38 initdaemon();
39 }
40/*
41 set the correct mode on the link device
42*/
43setup(str)
44 char *str; {
45 struct sgttyb stt;
46 static char readbuf[BUFSIZ],writebuf[BUFSIZ];
47 if(str == 0 || str[0] == 0){
48 err("invalid net device\n");
49 exit(1);
50 }
51 masterseqno = 1;
52 readtty = pipesim ? fdopen(readfd,"r") : fopen(str,"r");
53 if(readtty == NULL){
54 perror(str);
55 exit(1);
56 }
57 writetty = pipesim ? fdopen(writefd,"w") : fopen(str,"w");
58 if(writetty == NULL){
59 perror(str);
60 exit(1);
61 }
62 if(!pipesim){
63 /* set exclusive use for line */
64 if(ioctl(fileno(readtty),TIOCEXCL,&stt) != 0 ||
65 gtty(fileno(readtty),&stt) < 0){
66 perror(str);
67 exit(1);
68 }
69 stt.sg_ispeed = stt.sg_ospeed = linkspeed; /* user-set baud */
70 stt.sg_erase = stt.sg_kill = 0; /* erase and kill off */
71 stt.sg_flags = ANYP; /* even and odd parity, off everything else */
72 if(stty(fileno(readtty),&stt) < 0){
73 perror(str);
74 exit(1);
75 }
76 }
77 setbuf(readtty,readbuf);
78 setbuf(writetty,writebuf);
79 }
80/*
81 initialize various data structures and print banner
82*/
83initdaemon(){
84 long timev;
85 int timei;
86 FILE *cfile;
87 cfile = fopen(INITFILE,"r");
88 rdnetfile(cfile);
89 fclose(cfile);
90 err("remote %c local %c link %s speed %d vtov %d length %d\n",
91 remote,local,device,linkspeed,vaxtovax,datasize);
92 err("debug %d time %d count %d onlyuid %d\n",debugflg,atime,
93 maxbread,onlyuid);
94 setup(device);
95 timev = gettime();
96 timei = timev >> 16;
97 srand(timei);
98# ifdef IMAGE
99 if(machtype[local - 'a'] != M_OTHER)
100# endif
101# ifdef EECS40
102 if(machtype[local - 'a'] != M_OTHER)
103# endif
104# ifdef OPTVAX
105 if(machtype[local - 'a'] != M_OTHER)
106# endif
107# ifdef CSVAX
108 if(machtype[local - 'a'] != M_VAX)
109# endif
110# ifdef CORY
111 if(machtype[local - 'a'] != M_CORY)
112# endif
113# ifdef INGVAX
114 if(machtype[local - 'a'] != M_INGRES)
115# endif
116# ifdef ING70
117 if(machtype[local - 'a'] != M_INGRES)
118# endif
119# ifdef CC
120 if(machtype[local -'a'] != M_CC && machtype[local - 'a'] != M_SRC)
121# endif
122 err("Machine type disagrees with local machine\n");
123 }
124/*VARARGS0*/
125error(s,a,b,c,d,e,f,g,h)
126char *s; {
127 char buf[10];
128 if(remote != 0) sprintf(buf,"%s",longname(remote));
129 else buf[0] = 0;
130 fflush(stdout);
131 if(debugflg){
132 fprintf(stderr,s,a,b,c,d,e,f,g,h);
133 putc('\n',stderr);
134 }
135 addtolog(remote,"Err %s: ",buf);
136 addtolog(remote,s,a,b,c,d,e,f,g,h);
137 addtolog(remote,"\n");
138 }
139/* this is really not right - we should use the rcslog format */
140/* also, the user must be able to write on the
141 public logfile to get error messages such as
142 directory not found after he has
143 setuid'd from root
144*/
145/*VARARGS0*/
146addtolog(mach,s,a,b,c,d,e,f,g,h,i,j,k,l,m,n)
147char *s;
148{
149 static FILE *log = NULL;
150 struct stat statbuf;
151 logfile[strlen(logfile)-1] = mach;
152 if(log == NULL){
153 if(stat(logfile,&statbuf) < 0)return;
154 log = fopen(logfile,"a");
155 }
156 if(log == NULL)return;
157 fseek(log,0L,2);
158 fprintf(log,s,a,b,c,d,e,f,g,h,i,j,k,l,m,n);
159 fflush(log);
160 debug(s,a,b,c,d,e,f,g,h,i,h,k,l,m,n);
161 }