From 2ea0a921e8d0c100d5f894536a93f0dfdf45f67b Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 28 Nov 2024 15:11:50 +0100 Subject: Fix restore portal session option not working, close other notifications when showing a new one --- src/Process.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/Process.cpp') 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 #include +#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; } } -- cgit v1.2.3