aboutsummaryrefslogtreecommitdiff
path: root/src/Program.c
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-07-10 04:55:11 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-10 04:55:11 +0200
commit2e156d80e4e3d379849bb1e127e4c69a8f34cea4 (patch)
tree8243911f278aa109707db9f35b84f69be20b93b7 /src/Program.c
parenta50b832de4019ce8b5d72e8541d64d68ed3a615a (diff)
Fallback to invidio.us only if mpv exits (faster fallback)
Diffstat (limited to 'src/Program.c')
-rw-r--r--src/Program.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/Program.c b/src/Program.c
index 2c6759e..65164c4 100644
--- a/src/Program.c
+++ b/src/Program.c
@@ -114,6 +114,28 @@ int wait_program(pid_t process_id) {
return WEXITSTATUS(status);
}
+bool wait_program_non_blocking(pid_t process_id, int *status) {
+ int s;
+ int wait_result = waitpid(process_id, &s, WNOHANG);
+ if(wait_result == -1) {
+ perror("waitpid failed");
+ *status = -errno;
+ return false;
+ } else if(wait_result == 0) {
+ /* the child process is still running */
+ *status = 0;
+ return false;
+ }
+
+ if(!WIFEXITED(s)) {
+ *status = -4;
+ return false;
+ }
+
+ *status = WEXITSTATUS(s);
+ return true;
+}
+
int exec_program_async(const char **args, pid_t *result_process_id) {
/* 1 arguments */
if(args[0] == NULL)