| 473 | } |
| 474 | |
| 475 | static int ProcessWaitPID(pid_t pid, int *status) |
| 476 | { |
| 477 | Dictionary::Ptr request = new Dictionary({ |
| 478 | { "command", "waitpid" }, |
| 479 | { "pid", pid } |
| 480 | }); |
| 481 | |
| 482 | String jrequest = JsonEncode(request); |
| 483 | size_t length = jrequest.GetLength(); |
| 484 | |
| 485 | std::unique_lock<std::mutex> lock(l_ProcessControlMutex); |
| 486 | |
| 487 | do { |
| 488 | while (send(l_ProcessControlFD, &length, sizeof(length), 0) < 0) { |
| 489 | StartSpawnProcessHelper(); |
| 490 | } |
| 491 | } while (send(l_ProcessControlFD, jrequest.CStr(), jrequest.GetLength(), 0) < 0); |
| 492 | |
| 493 | char buf[4096]; |
| 494 | |
| 495 | ssize_t rc = recv(l_ProcessControlFD, buf, sizeof(buf), 0); |
| 496 | |
| 497 | if (rc <= 0) |
| 498 | return -1; |
| 499 | |
| 500 | String jresponse = String(buf, buf + rc); |
| 501 | |
| 502 | Dictionary::Ptr response = JsonDecode(jresponse); |
| 503 | *status = response->Get("status"); |
| 504 | return response->Get("rc"); |
| 505 | } |
| 506 | |
| 507 | void Process::InitializeSpawnHelper() |
| 508 | { |