| 290 | } |
| 291 | |
| 292 | char* |
| 293 | connectAndSendUserCommand(char c, |
| 294 | int *coordCmdStatus, |
| 295 | int *numPeers, |
| 296 | int *isRunning, |
| 297 | int *ckptInterval) |
| 298 | { |
| 299 | char *replyData = NULL; |
| 300 | int coordFd = createNewSocketToCoordinator(COORD_ANY); |
| 301 | if (coordFd == -1) { |
| 302 | *coordCmdStatus = CoordCmdStatus::ERROR_COORDINATOR_NOT_FOUND; |
| 303 | return replyData; |
| 304 | } |
| 305 | |
| 306 | // Tell the coordinator to run given user command |
| 307 | DmtcpMessage msg(DMT_USER_CMD); |
| 308 | msg.coordCmd = c; |
| 309 | |
| 310 | if (c == 'i') { |
| 311 | const char *interval = getenv(ENV_VAR_CKPT_INTR); |
| 312 | if (interval != NULL) { |
| 313 | msg.theCheckpointInterval = jalib::StringToInt(interval); |
| 314 | } |
| 315 | } |
| 316 | JASSERT(Util::writeAll(coordFd, &msg, sizeof(msg)) == sizeof(msg)); |
| 317 | |
| 318 | // The coordinator will violently close our socket... |
| 319 | if (c == 'q' || c == 'Q') { |
| 320 | *coordCmdStatus = CoordCmdStatus::NOERROR; |
| 321 | return replyData; |
| 322 | } |
| 323 | |
| 324 | // Receive REPLY |
| 325 | DmtcpMessage reply; |
| 326 | reply.poison(); |
| 327 | recvMsgFromCoordinatorRaw(coordFd, &reply, (void**)&replyData); |
| 328 | reply.assertValid(); |
| 329 | JASSERT(reply.type == DMT_USER_CMD_RESULT); |
| 330 | |
| 331 | if (coordCmdStatus != NULL) { |
| 332 | *coordCmdStatus = reply.coordCmdStatus; |
| 333 | } |
| 334 | if (numPeers != NULL) { |
| 335 | *numPeers = reply.numPeers; |
| 336 | } |
| 337 | if (isRunning != NULL) { |
| 338 | *isRunning = reply.isRunning; |
| 339 | } |
| 340 | if (ckptInterval != NULL) { |
| 341 | *ckptInterval = reply.theCheckpointInterval; |
| 342 | } |
| 343 | |
| 344 | _real_close(coordFd); |
| 345 | |
| 346 | return replyData; |
| 347 | } |
| 348 | |
| 349 | void |
no test coverage detected