Changeset 28158 for trunk/Ohana/src/opihi/pcontrol/StopHosts.c
- Timestamp:
- May 28, 2010, 11:51:46 AM (16 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/pcontrol/StopHosts.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/pcontrol/StopHosts.c
r27592 r28158 1 1 # include "pcontrol.h" 2 3 // we attempt to harvest the 'down' hosts in HarvestHost. However, sometimes the 4 // child is busy and does not exit in the timeout period. we need to keep a list and 5 // try again occasionally to free up the needed resources 6 static int NUNHARVESTED = 0; 7 static int Nunharvested = 0; 8 static int *unharvested = NULL; 2 9 3 10 void DownHost (Host *host) { … … 140 147 switch (errno) { 141 148 case ECHILD: 142 gprint (GP_ERR, " unknown PID, not a child proc\n");149 gprint (GP_ERR, "HarvestHost: unknown PID (%d), not a child proc\n", pid); 143 150 gprint (GP_ERR, "did process already exit? programming error?\n"); 144 151 break; … … 152 159 153 160 case 0: 154 gprint (GP_ERR, "HarvestHost: child with connection to remote host failed to exit: may be hung"); 161 gprint (GP_ERR, "HarvestHost: child with connection to remote host failed to exit: may be hung\n"); 162 AddZombie(pid); 155 163 break; 156 164 … … 174 182 return (TRUE); 175 183 } 184 185 int AddZombie(int pid) { 186 187 if (unharvested == NULL) { 188 NUNHARVESTED = 128; 189 ALLOCATE (unharvested, int, NUNHARVESTED); 190 memset (unharvested, 0, NUNHARVESTED*sizeof(int)); 191 } 192 unharvested[Nunharvested] = pid; 193 194 Nunharvested ++; 195 if (Nunharvested >= NUNHARVESTED) { 196 NUNHARVESTED += 128; 197 REALLOCATE (unharvested, int, NUNHARVESTED); 198 memset (&unharvested[Nunharvested], 0, (NUNHARVESTED - Nunharvested)*sizeof(int)); 199 } 200 return TRUE; 201 } 202 203 int DelZombies() { 204 205 int i, j; 206 207 if (!unharvested) return FALSE; 208 if (!Nunharvested) return FALSE; 209 if (!NUNHARVESTED) return FALSE; 210 211 int *newlist = NULL; 212 213 ALLOCATE (newlist, int, NUNHARVESTED); 214 memset (newlist, 0, NUNHARVESTED*sizeof(int)); 215 216 j = 0; 217 for (i = 0; i < NUNHARVESTED; i++) { 218 if (!unharvested[i]) continue; 219 newlist[j] = unharvested[i]; 220 j++; 221 } 222 free (unharvested); 223 unharvested = newlist; 224 Nunharvested = j; 225 return TRUE; 226 } 227 228 int CheckZombies() { 229 230 int pid, i, result, waitstatus; 231 232 if (!unharvested) return FALSE; 233 if (!Nunharvested) return FALSE; 234 if (!NUNHARVESTED) return FALSE; 235 236 for (i = 0; i < Nunharvested; i++) { 237 if (!unharvested[i]) continue; 238 pid = unharvested[i]; 239 result = waitpid (pid, &waitstatus, WNOHANG); 240 switch (result) { 241 case -1: /* error with waitpid */ 242 switch (errno) { 243 case ECHILD: 244 gprint (GP_ERR, "CheckZombies: unknown PID (%d), not a child proc\n", pid); 245 gprint (GP_ERR, "did process already exit? programming error?\n"); 246 break; 247 case EINTR: 248 case EINVAL: 249 default: 250 perror ("unexpected error"); 251 ABORT ("CheckZombies impossible condition"); 252 } 253 break; 254 255 case 0: 256 if (VerboseMode()) gprint (GP_ERR, "CheckZombies: still waiting on %d\n", pid); 257 break; 258 259 default: 260 if (result != pid) { 261 gprint (GP_ERR, "waitpid error: mis-matched PID (%d vs %d). programming error\n", result, pid); 262 ABORT ("CheckZombies impossible condition"); 263 } 264 265 if (WIFEXITED(waitstatus)) { 266 if (VerboseMode()) gprint (GP_ERR, "child exited with status %d\n", WEXITSTATUS(waitstatus)); 267 } 268 if (WIFSIGNALED(waitstatus)) { 269 if (VerboseMode()) gprint (GP_ERR, "child crashed with status %d\n", WTERMSIG(waitstatus)); 270 } 271 if (WIFSTOPPED(waitstatus)) { 272 ABORT ("waitpid returns 'stopped': programming error\n"); 273 } 274 unharvested[i] = 0; 275 break; 276 } 277 } 278 DelZombies(); 279 return (TRUE); 280 }
Note:
See TracChangeset
for help on using the changeset viewer.
