11#include "fastfetch.h"
22#include "common/processing.h"
33#include "common/io/io.h"
4- #include "common/time.h"
54#include "util/stringUtils.h"
65#include "util/mallocHelper.h"
76
@@ -90,6 +89,16 @@ const char* ffProcessAppendOutput(FFstrbuf* buffer, char* const argv[], bool use
9089 waitpid (childPid , NULL , 0 );
9190 return "poll(&pollfd, 1, timeout) timeout (try increasing --processing-timeout)" ;
9291 }
92+ else if (errno == EINTR )
93+ {
94+ // The child process has been terminated. See `chldSignalHandler` in `common/init.c`
95+ if (waitpid (childPid , NULL , WNOHANG ) == childPid )
96+ {
97+ // Read remaining data from the pipe
98+ fcntl (childPipeFd , F_SETFL , O_CLOEXEC | O_NONBLOCK );
99+ childPid = -1 ;
100+ }
101+ }
93102 else if (pollfd .revents & POLLERR )
94103 {
95104 kill (childPid , SIGTERM );
@@ -104,7 +113,7 @@ const char* ffProcessAppendOutput(FFstrbuf* buffer, char* const argv[], bool use
104113 else if (nRead == 0 )
105114 {
106115 int stat_loc = 0 ;
107- if (waitpid (childPid , & stat_loc , 0 ) == childPid )
116+ if (childPid > 0 && waitpid (childPid , & stat_loc , 0 ) == childPid )
108117 {
109118 if (!WIFEXITED (stat_loc ))
110119 return "child process exited abnormally" ;
@@ -113,10 +122,15 @@ const char* ffProcessAppendOutput(FFstrbuf* buffer, char* const argv[], bool use
113122 // We only handle 127 as an error. See `getTerminalVersionUrxvt` in `terminalshell.c`
114123 return NULL ;
115124 }
116- return "waitpid() failed" ;
125+ return NULL ;
117126 }
118127 else if (nRead < 0 )
119- break ;
128+ {
129+ if (errno == EAGAIN )
130+ return NULL ;
131+ else
132+ break ;
133+ }
120134 };
121135
122136 return "read(childPipeFd, str, FF_PIPE_BUFSIZ) failed" ;
0 commit comments