Skip to content

Commit 060e20f

Browse files
committed
Clean up the patch for the crash issue in the Process class
fixes #13655
1 parent 9fa3f3b commit 060e20f

File tree

1 file changed

+21
-35
lines changed

1 file changed

+21
-35
lines changed

lib/base/process.cpp

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ static void ProcessHandler(void)
256256

257257
struct iovec io;
258258
io.iov_base = &length;
259-
io.iov_len = sizeof(size_t);
259+
io.iov_len = sizeof(length);
260260

261261
msg.msg_iov = &io;
262262
msg.msg_iovlen = 1;
@@ -267,17 +267,11 @@ static void ProcessHandler(void)
267267

268268
int rc = recvmsg(l_ProcessControlFD, &msg, 0);
269269

270-
if (rc < 0 && (errno == EINTR || errno == EAGAIN))
271-
continue;
272-
273-
if (rc < 0) {
274-
BOOST_THROW_EXCEPTION(posix_error()
275-
<< boost::errinfo_api_function("recvmsg")
276-
<< boost::errinfo_errno(errno));
277-
}
270+
if (rc <= 0) {
271+
if (rc < 0 && (errno == EINTR || errno == EAGAIN))
272+
continue;
278273

279-
if (length > 1024 * 1024 * 1024) {
280-
BOOST_THROW_EXCEPTION(std::runtime_error("invalid message length"));
274+
break;
281275
}
282276

283277
char *mbuf = new char[length];
@@ -286,15 +280,13 @@ static void ProcessHandler(void)
286280
while (count < length) {
287281
rc = recv(l_ProcessControlFD, mbuf + count, length - count, 0);
288282

289-
if (rc < 0) {
290-
if (errno == EINTR || errno == EAGAIN)
291-
continue;
283+
if (rc <= 0) {
284+
if (rc < 0 && (errno == EINTR || errno == EAGAIN))
285+
continue;
292286

293287
delete [] mbuf;
294288

295-
BOOST_THROW_EXCEPTION(posix_error()
296-
<< boost::errinfo_api_function("recv")
297-
<< boost::errinfo_errno(errno));
289+
_exit(0);
298290
}
299291

300292
count += rc;
@@ -391,7 +383,7 @@ static pid_t ProcessSpawn(const std::vector<String>& arguments, const Dictionary
391383

392384
struct iovec io;
393385
io.iov_base = &length;
394-
io.iov_len = sizeof(size_t);
386+
io.iov_len = sizeof(length);
395387

396388
msg.msg_iov = &io;
397389
msg.msg_iovlen = 1;
@@ -409,14 +401,12 @@ static pid_t ProcessSpawn(const std::vector<String>& arguments, const Dictionary
409401

410402
msg.msg_controllen = cmsg->cmsg_len;
411403

404+
send_message:
412405
while (sendmsg(l_ProcessControlFD, &msg, 0) < 0)
413406
StartSpawnProcessHelper();
414407

415-
if (send(l_ProcessControlFD, jrequest.CStr(), jrequest.GetLength(), 0) < 0) {
416-
BOOST_THROW_EXCEPTION(posix_error()
417-
<< boost::errinfo_api_function("send")
418-
<< boost::errinfo_errno(errno));
419-
}
408+
if (send(l_ProcessControlFD, jrequest.CStr(), jrequest.GetLength(), 0) < 0)
409+
goto send_message;
420410

421411
char buf[4096];
422412

@@ -443,14 +433,12 @@ static int ProcessKill(pid_t pid, int signum)
443433

444434
boost::mutex::scoped_lock lock(l_ProcessControlMutex);
445435

446-
while (send(l_ProcessControlFD, &length, sizeof(size_t), 0) < 0)
436+
send_message:
437+
while (send(l_ProcessControlFD, &length, sizeof(length), 0) < 0)
447438
StartSpawnProcessHelper();
448439

449-
if (send(l_ProcessControlFD, jrequest.CStr(), jrequest.GetLength(), 0) < 0) {
450-
BOOST_THROW_EXCEPTION(posix_error()
451-
<< boost::errinfo_api_function("send")
452-
<< boost::errinfo_errno(errno));
453-
}
440+
if (send(l_ProcessControlFD, jrequest.CStr(), jrequest.GetLength(), 0) < 0)
441+
goto send_message;
454442

455443
char buf[4096];
456444

@@ -476,14 +464,12 @@ static int ProcessWaitPID(pid_t pid, int *status)
476464

477465
boost::mutex::scoped_lock lock(l_ProcessControlMutex);
478466

479-
while (send(l_ProcessControlFD, &length, sizeof(size_t), 0) < 0)
467+
send_message:
468+
while (send(l_ProcessControlFD, &length, sizeof(length), 0) < 0)
480469
StartSpawnProcessHelper();
481470

482-
if (send(l_ProcessControlFD, jrequest.CStr(), jrequest.GetLength(), 0) < 0) {
483-
BOOST_THROW_EXCEPTION(posix_error()
484-
<< boost::errinfo_api_function("send")
485-
<< boost::errinfo_errno(errno));
486-
}
471+
if (send(l_ProcessControlFD, jrequest.CStr(), jrequest.GetLength(), 0) < 0)
472+
goto send_message;
487473

488474
char buf[4096];
489475

0 commit comments

Comments
 (0)