mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-01 10:32:35 +01:00
Processing (Windows): support timeout
This commit is contained in:
@@ -14,8 +14,6 @@
|
||||
#include <poll.h>
|
||||
#endif
|
||||
|
||||
#define FF_WAIT_TIMEOUT 1000
|
||||
|
||||
int waitpid_timeout(pid_t pid, int* status)
|
||||
{
|
||||
if (FF_WAIT_TIMEOUT <= 0)
|
||||
@@ -55,7 +53,7 @@ int waitpid_timeout(pid_t pid, int* status)
|
||||
}
|
||||
}
|
||||
|
||||
const char* ffProcessAppendStdOut(FFstrbuf* buffer, char* const argv[])
|
||||
const char* ffProcessAppendOutput(FFstrbuf* buffer, char* const argv[], bool useStdErr)
|
||||
{
|
||||
int pipes[2];
|
||||
|
||||
@@ -69,52 +67,10 @@ const char* ffProcessAppendStdOut(FFstrbuf* buffer, char* const argv[])
|
||||
//Child
|
||||
if(childPid == 0)
|
||||
{
|
||||
dup2(pipes[1], STDOUT_FILENO);
|
||||
dup2(pipes[1], useStdErr ? STDERR_FILENO : STDOUT_FILENO);
|
||||
close(pipes[0]);
|
||||
close(pipes[1]);
|
||||
close(STDERR_FILENO);
|
||||
execvp(argv[0], argv);
|
||||
exit(901);
|
||||
}
|
||||
|
||||
//Parent
|
||||
close(pipes[1]);
|
||||
|
||||
int FF_AUTO_CLOSE_FD childPipeFd = pipes[0];
|
||||
int status = -1;
|
||||
if(waitpid_timeout(childPid, &status) < 0)
|
||||
return "waitpid(childPid, &status) failed";
|
||||
|
||||
if (!WIFEXITED(status))
|
||||
return "WIFEXITED(status) == false";
|
||||
|
||||
if(WEXITSTATUS(status) == 901)
|
||||
return "WEXITSTATUS(status) == 901 ( execvp failed )";
|
||||
|
||||
if(!ffAppendFDBuffer(childPipeFd, buffer))
|
||||
return "ffAppendFDBuffer(childPipeFd, buffer) failed";
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* ffProcessAppendStdErr(FFstrbuf* buffer, char* const argv[])
|
||||
{
|
||||
int pipes[2];
|
||||
|
||||
if(pipe(pipes) == -1)
|
||||
return "pipe() failed";
|
||||
|
||||
pid_t childPid = fork();
|
||||
if(childPid == -1)
|
||||
return "fork() failed";
|
||||
|
||||
//Child
|
||||
if(childPid == 0)
|
||||
{
|
||||
dup2(pipes[1], STDERR_FILENO);
|
||||
close(pipes[0]);
|
||||
close(pipes[1]);
|
||||
close(STDOUT_FILENO);
|
||||
close(useStdErr ? STDOUT_FILENO : STDERR_FILENO);
|
||||
execvp(argv[0], argv);
|
||||
exit(901);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user