diff options
author | dec05eba <dec05eba@protonmail.com> | 2024-11-28 15:11:50 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2024-11-28 15:11:50 +0100 |
commit | 2ea0a921e8d0c100d5f894536a93f0dfdf45f67b (patch) | |
tree | 1f50796f39afc11b6c4e5ba948175b27ad0734a1 /src/Process.cpp | |
parent | ece3d02e0a34d7a90d3e3d21fc426f4954ddfe86 (diff) |
Fix restore portal session option not working, close other notifications when showing a new one
Diffstat (limited to 'src/Process.cpp')
-rw-r--r-- | src/Process.cpp | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/Process.cpp b/src/Process.cpp index 07d9dc6..e5886c0 100644 --- a/src/Process.cpp +++ b/src/Process.cpp @@ -9,6 +9,9 @@ #include <dirent.h> #include <stdlib.h> +#define PIPE_READ 0 +#define PIPE_WRITE 1 + namespace gsr { static void debug_print_args(const char **args) { fprintf(stderr, "gsr-ui info: running command:"); @@ -51,22 +54,40 @@ namespace gsr { return true; } - pid_t exec_program(const char **args) { + pid_t exec_program(const char **args, int *read_fd) { + if(read_fd) + *read_fd = -1; + /* 1 argument */ if(args[0] == nullptr) return -1; + int fds[2] = {-1, -1}; + if(pipe(fds) == -1) + return -1; + debug_print_args(args); pid_t pid = vfork(); if(pid == -1) { + close(fds[PIPE_READ]); + close(fds[PIPE_WRITE]); perror("Failed to vfork"); return -1; } else if(pid == 0) { /* child */ + dup2(fds[PIPE_WRITE], STDOUT_FILENO); + close(fds[PIPE_READ]); + close(fds[PIPE_WRITE]); + execvp(args[0], (char* const*)args); perror("execvp"); _exit(127); } else { /* parent */ + close(fds[PIPE_WRITE]); + if(read_fd) + *read_fd = fds[PIPE_READ]; + else + close(fds[PIPE_READ]); return pid; } } |