Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/viewer/svutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Copy link
Copy Markdown
Member

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 of exit()?

Copy link
Copy Markdown
Contributor Author

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, so exit() 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.

}
# endif
}
Expand Down Expand Up @@ -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);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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));
}
}

Expand Down