Skip to content

Exit child process when execvp fails - #4577

Open
Ramya-9353 wants to merge 4 commits into
tesseract-ocr:mainfrom
Ramya-9353:fix-scrollview-execvp-failure
Open

Exit child process when execvp fails#4577
Ramya-9353 wants to merge 4 commits into
tesseract-ocr:mainfrom
Ramya-9353:fix-scrollview-execvp-failure

Conversation

@Ramya-9353

Copy link
Copy Markdown
Contributor

Summary

Handle the failure case of execvp() in SVSync::StartProcess().

If execvp() fails, the child process now reports the error and exits immediately instead of continuing along the parent's execution path.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Comment thread src/viewer/svutil.cpp Outdated
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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves robustness in the ScrollView utility layer by ensuring forked child processes don’t accidentally continue execution when execvp() fails, and by making socket flushing safer when send() is interrupted or fails.

Changes:

  • In SVSync::StartProcess(), handle execvp() failure by reporting the error and exiting the child immediately.
  • In SVNetwork::Flush(), handle send() failures safely (avoid erasing with a negative count) and retry on EINTR (non-Windows).

Comment thread src/viewer/svutil.cpp Outdated
Comment on lines +178 to +181
#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.

Comment thread src/viewer/svutil.cpp Outdated
Comment on lines +174 to +176
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants