chiark / gitweb /
Allow "-" as exroutes parameter.
[userv-utils.git] / ipif / service.c
1 /*
2  * userv service (or standalone program)
3  * for per-user IP subranges.
4  *
5  * This is invoked as root, directly from userv.
6  * Its arguments are supposed to be, in order:
7  *  <config>
8  *      Specifies address ranges and gids which own them.
9  *  --  Indicates that the remaining arguments are user-supplied
10  *      and therefore untrusted.
11  *  <local-addr>,<peer-addr>,<mtu>,<proto>
12  *      As for slattach.  Supported protocols are slip, cslip, and
13  *      adaptive.  Alternatively, set to `debug' to print debugging
14  *      info.  <local-addr> is address of the interface on chiark;
15  *      <peer-addr> is the address of the point-to-point peer.
16  *  <prefix>/<mask>,<prefix>/<mask>,...
17  *      List of additional routes to add for this interface.
18  *      May be the empty argument, or `-' if this is problematic.
19  *
20  * <config> is either
21  *    <gid>,<prefix>/<len>[,<junk>]
22  *      indicating that that gid may allocate addresses in
23  *      the relevant subspace (<junk> is ignored)
24  * or #...
25  *      which is a comment
26  * or /<config-file-name> or ./<config-file-name> or ../<config-file-name>
27  *      which refers to a file which contains lines which
28  *      are each <config>
29  * or *
30  *      which means that anything is permitted
31  * 
32  * Should be run from userv with no-disconnect-hup.
33  */
34
35 #include <stdio.h>
36 #include <string.h>
37 #include <stdlib.h>
38 #include <assert.h>
39 #include <errno.h>
40 #include <stdarg.h>
41 #include <ctype.h>
42 #include <limits.h>
43 #include <signal.h>
44 #include <unistd.h>
45
46 #include <sys/types.h>
47 #include <sys/wait.h>
48 #include <sys/stat.h>
49
50 #define NARGS 4
51 #define MAXEXROUTES 5
52 #define ATXTLEN 12
53
54 static const unsigned long gidmaxval= (unsigned long)((gid_t)-2);
55 static const char *const protos_ok[]= { "slip", "cslip", "adaptive", 0 };
56 static const int signals[]= { SIGHUP, SIGINT, SIGTERM, 0 };
57
58 static const char *configstr, *proto;
59 static unsigned long localaddr, peeraddr, mtu;
60 static int localallow, peerallow, allallow;
61 static int nexroutes;
62 static struct exroute {
63   unsigned long prefix, mask;
64   int allow;
65   char prefixtxt[ATXTLEN], masktxt[ATXTLEN];
66 } exroutes[MAXEXROUTES];
67
68 static char localtxt[ATXTLEN];
69 static char peertxt[ATXTLEN];
70
71 static struct pplace {
72   struct pplace *parent;
73   const char *filename;
74   int lineno;
75 } *cpplace;
76
77
78 static int slpipe[2], ptmaster, undoslattach;
79 static const char *ifname;
80 static const char *ptyname;
81
82 #define NPIDS 4
83
84 static union {
85   struct { pid_t sl, cout, cin, task; } byname;
86   pid_t bynumber[NPIDS];
87 } pids;
88 sigset_t emptyset, fullset;
89
90
91 static int cleantask(void) {
92   pid_t pid;
93
94   pid= fork();
95   if (!pid) return 1;
96   if (pid == (pid_t)-1)
97     perror("userv-ipif: fork for undo slattach failed - cannot clean up properly");
98   return 0;
99 }
100
101 static void terminate(int estatus) {
102   int i, status;
103   pid_t pid;
104   
105   for (i=0; i<NPIDS; i++)
106     if (pids.bynumber[i]) kill(pids.bynumber[i], SIGTERM);
107
108   if (undoslattach) {
109     if (cleantask()) {
110       execlp("slattach", "slattach", "-p", "tty", ptyname, (char*)0);
111       perror("userv-ipif: exec slattach for undo slattach failed");
112       exit(-1);
113     }
114     if (ifname && cleantask()) {
115       execlp("ifconfig", "ifconfig", ifname, "down", (char*)0);
116       perror("userv-ipif: exec ifconfig for undo ifconfig failed");
117       exit(-1);
118     }
119   }
120
121   for (;;) {
122     pid= waitpid(-1,&status,0);
123     if (pid == (pid_t)-1) break;
124   }
125   exit(estatus);
126 }
127
128
129 static void fatal(const char *fmt, ...)
130      __attribute__((format(printf,1,2)));
131 static void fatal(const char *fmt, ...) {
132   va_list al;
133   va_start(al,fmt);
134
135   fputs("userv-ipif service: fatal error: ",stderr);
136   vfprintf(stderr, fmt, al);
137   putc('\n',stderr);
138   terminate(8);
139 }
140   
141 static void sysfatal(const char *fmt, ...)
142      __attribute__((format(printf,1,2)));
143 static void sysfatal(const char *fmt, ...) {
144   va_list al;
145   int e;
146
147   e= errno;
148   va_start(al,fmt);
149
150   fputs("userv-ipif service: fatal system error: ",stderr);
151   vfprintf(stderr, fmt, al);
152   fprintf(stderr,": %s\n", strerror(e));
153   terminate(12);
154 }
155
156
157 static void badusage(const char *fmt, ...)
158      __attribute__((format(printf,1,2)));
159 static void badusage(const char *fmt, ...) {
160   va_list al;
161   struct pplace *cpp;
162   
163   if (cpplace) {
164     fprintf(stderr,
165             "userv-ipif service: %s:%d: ",
166             cpplace->filename, cpplace->lineno);
167   } else {
168     fputs("userv-ipif service: invalid usage: ",stderr);
169   }
170   va_start(al,fmt);
171   vfprintf(stderr, fmt, al);
172   putc('\n',stderr);
173
174   if (cpplace) {
175     for (cpp=cpplace->parent; cpp; cpp=cpp->parent) {
176       fprintf(stderr,
177               "userv-ipif service: %s:%d: ... in file included from here\n",
178               cpp->filename, cpp->lineno);
179     }
180   }
181   terminate(16);
182 }
183
184 static char *ip2txt(unsigned long addr, char *buf) {
185   sprintf(buf, "%lu.%lu.%lu.%lu",
186           (addr>>24) & 0x0ff,
187           (addr>>16) & 0x0ff,
188           (addr>>8) & 0x0ff,
189           (addr) & 0x0ff);
190   return buf;
191 }
192
193 static unsigned long eat_number(const char **argp, const char *what,
194                                 unsigned long min, unsigned long max,
195                                 const char *endchars, int *endchar_r) {
196   /* If !endchars then the endchar must be a nul, otherwise it may be
197    * a nul (resulting in *argp set to 0) or something else (*argp set
198    * to point to after delim, *endchar_r set to delim).
199    * *endchar_r may be 0.
200    */
201   unsigned long rv;
202   char *ep;
203   int endchar;
204
205   if (!*argp) { badusage("missing number %s",what); }
206   rv= strtoul(*argp,&ep,0);
207   if ((endchar= *ep)) {
208     if (!endchars) badusage("junk after number %s",what);
209     if (!strchr(endchars,endchar))
210       badusage("invalid character or delimiter `%c' in or after number, %s:"
211                " expected %s (or none?)", endchar,what,endchars);
212     *argp= ep+1;
213   } else {
214     *argp= 0;
215   }
216   if (endchar_r) *endchar_r= endchar;
217   if (rv < min || rv > max) badusage("number %s value %lu out of range %lu..%lu",
218                                      what, rv, min, max);
219   return rv;
220 }
221
222 static void addrnet_mustdiffer(const char *w1, unsigned long p1, unsigned long m1,
223                                const char *w2, unsigned long p2, unsigned long m2) {
224   unsigned long mask;
225
226   mask= m1&m2;
227   if ((p1 & mask) != (p2 & mask)) return;
228   badusage("%s %08lx/%08lx overlaps/clashes with %s %08lx/%08lx",
229            w1,p1,m1, w2,p2,m2);
230 }
231   
232 static unsigned long eat_addr(const char **argp, const char *what,
233                               const char *endchars, int *endchar_r) {
234   char whatbuf[100];
235   unsigned long rv;
236   int i;
237
238   for (rv=0, i=0;
239        i<4;
240        i++) {
241     rv <<= 8;
242     sprintf(whatbuf,"%s byte #%d",what,i);
243     rv |= eat_number(argp,whatbuf, 0,255, i<3 ? "." : endchars, endchar_r);
244   }
245
246   return rv;
247 }
248
249 static void eat_prefixmask(const char **argp, const char *what,
250                            const char *endchars, int *endchar_r,
251                            unsigned long *prefix_r, unsigned long *mask_r, int *len_r) {
252   /* mask_r and len_r may be 0 */
253   char whatbuf[100];
254   int len;
255   unsigned long prefix, mask;
256
257   prefix= eat_addr(argp,what, "/",0);
258   sprintf(whatbuf,"%s length",what);
259   len= eat_number(argp,whatbuf, 0,32, endchars,endchar_r);
260
261   mask= (~0UL << (32-len));
262   if (prefix & ~mask) badusage("%s prefix %08lx not fully contained in mask %08lx",
263                                what,prefix,mask);
264   *prefix_r= prefix;
265   if (mask_r) *mask_r= mask;
266   if (len_r) *len_r= len;
267 }
268
269 static int addrnet_isin(unsigned long prefix, unsigned long mask,
270                         unsigned long mprefix, unsigned long mmask) {
271   return  !(~mask & mmask)  &&  (prefix & mmask) == mprefix;
272 }
273   
274
275 static void permit(unsigned long pprefix, unsigned long pmask) {
276   int i, any;
277   
278   assert(!(pprefix & ~pmask));
279
280   if (!proto) fputs("permits",stdout);
281   if (addrnet_isin(localaddr,~0UL, pprefix,pmask)) {
282     if (!proto) fputs(" local-addr",stdout);
283     any= localallow= 1;
284   }
285   if (addrnet_isin(peeraddr,~0UL, pprefix,pmask)) {
286     if (!proto) fputs(" peer-addr",stdout);
287     any= peerallow= 1;
288   }
289   for (i=0; i<nexroutes; i++) {
290     if (addrnet_isin(exroutes[i].prefix,exroutes[i].mask, pprefix,pmask)) {
291       if (!proto) printf(" route#%d",i);
292       any= exroutes[i].allow= 1;
293     }
294   }
295   if (!proto) {
296     if (!any) fputs(" nothing!",stderr);
297     putchar('\n');
298   }
299 }
300
301 static void pconfig(const char *configstr, int truncated);
302
303 static void pfile(const char *filename) {
304   FILE *file;
305   char buf[PATH_MAX];
306   int l, truncated, c;
307   struct pplace npp, *cpp;
308
309   for (cpp=cpplace; cpp; cpp=cpp->parent) {
310     if (!strcmp(cpp->filename,filename))
311       badusage("recursive configuration file `%s'",filename);
312   }
313
314   file= fopen(filename,"r");
315   if (!file)
316     badusage("cannot open configuration file `%s': %s", filename, strerror(errno));
317
318   if (!proto) printf("config file `%s':\n",filename);
319
320   npp.parent= cpplace;
321   npp.filename= filename;
322   npp.lineno= 0;
323   cpplace= &npp;
324
325   while (fgets(buf, sizeof(buf), file)) {
326     npp.lineno++;
327     l= strlen(buf);
328     if (!l) continue;
329
330     truncated= (buf[l-1] != '\n');
331     while (l>0 && isspace((unsigned char) buf[l-1])) l--;
332     if (!l) continue;
333     buf[l]= 0;
334
335     if (truncated) {
336       while ((c= getc(file)) != EOF && c != '\n');
337       if (c == EOF) break;
338     }
339
340     pconfig(buf,truncated);
341   }
342   if (ferror(file))
343     badusage("failed while reading configuration file: %s", strerror(errno));
344
345   cpplace= npp.parent;
346 }
347
348 static void pconfig(const char *configstr, int truncated) {
349   unsigned long fgid, tgid, pprefix, pmask;
350   int plen;
351   char ptxt[ATXTLEN];
352   const char *gidlist;
353   
354   switch (configstr[0]) {
355   case '*':
356     if (strcmp(configstr,"*")) badusage("`*' directive must be only thing on line");
357     permit(0UL,0UL);
358     return;
359     
360   case '#':
361     return;
362     
363   case '/': case '.':
364     if (truncated) badusage("filename too long (`%.100s...')",configstr);
365     pfile(configstr);
366     return;
367     
368   default:
369     if (!isdigit((unsigned char)configstr[0]))
370       badusage("unknown configuration directive");
371     
372     fgid= eat_number(&configstr,"gid", 0,gidmaxval, ",",0);
373     eat_prefixmask(&configstr,"permitted-prefix", ",",0, &pprefix,&pmask,&plen);
374     if (!configstr && truncated) badusage("gid,prefix/len,... spec too long");
375
376     if (!proto) printf(" %5lu,%s/%d: ", fgid, ip2txt(pprefix,ptxt), plen);
377
378     gidlist= getenv("USERV_GID");
379     if (!gidlist) fatal("USERV_GID not set");
380     for (;;) {
381       if (!gidlist) {
382         if (!proto) printf("no matching gid\n");
383         return;
384       }
385       tgid= eat_number(&gidlist,"userv-gid", 0,gidmaxval, " ",0);
386       if (tgid == fgid) break;
387     }
388     permit(pprefix,pmask);
389     return;
390   }
391 }
392
393 static void checkallow(int allow, const char *what,
394                        const char *prefixtxt, const char *masktxt) {
395   if (allow) return;
396   fprintf(stderr,"userv-ipif service: access denied for %s, %s/%s\n",
397           what, prefixtxt, masktxt);
398   allallow= 0;
399 }
400
401 static void parseargs(int argc, const char *const *argv) {
402   unsigned long routeaddr, routemask;
403   const char *carg;
404   const char *const *cprotop;
405   int i;
406   char erwhatbuf[100], erwhatbuf2[100];
407   
408   if (argc < NARGS+1) { badusage("too few arguments"); }
409   if (argc > NARGS+1) { badusage("too many arguments"); }
410
411   configstr= *++argv;
412   
413   carg= *++argv;
414   if (strcmp(carg,"--")) badusage("separator argument `--' not found, got `%s'",carg);
415
416   carg= *++argv;
417   localaddr= eat_addr(&carg,"local-addr", ",",0);
418   peeraddr= eat_addr(&carg,"peer-addr", ",",0);
419   mtu= eat_number(&carg,"mtu", 576,65536, ",",0);
420   localallow= peerallow= 0;
421   
422   if (!strcmp(carg,"debug")) {
423     proto= 0;
424   } else {
425     for (cprotop= protos_ok;
426          (proto= *cprotop) && strcmp(proto,carg);
427          cprotop++);
428     if (!proto) fatal("invalid protocol");
429   }
430   
431   addrnet_mustdiffer("local-addr",localaddr,~0UL, "peer-addr",peeraddr,~0UL);
432   
433   carg= *++argv;
434   if (strcmp(carg,"-")) {
435     for (nexroutes=0;
436          carg && *carg;
437          nexroutes++) {
438       if (nexroutes == MAXEXROUTES)
439         fatal("too many extra routes (only %d allowed)",MAXEXROUTES);
440       sprintf(erwhatbuf,"route#%d",nexroutes);
441     
442       eat_prefixmask(&carg,erwhatbuf, ",",0, &routeaddr,&routemask,0);
443       if (routemask == ~0UL) {
444         addrnet_mustdiffer(erwhatbuf,routeaddr,routemask, "local-addr",localaddr,~0UL);
445         addrnet_mustdiffer(erwhatbuf,routeaddr,routemask, "peer-addr",peeraddr,~0UL);
446       }
447       for (i=0; i<nexroutes; i++) {
448         sprintf(erwhatbuf2,"route#%d",i);
449         addrnet_mustdiffer(erwhatbuf,routeaddr,routemask,
450                            erwhatbuf2,exroutes[i].prefix,exroutes[i].mask);
451       }
452       exroutes[nexroutes].prefix= routeaddr;
453       exroutes[nexroutes].mask= routemask;
454       exroutes[nexroutes].allow= 0;
455       ip2txt(routeaddr,exroutes[nexroutes].prefixtxt);
456       ip2txt(routemask,exroutes[nexroutes].masktxt);
457     }
458   }
459
460   ip2txt(localaddr,localtxt);
461   ip2txt(peeraddr,peertxt);
462 }
463
464 static void checkpermit(void) {
465   int i;
466   char erwhatbuf[100];
467   
468   allallow= 1;
469   checkallow(localallow,"local-addr", localtxt,"32");
470   checkallow(peerallow,"peer-addr", peertxt,"32");
471   for (i=0; i<nexroutes; i++) {
472     sprintf(erwhatbuf, "route#%d", i);
473     checkallow(exroutes[i].allow, erwhatbuf, exroutes[i].prefixtxt, exroutes[i].masktxt);
474   }
475   if (!allallow) fatal("access denied");
476 }
477
478 static void dumpdebug(void) __attribute__((noreturn));
479 static void dumpdebug(void) {
480   int i;
481   char erwhatbuf[100];
482   
483   printf("protocol: debug\n"
484          "local:    %08lx == %s\n"
485          "peer:     %08lx == %s\n"
486          "mtu:      %ld\n"
487          "routes:   %d\n",
488          localaddr, localtxt,
489          peeraddr, peertxt,
490          mtu,
491          nexroutes);
492   for (i=0; i<nexroutes; i++) {
493     sprintf(erwhatbuf, "route#%d:", i);
494     printf("%-9s %08lx/%08lx == %s/%s\n",
495            erwhatbuf,
496            exroutes[i].prefix, exroutes[i].mask,
497            exroutes[i].prefixtxt, exroutes[i].masktxt);
498   }
499   if (ferror(stdout) || fclose(stdout)) sysfatal("flush stdout");
500   exit(0);
501 }
502
503
504 static void setsigmask(const sigset_t *ss) {
505   int r;
506   
507   r= sigprocmask(SIG_SETMASK, ss, 0);
508   if (r) sysfatal("[un]block signals");
509 }  
510
511 static void setsignals(void (*handler)(int), struct sigaction *sa, int chldflags) {
512   const int *signalp;
513   int r, sig;
514   
515   sa->sa_handler= handler;
516   sa->sa_flags= 0; 
517   for (signalp=signals; (sig=*signalp); signalp++) {
518     r= sigaction(sig, sa, 0);  if (r) sysfatal("uncatch signal");
519   }
520   sa->sa_flags= chldflags;
521   r= sigaction(SIGCHLD, sa, 0);  if (r) sysfatal("uncatch children");
522 }
523
524 static void infork(void) {
525   struct sigaction sa;
526
527   memset(&pids,0,sizeof(pids));
528   sigemptyset(&sa.sa_mask);
529   setsignals(SIG_DFL,&sa,0);
530   setsigmask(&emptyset);
531   undoslattach= 0;
532 }
533
534 static pid_t makesubproc(void (*entry)(void)) {
535   pid_t pid;
536
537   pid= fork();  if (pid == (pid_t)-1) sysfatal("fork for subprocess");
538   if (pid) return pid;
539
540   infork();
541   entry();
542   abort();
543 }
544
545 static int task(void) {
546   pid_t pid;
547
548   pid= fork();
549   if (pid == (pid_t)-1) sysfatal("fork for task");
550   if (!pid) { infork(); return 1; }
551
552   pids.byname.task= pid;
553   while (pids.byname.task) sigsuspend(&emptyset);
554   return 0;
555 }
556
557 static void mdup2(int fd1, int fd2, const char *what) {
558   int r;
559
560   for (;;) {
561     r= dup2(fd1,fd2); if (r==fd2) return;
562     if (r!=-1) fatal("dup2 in %s gave wrong answer %d instead of %d",what,r,fd2);
563     if (errno != EINTR) sysfatal("dup2 failed in %s",what);
564   }
565 }
566
567 static void sl_entry(void) {
568   mdup2(slpipe[1],1,"slattach child");
569   execlp("slattach", "slattach", "-v", "-L", "-p",proto, ptyname, (char*)0);
570   sysfatal("cannot exec slattach");
571 }
572
573 static void cin_entry(void) {
574   mdup2(ptmaster,1,"cat input child");
575   execlp("cat", "cat", (char*)0);
576   sysfatal("cannot exec cat input");
577 }
578
579 static void cout_entry(void) {
580   mdup2(ptmaster,0,"cat output child");
581   execlp("cat", "cat", (char*)0);
582   sysfatal("cannot exec cat output");
583 }
584
585 static void sighandler(int signum) {
586   pid_t pid;
587   int estatus, status;
588   const char *taskfail;
589
590   estatus= 4;
591   
592   if (signum == SIGCHLD) {
593     for (;;) {
594       pid= waitpid(-1,&status,WNOHANG);
595       if (!pid || pid == (pid_t)-1) return;
596
597       if (pid == pids.byname.task) {
598         pids.byname.task= 0;
599         if (!status) return;
600         taskfail= "task";
601       } else if (pid == pids.byname.cin) {
602         pids.byname.cin= 0;
603         if (status) {
604           taskfail= "input cat";
605         } else {
606           taskfail= 0;
607           estatus= 0;
608         }
609       } else if (pid == pids.byname.cout) {
610         pids.byname.cout= 0;
611         taskfail= "output cat";
612       } else if (pid == pids.byname.sl) {
613         pids.byname.sl= 0;
614         taskfail= "slattach";
615       } else {
616         continue;
617       }
618       break;
619     }
620     if (taskfail) {
621       if (WIFEXITED(status)) {
622         fprintf(stderr,
623                 "userv-ipif service: %s unexpectedly exited with exit status %d\n",
624                 taskfail, WEXITSTATUS(status));
625       } else if (WIFSIGNALED(status)) {
626         fprintf(stderr,
627                 "userv-ipif service: %s unexpectedly killed by signal %s%s\n",
628                 taskfail, strsignal(WTERMSIG(status)),
629                 WCOREDUMP(status) ? " (core dumped)" : "");
630       } else {
631         fprintf(stderr, "userv-ipif service: %s unexpectedly terminated"
632                 " with unknown status code %d\n", taskfail, status);
633       }
634     }
635   } else {
636     fprintf(stderr,
637             "userv-ipif service: received signal %d, terminating\n",
638             signum);
639   }
640
641   terminate(estatus);
642 }
643
644 static void startup(void) {
645   int r;
646   struct sigaction sa;
647   
648   sigfillset(&fullset);
649   sigemptyset(&emptyset);
650
651   ptmaster= getpt();  if (ptmaster==-1) sysfatal("allocate pty master");
652   r= grantpt(ptmaster);  if (r) sysfatal("grab/grant pty slave");
653   ptyname= ptsname(ptmaster);  if (!ptyname) sysfatal("get pty slave name");
654   r= chmod(ptyname,0600);  if (r) sysfatal("chmod pty slave");
655   r= unlockpt(ptmaster);  if (r) sysfatal("unlock pty");
656
657   sigfillset(&sa.sa_mask);
658   setsignals(sighandler,&sa,SA_NOCLDSTOP);
659   setsigmask(&fullset);
660 }
661
662 static void startslattach(void) {
663   static char ifnbuf[200];
664
665   FILE *piper;
666   int r, l, k;
667
668   r= pipe(slpipe);  if (r) sysfatal("create pipe");
669   piper= fdopen(slpipe[0],"r");  if (!piper) sysfatal("fdopen pipe");
670
671   undoslattach= 1;
672   pids.byname.sl= makesubproc(sl_entry);
673
674   close(slpipe[1]);
675   setsigmask(&emptyset);
676   if (!fgets(ifnbuf,sizeof(ifnbuf),piper)) {
677     if (ferror(piper)) sysfatal("cannot read ifname from slattach");
678     else fatal("cannot read ifname from slattach");
679   }
680   setsigmask(&fullset);
681   l= strlen(ifnbuf);
682   if (l<0 || ifnbuf[l-1] != '\n') fatal("slattach gave strange output `%s'",ifnbuf);
683   ifnbuf[l-1]= 0;
684   for (k=l; k>0 && ifnbuf[k-1]!=' '; k--);
685   ifname= ifnbuf+k;
686 }
687
688 static void netconfigure(void) {
689   char mtutxt[100];
690   int i;
691
692   if (task()) {
693     sprintf(mtutxt,"%lu",mtu);
694   
695     execlp("ifconfig", "ifconfig", ifname, localtxt,
696            "netmask","255.255.255.255", "-broadcast", "pointopoint",peertxt,
697            "mtu",mtutxt, "up", (char*)0);
698     sysfatal("cannot exec ifconfig");
699   }
700
701   for (i=0; i<nexroutes; i++) {
702     if (task()) {
703       execlp("route","route", "add", "-net",exroutes[i].prefixtxt,
704              "netmask",exroutes[i].masktxt,
705              "gw",peertxt, "dev",ifname, (char*)0);
706       sysfatal("cannot exec route (for route)");
707     }
708   }
709 }
710
711 static void copydata(void) __attribute__((noreturn));
712 static void copydata(void) {
713   int r;
714   
715   pids.byname.cin= makesubproc(cin_entry);
716   for (;;) {
717     r= write(1, "\300", 1); if (r==1) break;
718     assert(r==-1);  if (errno != EINTR) sysfatal("send initial delim to confirm");
719   }
720   pids.byname.cout= makesubproc(cout_entry);
721
722   for (;;) sigsuspend(&emptyset);
723 }
724
725 int main(int argc, const char *const *argv) {
726   parseargs(argc,argv);
727   pconfig(configstr,0);
728   checkpermit();
729   if (!proto) dumpdebug();
730
731   startup();
732   startslattach();
733   netconfigure();
734   copydata();
735 }