mirror of
https://github.com/amadvance/snapraid.git
synced 2026-12-02 21:00:16 -05:00
Handle partial writes and log unexpected stdin errors in Windows os_command
This commit is contained in:
parent
b383cbc4ba
commit
44575b21b1
1 changed files with 20 additions and 4 deletions
22
os/mingw.c
22
os/mingw.c
|
|
@ -683,6 +683,10 @@ void windows_errno(DWORD error)
|
||||||
case ERROR_CRC : /* in ReadFile() */
|
case ERROR_CRC : /* in ReadFile() */
|
||||||
errno = EIO;
|
errno = EIO;
|
||||||
break;
|
break;
|
||||||
|
case ERROR_BROKEN_PIPE : /* in ReadFile() and WriteFile() */
|
||||||
|
case ERROR_NO_DATA :
|
||||||
|
errno = EPIPE;
|
||||||
|
break;
|
||||||
case WSAEADDRINUSE :
|
case WSAEADDRINUSE :
|
||||||
errno = EADDRINUSE;
|
errno = EADDRINUSE;
|
||||||
break;
|
break;
|
||||||
|
|
@ -3414,9 +3418,21 @@ int os_command(const char* command, const char* run_as_user, const char* stdin_t
|
||||||
CloseHandle(stdin_read_handle);
|
CloseHandle(stdin_read_handle);
|
||||||
|
|
||||||
/* write the string to the child's STDIN */
|
/* write the string to the child's STDIN */
|
||||||
if (stdin_text && strlen(stdin_text) > 0) {
|
if (stdin_text != 0) {
|
||||||
DWORD written;
|
size_t len = strlen(stdin_text);
|
||||||
WriteFile(stdin_write_handle, stdin_text, (DWORD)strlen(stdin_text), &written, NULL);
|
size_t written = 0;
|
||||||
|
while (written < len) {
|
||||||
|
DWORD count;
|
||||||
|
if (!WriteFile(stdin_write_handle, stdin_text + written, len - written, &count, 0)) {
|
||||||
|
DWORD error = GetLastError();
|
||||||
|
if (error == ERROR_BROKEN_PIPE || error == ERROR_NO_DATA)
|
||||||
|
break; /* child closed stdin early */
|
||||||
|
windows_errno(error);
|
||||||
|
os_syslog(OS_LVL_INFO, "failed to write stdin to command %s, errno=%s(%d)", command, strerror(errno), errno);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
written += count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* closing the write handle sends EOF to the child */
|
/* closing the write handle sends EOF to the child */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue