Skip to content

Commit 52c304e

Browse files
committed
IO (Linux): add detailed error messages for ffProcessAppendStdOut
1 parent 695e3cc commit 52c304e

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

src/common/io/io.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,23 @@ static inline void ffUnsuppressIO(bool* suppressed)
101101

102102
void ffListFilesRecursively(const char* path);
103103

104+
static inline bool wrapClose(FFNativeFD* pfd)
105+
{
106+
assert(pfd);
107+
108+
#ifndef WIN32
109+
if (*pfd < 0)
110+
return false;
111+
close(*pfd);
112+
#else
113+
// https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443
114+
if (*pfd == NULL || *pfd == INVALID_HANDLE_VALUE)
115+
return false;
116+
CloseHandle(*pfd);
117+
#endif
118+
119+
return true;
120+
}
121+
#define FF_AUTO_CLOSE_FD __attribute__((__cleanup__(wrapClose)))
122+
104123
#endif // FF_INCLUDED_common_io_io

src/common/processing_linux.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,20 @@ const char* ffProcessAppendStdOut(FFstrbuf* buffer, char* const argv[])
3030

3131
//Parent
3232
close(pipes[1]);
33-
waitpid(childPid, NULL, 0);
34-
bool ok = ffAppendFDBuffer(pipes[0], buffer);
35-
close(pipes[0]);
3633

37-
return ok ? NULL : "ffAppendFDBuffer() failed";
34+
int FF_AUTO_CLOSE_FD childPipeFd = pipes[0];
35+
int status = -1;
36+
if(waitpid(childPid, &status, 0) < 0)
37+
return "waitpid(childPid, &status, 0) failed";
38+
39+
if (!WIFEXITED(status))
40+
return "WIFEXITED(status) == false";
41+
42+
if(WEXITSTATUS(status) == 901)
43+
return "WEXITSTATUS(status) == 901 ( execvp failed )";
44+
45+
if(!ffAppendFDBuffer(childPipeFd, buffer))
46+
return "ffAppendFDBuffer(childPipeFd, buffer) failed";
47+
48+
return NULL;
3849
}

0 commit comments

Comments
 (0)