[MINI2440] Force the amount of memory
[qemu/mini2440/sniper_sniper_test.git] / slirp / misc.c
blob662039185073b2eddc6a66a9cbd77fe2ff0eb8f5
1 /*
2 * Copyright (c) 1995 Danny Gasparovski.
4 * Please read the file COPYRIGHT for the
5 * terms and conditions of the copyright.
6 */
8 #define WANT_SYS_IOCTL_H
9 #include <slirp.h>
11 u_int curtime, time_fasttimo, last_slowtimo;
13 #if 0
14 int x_port = -1;
15 int x_display = 0;
16 int x_screen = 0;
18 int
19 show_x(buff, inso)
20 char *buff;
21 struct socket *inso;
23 if (x_port < 0) {
24 lprint("X Redir: X not being redirected.\r\n");
25 } else {
26 lprint("X Redir: In sh/bash/zsh/etc. type: DISPLAY=%s:%d.%d; export DISPLAY\r\n",
27 inet_ntoa(our_addr), x_port, x_screen);
28 lprint("X Redir: In csh/tcsh/etc. type: setenv DISPLAY %s:%d.%d\r\n",
29 inet_ntoa(our_addr), x_port, x_screen);
30 if (x_display)
31 lprint("X Redir: Redirecting to display %d\r\n", x_display);
34 return CFG_OK;
39 * XXX Allow more than one X redirection?
41 void
42 redir_x(inaddr, start_port, display, screen)
43 u_int32_t inaddr;
44 int start_port;
45 int display;
46 int screen;
48 int i;
50 if (x_port >= 0) {
51 lprint("X Redir: X already being redirected.\r\n");
52 show_x(0, 0);
53 } else {
54 for (i = 6001 + (start_port-1); i <= 6100; i++) {
55 if (solisten(htons(i), inaddr, htons(6000 + display), 0)) {
56 /* Success */
57 x_port = i - 6000;
58 x_display = display;
59 x_screen = screen;
60 show_x(0, 0);
61 return;
64 lprint("X Redir: Error: Couldn't redirect a port for X. Weird.\r\n");
67 #endif
70 * Get our IP address and put it in our_addr
72 void
73 getouraddr(void)
75 char buff[256];
76 struct hostent *he = NULL;
78 if (gethostname(buff,256) == 0)
79 he = gethostbyname(buff);
80 if (he)
81 our_addr = *(struct in_addr *)he->h_addr;
82 if (our_addr.s_addr == 0)
83 our_addr.s_addr = loopback_addr.s_addr;
86 struct quehead {
87 struct quehead *qh_link;
88 struct quehead *qh_rlink;
91 inline void
92 insque(void *a, void *b)
94 register struct quehead *element = (struct quehead *) a;
95 register struct quehead *head = (struct quehead *) b;
96 element->qh_link = head->qh_link;
97 head->qh_link = (struct quehead *)element;
98 element->qh_rlink = (struct quehead *)head;
99 ((struct quehead *)(element->qh_link))->qh_rlink
100 = (struct quehead *)element;
103 inline void
104 remque(void *a)
106 register struct quehead *element = (struct quehead *) a;
107 ((struct quehead *)(element->qh_link))->qh_rlink = element->qh_rlink;
108 ((struct quehead *)(element->qh_rlink))->qh_link = element->qh_link;
109 element->qh_rlink = NULL;
110 /* element->qh_link = NULL; TCP FIN1 crashes if you do this. Why ? */
113 /* #endif */
117 add_exec(struct ex_list **ex_ptr, int do_pty, char *exec, int addr, int port)
119 struct ex_list *tmp_ptr;
121 /* First, check if the port is "bound" */
122 for (tmp_ptr = *ex_ptr; tmp_ptr; tmp_ptr = tmp_ptr->ex_next) {
123 if (port == tmp_ptr->ex_fport && addr == tmp_ptr->ex_addr)
124 return -1;
127 tmp_ptr = *ex_ptr;
128 *ex_ptr = (struct ex_list *)malloc(sizeof(struct ex_list));
129 (*ex_ptr)->ex_fport = port;
130 (*ex_ptr)->ex_addr = addr;
131 (*ex_ptr)->ex_pty = do_pty;
132 (*ex_ptr)->ex_exec = (do_pty == 3) ? exec : strdup(exec);
133 (*ex_ptr)->ex_next = tmp_ptr;
134 return 0;
137 #ifndef HAVE_STRERROR
140 * For systems with no strerror
143 extern int sys_nerr;
144 extern char *sys_errlist[];
146 char *
147 strerror(error)
148 int error;
150 if (error < sys_nerr)
151 return sys_errlist[error];
152 else
153 return "Unknown error.";
156 #endif
159 #ifdef _WIN32
162 fork_exec(struct socket *so, const char *ex, int do_pty)
164 /* not implemented */
165 return 0;
168 #else
170 #ifndef CONFIG_QEMU
172 slirp_openpty(amaster, aslave)
173 int *amaster, *aslave;
175 register int master, slave;
177 #ifdef HAVE_GRANTPT
178 char *ptr;
180 if ((master = open("/dev/ptmx", O_RDWR)) < 0 ||
181 grantpt(master) < 0 ||
182 unlockpt(master) < 0 ||
183 (ptr = ptsname(master)) == NULL) {
184 close(master);
185 return -1;
188 if ((slave = open(ptr, O_RDWR)) < 0 ||
189 ioctl(slave, I_PUSH, "ptem") < 0 ||
190 ioctl(slave, I_PUSH, "ldterm") < 0 ||
191 ioctl(slave, I_PUSH, "ttcompat") < 0) {
192 close(master);
193 close(slave);
194 return -1;
197 *amaster = master;
198 *aslave = slave;
199 return 0;
201 #else
203 static char line[] = "/dev/ptyXX";
204 register const char *cp1, *cp2;
206 for (cp1 = "pqrsPQRS"; *cp1; cp1++) {
207 line[8] = *cp1;
208 for (cp2 = "0123456789abcdefghijklmnopqrstuv"; *cp2; cp2++) {
209 line[9] = *cp2;
210 if ((master = open(line, O_RDWR, 0)) == -1) {
211 if (errno == ENOENT)
212 return (-1); /* out of ptys */
213 } else {
214 line[5] = 't';
215 /* These will fail */
216 (void) chown(line, getuid(), 0);
217 (void) chmod(line, S_IRUSR|S_IWUSR|S_IWGRP);
218 #ifdef HAVE_REVOKE
219 (void) revoke(line);
220 #endif
221 if ((slave = open(line, O_RDWR, 0)) != -1) {
222 *amaster = master;
223 *aslave = slave;
224 return 0;
226 (void) close(master);
227 line[5] = 'p';
231 errno = ENOENT; /* out of ptys */
232 return (-1);
233 #endif
235 #endif
238 * XXX This is ugly
239 * We create and bind a socket, then fork off to another
240 * process, which connects to this socket, after which we
241 * exec the wanted program. If something (strange) happens,
242 * the accept() call could block us forever.
244 * do_pty = 0 Fork/exec inetd style
245 * do_pty = 1 Fork/exec using slirp.telnetd
246 * do_ptr = 2 Fork/exec using pty
249 fork_exec(struct socket *so, const char *ex, int do_pty)
251 int s;
252 struct sockaddr_in addr;
253 socklen_t addrlen = sizeof(addr);
254 int opt;
255 int master = -1;
256 const char *argv[256];
257 #if 0
258 char buff[256];
259 #endif
260 /* don't want to clobber the original */
261 char *bptr;
262 const char *curarg;
263 int c, i, ret;
265 DEBUG_CALL("fork_exec");
266 DEBUG_ARG("so = %lx", (long)so);
267 DEBUG_ARG("ex = %lx", (long)ex);
268 DEBUG_ARG("do_pty = %lx", (long)do_pty);
270 if (do_pty == 2) {
271 #if 0
272 if (slirp_openpty(&master, &s) == -1) {
273 lprint("Error: openpty failed: %s\n", strerror(errno));
274 return 0;
276 #else
277 return 0;
278 #endif
279 } else {
280 addr.sin_family = AF_INET;
281 addr.sin_port = 0;
282 addr.sin_addr.s_addr = INADDR_ANY;
284 if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0 ||
285 bind(s, (struct sockaddr *)&addr, addrlen) < 0 ||
286 listen(s, 1) < 0) {
287 lprint("Error: inet socket: %s\n", strerror(errno));
288 closesocket(s);
290 return 0;
294 switch(fork()) {
295 case -1:
296 lprint("Error: fork failed: %s\n", strerror(errno));
297 close(s);
298 if (do_pty == 2)
299 close(master);
300 return 0;
302 case 0:
303 /* Set the DISPLAY */
304 if (do_pty == 2) {
305 (void) close(master);
306 #ifdef TIOCSCTTY /* XXXXX */
307 (void) setsid();
308 ioctl(s, TIOCSCTTY, (char *)NULL);
309 #endif
310 } else {
311 getsockname(s, (struct sockaddr *)&addr, &addrlen);
312 close(s);
314 * Connect to the socket
315 * XXX If any of these fail, we're in trouble!
317 s = socket(AF_INET, SOCK_STREAM, 0);
318 addr.sin_addr = loopback_addr;
319 do {
320 ret = connect(s, (struct sockaddr *)&addr, addrlen);
321 } while (ret < 0 && errno == EINTR);
324 #if 0
325 if (x_port >= 0) {
326 #ifdef HAVE_SETENV
327 sprintf(buff, "%s:%d.%d", inet_ntoa(our_addr), x_port, x_screen);
328 setenv("DISPLAY", buff, 1);
329 #else
330 sprintf(buff, "DISPLAY=%s:%d.%d", inet_ntoa(our_addr), x_port, x_screen);
331 putenv(buff);
332 #endif
334 #endif
335 dup2(s, 0);
336 dup2(s, 1);
337 dup2(s, 2);
338 for (s = getdtablesize() - 1; s >= 3; s--)
339 close(s);
341 i = 0;
342 bptr = strdup(ex); /* No need to free() this */
343 if (do_pty == 1) {
344 /* Setup "slirp.telnetd -x" */
345 argv[i++] = "slirp.telnetd";
346 argv[i++] = "-x";
347 argv[i++] = bptr;
348 } else
349 do {
350 /* Change the string into argv[] */
351 curarg = bptr;
352 while (*bptr != ' ' && *bptr != (char)0)
353 bptr++;
354 c = *bptr;
355 *bptr++ = (char)0;
356 argv[i++] = strdup(curarg);
357 } while (c);
359 argv[i] = NULL;
360 execvp(argv[0], (char **)argv);
362 /* Ooops, failed, let's tell the user why */
364 char buff[256];
366 snprintf(buff, sizeof(buff),
367 "Error: execvp of %s failed: %s\n",
368 argv[0], strerror(errno));
369 write(2, buff, strlen(buff)+1);
371 close(0); close(1); close(2); /* XXX */
372 exit(1);
374 default:
375 if (do_pty == 2) {
376 close(s);
377 so->s = master;
378 } else {
380 * XXX this could block us...
381 * XXX Should set a timer here, and if accept() doesn't
382 * return after X seconds, declare it a failure
383 * The only reason this will block forever is if socket()
384 * of connect() fail in the child process
386 do {
387 so->s = accept(s, (struct sockaddr *)&addr, &addrlen);
388 } while (so->s < 0 && errno == EINTR);
389 closesocket(s);
390 opt = 1;
391 setsockopt(so->s,SOL_SOCKET,SO_REUSEADDR,(char *)&opt,sizeof(int));
392 opt = 1;
393 setsockopt(so->s,SOL_SOCKET,SO_OOBINLINE,(char *)&opt,sizeof(int));
395 fd_nonblock(so->s);
397 /* Append the telnet options now */
398 if (so->so_m != NULL && do_pty == 1) {
399 sbappend(so, so->so_m);
400 so->so_m = NULL;
403 return 1;
406 #endif
408 #ifndef HAVE_STRDUP
409 char *
410 strdup(str)
411 const char *str;
413 char *bptr;
415 bptr = (char *)malloc(strlen(str)+1);
416 strcpy(bptr, str);
418 return bptr;
420 #endif
422 #if 0
423 void
424 snooze_hup(num)
425 int num;
427 int s, ret;
428 #ifndef NO_UNIX_SOCKETS
429 struct sockaddr_un sock_un;
430 #endif
431 struct sockaddr_in sock_in;
432 char buff[256];
434 ret = -1;
435 if (slirp_socket_passwd) {
436 s = socket(AF_INET, SOCK_STREAM, 0);
437 if (s < 0)
438 slirp_exit(1);
439 sock_in.sin_family = AF_INET;
440 sock_in.sin_addr.s_addr = slirp_socket_addr;
441 sock_in.sin_port = htons(slirp_socket_port);
442 if (connect(s, (struct sockaddr *)&sock_in, sizeof(sock_in)) != 0)
443 slirp_exit(1); /* just exit...*/
444 sprintf(buff, "kill %s:%d", slirp_socket_passwd, slirp_socket_unit);
445 write(s, buff, strlen(buff)+1);
447 #ifndef NO_UNIX_SOCKETS
448 else {
449 s = socket(AF_UNIX, SOCK_STREAM, 0);
450 if (s < 0)
451 slirp_exit(1);
452 sock_un.sun_family = AF_UNIX;
453 strcpy(sock_un.sun_path, socket_path);
454 if (connect(s, (struct sockaddr *)&sock_un,
455 sizeof(sock_un.sun_family) + sizeof(sock_un.sun_path)) != 0)
456 slirp_exit(1);
457 sprintf(buff, "kill none:%d", slirp_socket_unit);
458 write(s, buff, strlen(buff)+1);
460 #endif
461 slirp_exit(0);
465 void
466 snooze()
468 sigset_t s;
469 int i;
471 /* Don't need our data anymore */
472 /* XXX This makes SunOS barf */
473 /* brk(0); */
475 /* Close all fd's */
476 for (i = 255; i >= 0; i--)
477 close(i);
479 signal(SIGQUIT, slirp_exit);
480 signal(SIGHUP, snooze_hup);
481 sigemptyset(&s);
483 /* Wait for any signal */
484 sigsuspend(&s);
486 /* Just in case ... */
487 exit(255);
490 void
491 relay(s)
492 int s;
494 char buf[8192];
495 int n;
496 fd_set readfds;
497 struct ttys *ttyp;
499 /* Don't need our data anymore */
500 /* XXX This makes SunOS barf */
501 /* brk(0); */
503 signal(SIGQUIT, slirp_exit);
504 signal(SIGHUP, slirp_exit);
505 signal(SIGINT, slirp_exit);
506 signal(SIGTERM, slirp_exit);
508 /* Fudge to get term_raw and term_restore to work */
509 if (NULL == (ttyp = tty_attach (0, slirp_tty))) {
510 lprint ("Error: tty_attach failed in misc.c:relay()\r\n");
511 slirp_exit (1);
513 ttyp->fd = 0;
514 ttyp->flags |= TTY_CTTY;
515 term_raw(ttyp);
517 while (1) {
518 FD_ZERO(&readfds);
520 FD_SET(0, &readfds);
521 FD_SET(s, &readfds);
523 n = select(s+1, &readfds, (fd_set *)0, (fd_set *)0, (struct timeval *)0);
525 if (n <= 0)
526 slirp_exit(0);
528 if (FD_ISSET(0, &readfds)) {
529 n = read(0, buf, 8192);
530 if (n <= 0)
531 slirp_exit(0);
532 n = writen(s, buf, n);
533 if (n <= 0)
534 slirp_exit(0);
537 if (FD_ISSET(s, &readfds)) {
538 n = read(s, buf, 8192);
539 if (n <= 0)
540 slirp_exit(0);
541 n = writen(0, buf, n);
542 if (n <= 0)
543 slirp_exit(0);
547 /* Just in case.... */
548 exit(1);
550 #endif
552 #ifdef CONFIG_QEMU
553 #include "monitor.h"
555 void lprint(const char *format, ...)
557 va_list args;
559 va_start(args, format);
560 monitor_vprintf(cur_mon, format, args);
561 va_end(args);
563 #else
564 int (*lprint_print) _P((void *, const char *, va_list));
565 char *lprint_ptr, *lprint_ptr2, **lprint_arg;
567 void
568 #ifdef __STDC__
569 lprint(const char *format, ...)
570 #else
571 lprint(va_alist) va_dcl
572 #endif
574 va_list args;
576 #ifdef __STDC__
577 va_start(args, format);
578 #else
579 char *format;
580 va_start(args);
581 format = va_arg(args, char *);
582 #endif
583 #if 0
584 /* If we're printing to an sbuf, make sure there's enough room */
585 /* XXX +100? */
586 if (lprint_sb) {
587 if ((lprint_ptr - lprint_sb->sb_wptr) >=
588 (lprint_sb->sb_datalen - (strlen(format) + 100))) {
589 int deltaw = lprint_sb->sb_wptr - lprint_sb->sb_data;
590 int deltar = lprint_sb->sb_rptr - lprint_sb->sb_data;
591 int deltap = lprint_ptr - lprint_sb->sb_data;
593 lprint_sb->sb_data = (char *)realloc(lprint_sb->sb_data,
594 lprint_sb->sb_datalen + TCP_SNDSPACE);
596 /* Adjust all values */
597 lprint_sb->sb_wptr = lprint_sb->sb_data + deltaw;
598 lprint_sb->sb_rptr = lprint_sb->sb_data + deltar;
599 lprint_ptr = lprint_sb->sb_data + deltap;
601 lprint_sb->sb_datalen += TCP_SNDSPACE;
604 #endif
605 if (lprint_print)
606 lprint_ptr += (*lprint_print)(*lprint_arg, format, args);
608 /* Check if they want output to be logged to file as well */
609 if (lfd) {
611 * Remove \r's
612 * otherwise you'll get ^M all over the file
614 int len = strlen(format);
615 char *bptr1, *bptr2;
617 bptr1 = bptr2 = strdup(format);
619 while (len--) {
620 if (*bptr1 == '\r')
621 memcpy(bptr1, bptr1+1, len+1);
622 else
623 bptr1++;
625 vfprintf(lfd, bptr2, args);
626 free(bptr2);
628 va_end(args);
631 void
632 add_emu(buff)
633 char *buff;
635 u_int lport, fport;
636 u_int8_t tos = 0, emu = 0;
637 char buff1[256], buff2[256], buff4[128];
638 char *buff3 = buff4;
639 struct emu_t *emup;
640 struct socket *so;
642 if (sscanf(buff, "%256s %256s", buff2, buff1) != 2) {
643 lprint("Error: Bad arguments\r\n");
644 return;
647 if (sscanf(buff1, "%d:%d", &lport, &fport) != 2) {
648 lport = 0;
649 if (sscanf(buff1, "%d", &fport) != 1) {
650 lprint("Error: Bad first argument\r\n");
651 return;
655 if (sscanf(buff2, "%128[^:]:%128s", buff1, buff3) != 2) {
656 buff3 = 0;
657 if (sscanf(buff2, "%256s", buff1) != 1) {
658 lprint("Error: Bad second argument\r\n");
659 return;
663 if (buff3) {
664 if (strcmp(buff3, "lowdelay") == 0)
665 tos = IPTOS_LOWDELAY;
666 else if (strcmp(buff3, "throughput") == 0)
667 tos = IPTOS_THROUGHPUT;
668 else {
669 lprint("Error: Expecting \"lowdelay\"/\"throughput\"\r\n");
670 return;
674 if (strcmp(buff1, "ftp") == 0)
675 emu = EMU_FTP;
676 else if (strcmp(buff1, "irc") == 0)
677 emu = EMU_IRC;
678 else if (strcmp(buff1, "none") == 0)
679 emu = EMU_NONE; /* ie: no emulation */
680 else {
681 lprint("Error: Unknown service\r\n");
682 return;
685 /* First, check that it isn't already emulated */
686 for (emup = tcpemu; emup; emup = emup->next) {
687 if (emup->lport == lport && emup->fport == fport) {
688 lprint("Error: port already emulated\r\n");
689 return;
693 /* link it */
694 emup = (struct emu_t *)malloc(sizeof (struct emu_t));
695 emup->lport = (u_int16_t)lport;
696 emup->fport = (u_int16_t)fport;
697 emup->tos = tos;
698 emup->emu = emu;
699 emup->next = tcpemu;
700 tcpemu = emup;
702 /* And finally, mark all current sessions, if any, as being emulated */
703 for (so = tcb.so_next; so != &tcb; so = so->so_next) {
704 if ((lport && lport == ntohs(so->so_lport)) ||
705 (fport && fport == ntohs(so->so_fport))) {
706 if (emu)
707 so->so_emu = emu;
708 if (tos)
709 so->so_iptos = tos;
713 lprint("Adding emulation for %s to port %d/%d\r\n", buff1, emup->lport, emup->fport);
715 #endif
717 #ifdef BAD_SPRINTF
719 #undef vsprintf
720 #undef sprintf
723 * Some BSD-derived systems have a sprintf which returns char *
727 vsprintf_len(string, format, args)
728 char *string;
729 const char *format;
730 va_list args;
732 vsprintf(string, format, args);
733 return strlen(string);
737 #ifdef __STDC__
738 sprintf_len(char *string, const char *format, ...)
739 #else
740 sprintf_len(va_alist) va_dcl
741 #endif
743 va_list args;
744 #ifdef __STDC__
745 va_start(args, format);
746 #else
747 char *string;
748 char *format;
749 va_start(args);
750 string = va_arg(args, char *);
751 format = va_arg(args, char *);
752 #endif
753 vsprintf(string, format, args);
754 return strlen(string);
757 #endif
759 void
760 u_sleep(int usec)
762 struct timeval t;
763 fd_set fdset;
765 FD_ZERO(&fdset);
767 t.tv_sec = 0;
768 t.tv_usec = usec * 1000;
770 select(0, &fdset, &fdset, &fdset, &t);
774 * Set fd blocking and non-blocking
777 void
778 fd_nonblock(int fd)
780 #ifdef FIONBIO
781 int opt = 1;
783 ioctlsocket(fd, FIONBIO, &opt);
784 #else
785 int opt;
787 opt = fcntl(fd, F_GETFL, 0);
788 opt |= O_NONBLOCK;
789 fcntl(fd, F_SETFL, opt);
790 #endif
793 void
794 fd_block(int fd)
796 #ifdef FIONBIO
797 int opt = 0;
799 ioctlsocket(fd, FIONBIO, &opt);
800 #else
801 int opt;
803 opt = fcntl(fd, F_GETFL, 0);
804 opt &= ~O_NONBLOCK;
805 fcntl(fd, F_SETFL, opt);
806 #endif
810 #if 0
812 * invoke RSH
815 rsh_exec(so,ns, user, host, args)
816 struct socket *so;
817 struct socket *ns;
818 char *user;
819 char *host;
820 char *args;
822 int fd[2];
823 int fd0[2];
824 int s;
825 char buff[256];
827 DEBUG_CALL("rsh_exec");
828 DEBUG_ARG("so = %lx", (long)so);
830 if (pipe(fd)<0) {
831 lprint("Error: pipe failed: %s\n", strerror(errno));
832 return 0;
834 /* #ifdef HAVE_SOCKETPAIR */
835 #if 1
836 if (socketpair(PF_UNIX,SOCK_STREAM,0, fd0) == -1) {
837 close(fd[0]);
838 close(fd[1]);
839 lprint("Error: openpty failed: %s\n", strerror(errno));
840 return 0;
842 #else
843 if (slirp_openpty(&fd0[0], &fd0[1]) == -1) {
844 close(fd[0]);
845 close(fd[1]);
846 lprint("Error: openpty failed: %s\n", strerror(errno));
847 return 0;
849 #endif
851 switch(fork()) {
852 case -1:
853 lprint("Error: fork failed: %s\n", strerror(errno));
854 close(fd[0]);
855 close(fd[1]);
856 close(fd0[0]);
857 close(fd0[1]);
858 return 0;
860 case 0:
861 close(fd[0]);
862 close(fd0[0]);
864 /* Set the DISPLAY */
865 if (x_port >= 0) {
866 #ifdef HAVE_SETENV
867 sprintf(buff, "%s:%d.%d", inet_ntoa(our_addr), x_port, x_screen);
868 setenv("DISPLAY", buff, 1);
869 #else
870 sprintf(buff, "DISPLAY=%s:%d.%d", inet_ntoa(our_addr), x_port, x_screen);
871 putenv(buff);
872 #endif
875 dup2(fd0[1], 0);
876 dup2(fd0[1], 1);
877 dup2(fd[1], 2);
878 for (s = 3; s <= 255; s++)
879 close(s);
881 execlp("rsh","rsh","-l", user, host, args, NULL);
883 /* Ooops, failed, let's tell the user why */
885 sprintf(buff, "Error: execlp of %s failed: %s\n",
886 "rsh", strerror(errno));
887 write(2, buff, strlen(buff)+1);
888 close(0); close(1); close(2); /* XXX */
889 exit(1);
891 default:
892 close(fd[1]);
893 close(fd0[1]);
894 ns->s=fd[0];
895 so->s=fd0[0];
897 return 1;
900 #endif