IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 3, 2005, 5:50:08 PM (21 years ago)
Author:
eugene
Message:

psched / pscontrol / pclient dev work

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/pcontrol/rconnect.c

    r4689 r4705  
    1010
    1111  int i, stdin_fd[2], stdout_fd[2], stderr_fd[2], status;
     12  int result, waitstatus;
    1213  pid_t pid;
    1314  char *p;
     
    6970
    7071  /* send handshake command */
    71   sprintf (command, "echo CONNECTED\n");
    72   status = write (stdin_fd[1], command, strlen(command));
    73   if ((status == -1) && (errno == EPIPE)) goto pipe_error;
     72  status = write_fmt (stdin_fd[1], "echo CONNECTED\n");
     73  if ((status == -1) && (errno == EPIPE)) goto connect_error;
    7474
    7575  /* try to get evidence connection is alive - wait upto a few seconds */
     
    8181    usleep (20000);
    8282  }
     83  if (status == 0) goto connect_error;
     84  if (status == -1) goto connect_error;
    8385  if (VerboseMode()) fprintf (stderr, "%d cycles to connect\n", i);
    84   if (status == 0) goto pipe_error;
    85   if (status == -1) goto io_error;
    8686  FreeIOBuffer (&buffer);
    8787
     
    9898  goto close_pipes;
    9999
    100 io_error:
    101   if (VerboseMode()) fprintf (stderr, "timeout while connecting\n");
    102   goto close_pipes;
     100connect_error:
     101  if (VerboseMode()) fprintf (stderr, "error while connecting\n");
     102
     103  /* harvest the child process: kill & wait (< 100 ms) for exit */
     104  kill (pid, SIGKILL);
     105  result = waitpid (pid, &waitstatus, WNOHANG);
     106  for (i = 0; (i < 10) && (result == 0); i++) {
     107    usleep (10000);  /* 10 ms is min */
     108    result = waitpid (pid, &waitstatus, WNOHANG);
     109  }
     110
     111  if ((result == -1) && (errno != ECHILD)) {
     112    fprintf (stderr, "unexpected error from waitpid (%d): programming error\n", errno);
     113    exit (1);
     114  }
     115  if (result == 0) {
     116    if (VerboseMode()) fprintf (stderr, "child did not exit??");
     117  }
     118  if (result > 0) {
     119    if (result != pid) {
     120      fprintf (stderr, "waitpid error: mis-matched PID (%d vs %d).  programming error\n", result, pid);
     121      exit (1);
     122    }
     123    if (WIFSTOPPED(waitstatus)) {
     124      fprintf (stderr, "waitpid returns 'stopped': programming error\n");
     125      exit (1);
     126    }
     127  }
    103128
    104129close_pipes:
Note: See TracChangeset for help on using the changeset viewer.