home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff294.lzh / DNet / unix / dnet / double.c < prev    next >
C/C++ Source or Header  |  1989-12-11  |  2KB  |  88 lines

  1.  
  2. /*
  3.  *  DOUBLE
  4.  *
  5.  *  DOUBLE DNETDIRA DNETDIRB
  6.  *
  7.  *  Run dnet using a pipe (for testing)
  8.  */
  9.  
  10. #include <stdio.h>
  11. #include <fcntl.h>
  12. #include <sys/types.h>
  13. #include <sys/socket.h>
  14. #include <netinet/in.h>
  15. #include <netdb.h>
  16.  
  17. main(ac, av, envp)
  18. char *av[];
  19. char **envp;
  20. {
  21.     int files[2];
  22.     short i;
  23.     char buf[256];
  24.     char cmd[256];
  25.  
  26.     if (ac != 3) {
  27.     puts("double dnetdira dnetdirb");
  28.     exit(1);
  29.     }
  30.  
  31.     for (i = 0; envp[i]; ++i) {
  32.     if (strncmp(envp[i], "DNETDIR=", 8) == 0)
  33.         break;
  34.     }
  35.     if (envp[i] == NULL) {
  36.     puts("must set a dummy DNETDIR enviroment variable");
  37.     exit(1);
  38.     }
  39.  
  40.  
  41.     if (socketpair(AF_UNIX, SOCK_STREAM, 0, files) < 0) {
  42.     perror("socketpair");
  43.     exit(1);
  44.     }
  45.  
  46.     envp[i] = buf;
  47.     if (fork() == 0) {
  48.     int fd = open("d1.log", O_WRONLY | O_CREAT | O_TRUNC, 0666);
  49.     if (dup2(files[0], 0) < 0)
  50.         perror("dup2-1");
  51.     dup2(fd, 1);
  52.     dup2(fd, 2);
  53.     if (write(0, "", 0) < 0) {
  54.         perror("write");
  55.         exit(1);
  56.     }
  57.         sprintf(buf, "DNETDIR=%s", av[1]);
  58.     execlp("dnet", "dnet", "debug", NULL);
  59.     perror("exec");
  60.     exit(1);
  61.     }
  62.     if (fork() == 0) {
  63.     int fd = open("d2.log", O_WRONLY | O_CREAT | O_TRUNC, 0666);
  64.     if (dup2(files[1], 0) < 0)
  65.         perror("dup2-1");
  66.     dup2(fd, 1);
  67.     dup2(fd, 2);
  68.     close(files[0]);
  69.     close(files[1]);
  70.     if (write(0, "", 0) < 0) {
  71.         perror("write");
  72.         exit(1);
  73.     }
  74.         sprintf(buf, "DNETDIR=%s", av[2]);
  75.     execlp("dnet", "dnet", "debug", NULL);
  76.     perror("exec");
  77.     exit(1);
  78.     }
  79.     close(files[0]);
  80.     close(files[1]);
  81.     {
  82.     int pid;
  83.         while ((pid = wait(0)) > 0)
  84.         printf("pid %d exit\n", pid);
  85.     }
  86. }
  87.  
  88.