PennMUSH Community

Changeset 1223

Show
Ignore:
Timestamp:
03/07/08 00:09:48 (6 months ago)
Author:
shawnw
Message:

Use fds 0 and 1 for talking with info_slave instead of passing a fd on its command line.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 1.8.3/branches/devel/src/info_master.c

    r1158 r1223  
    9494{ 
    9595  int socks[2]; 
    96   char num[NI_MAXSERV]; 
    9796  pid_t child; 
    9897  int n; 
     
    140139  } else { 
    141140    int errfd = fileno(stderr); 
    142     /* Close unneeded fds and sockets: Everything but stdout and the socket used to talk to the mush */ 
     141    int dupfd; 
     142 
     143    /* Close unneeded fds and sockets: Everything but stderr and the 
     144       socket used to talk to the mush */ 
    143145    for (n = 0; n < maxd; n++) { 
    144146      if (n == errfd) 
     
    150152      close(n); 
    151153    } 
    152     snprintf(num, NI_MAXSERV, "%d", socks[1]); 
    153     execl("./info_slave", "info_slave", num, (char *) NULL); 
     154    /* Reuse stdin and stdout for talking to the slave */ 
     155    dupfd = dup2(socks[1], 0); 
     156    if (dupfd < 0) { 
     157      penn_perror("dup2() of stdin in info_slave"); 
     158      exit(1); 
     159    } 
     160 
     161    dupfd = dup2(socks[1], 1); 
     162    if (dupfd < 0) { 
     163      penn_perror("dup2() of stdout in info_slave"); 
     164      exit(1); 
     165    } 
     166 
     167    close(socks[1]); 
     168 
     169    execl("./info_slave", "info_slave", (char *) NULL); 
    154170    penn_perror("execing info slave"); 
    155     _exit(1); 
     171    exit(1); 
    156172  } 
    157173 
  • 1.8.3/branches/devel/src/info_slave.c

    r1164 r1223  
    8787 
    8888int 
    89 main(int argc, char *argv[]) 
    90 
    91   int mush, port; 
     89main(void) 
     90
    9291  struct request_dgram req; 
    9392  struct response_dgram resp; 
     
    9695  char localport[NI_MAXSERV]; 
    9796 
    98   if (argc < 2) { 
    99     fputerr("info_slave needs a port number!"); 
    100     return EXIT_FAILURE; 
    101   } 
    102   port = strtol(argv[1], NULL, 10); 
    103  
    104   mush = port;                  /* We inherit open file descriptors and sockets from parent */ 
    105  
    10697  if (new_process_group() < 0) 
    10798    penn_perror("making new process group"); 
     
    116107  } 
    117108 
    118   if (eventwait_watch_fd_read(mush) < 0) { 
     109  if (eventwait_watch_fd_read(0) < 0) { 
    119110    penn_perror("eventwait_add_fd"); 
    120111    return EXIT_FAILURE; 
     
    135126    int ev = eventwait(); 
    136127 
    137     if (ev == mush
    138       len = recv(mush, &req, sizeof req, 0); 
     128    if (ev == 0
     129      len = recv(0, &req, sizeof req, 0); 
    139130    else if (ev == (int) netmush) { 
    140131      /* Parent process exited. Exit too. */ 
     
    217208      strcpy(resp.hostname, resp.ipaddr); 
    218209 
    219     len = send(mush, &resp, sizeof resp, 0); 
     210    len = send(1, &resp, sizeof resp, 0); 
    220211 
    221212    /* Should never happen. */