Changeset 4705 for trunk/Ohana/src/opihi/pcontrol/rconnect.c
- Timestamp:
- Aug 3, 2005, 5:50:08 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/pcontrol/rconnect.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/pcontrol/rconnect.c
r4689 r4705 10 10 11 11 int i, stdin_fd[2], stdout_fd[2], stderr_fd[2], status; 12 int result, waitstatus; 12 13 pid_t pid; 13 14 char *p; … … 69 70 70 71 /* 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; 74 74 75 75 /* try to get evidence connection is alive - wait upto a few seconds */ … … 81 81 usleep (20000); 82 82 } 83 if (status == 0) goto connect_error; 84 if (status == -1) goto connect_error; 83 85 if (VerboseMode()) fprintf (stderr, "%d cycles to connect\n", i); 84 if (status == 0) goto pipe_error;85 if (status == -1) goto io_error;86 86 FreeIOBuffer (&buffer); 87 87 … … 98 98 goto close_pipes; 99 99 100 io_error: 101 if (VerboseMode()) fprintf (stderr, "timeout while connecting\n"); 102 goto close_pipes; 100 connect_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 } 103 128 104 129 close_pipes:
Note:
See TracChangeset
for help on using the changeset viewer.
