-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Exit child process when execvp fails #4577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -109,6 +109,9 @@ void SVSync::StartProcess(const char *executable, const char *args) { | |
| } | ||
| argv[argc] = nullptr; | ||
| execvp(executable, argv.get()); | ||
| // execvp returns only if execution failed. | ||
| perror(executable); | ||
| _exit(EXIT_FAILURE); | ||
| } | ||
| # endif | ||
| } | ||
|
|
@@ -168,8 +171,23 @@ void SVNetwork::Send(const char *msg) { | |
| void SVNetwork::Flush() { | ||
| std::lock_guard<std::mutex> guard(mutex_send_); | ||
| while (!msg_buffer_out_.empty()) { | ||
| int i = send(stream_, msg_buffer_out_.c_str(), msg_buffer_out_.length(), 0); | ||
| msg_buffer_out_.erase(0, i); | ||
| int i = | ||
| send(stream_, msg_buffer_out_.c_str(), msg_buffer_out_.length(), 0); | ||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Switched to auto, which picks up ssize_t on POSIX and int on Winsock, so the return value is no longer narrowed. |
||
| if (i < 0) { | ||
| #ifndef _WIN32 | ||
| if (errno == EINTR) { | ||
| continue; | ||
| } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added to the standard includes rather than relying on transitive inclusion. |
||
| #endif | ||
| break; | ||
| } | ||
|
|
||
| if (i == 0) { | ||
| break; | ||
| } | ||
|
|
||
| msg_buffer_out_.erase(0, static_cast<std::string::size_type>(i)); | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentation here must be fixed. And why
_exit()instead ofexit()?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation fixed.
_exit()is deliberate: after a failed exec the child still holds copies of the parent's stdio buffers and atexit handlers, soexit()could flush buffered output a second time and run the parent's cleanup in the child._exit()terminates without touching either, which is the usual pattern on the failed-exec path.