aboutsummaryrefslogtreecommitdiff
path: root/src/Process.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2024-09-22 18:17:46 +0200
committerdec05eba <dec05eba@protonmail.com>2024-09-22 18:17:46 +0200
commit61c9b4918ed81a6ad439748f8bcb1c6f9b0cf65e (patch)
tree7b54793153fb8f3b608e59a0c27ddec63fb817f5 /src/Process.cpp
parent5d6d57b8810a6ef88fb5e155d4610345f7df288d (diff)
Save recording status to file to reload it when gsr overlay restarts
Diffstat (limited to 'src/Process.cpp')
-rw-r--r--src/Process.cpp49
1 files changed, 2 insertions, 47 deletions
diff --git a/src/Process.cpp b/src/Process.cpp
index a1e1e6c..822e82e 100644
--- a/src/Process.cpp
+++ b/src/Process.cpp
@@ -58,17 +58,9 @@ namespace gsr {
}
}
- static bool is_number(const char *str) {
- while(*str) {
- char c = *str;
- if(c < '0' || c > '9')
- return false;
- ++str;
- }
- return true;
- }
+ bool read_cmdline_arg0(const char *filepath, char *output_buffer) {
+ output_buffer[0] = '\0';
- static bool read_cmdline(const char *filepath, char *output_buffer) {
const char *arg0_end = NULL;
int fd = open(filepath, O_RDONLY);
if(fd == -1)
@@ -92,41 +84,4 @@ namespace gsr {
close(fd);
return false;
}
-
- static pid_t pidof(const char *process_name) {
- pid_t result = -1;
- DIR *dir = opendir("/proc");
- if(!dir)
- return -1;
-
- char cmdline_filepath[PATH_MAX];
- char arg0[PATH_MAX];
-
- struct dirent *entry;
- while((entry = readdir(dir)) != NULL) {
- if(!is_number(entry->d_name))
- continue;
-
- snprintf(cmdline_filepath, sizeof(cmdline_filepath), "/proc/%s/cmdline", entry->d_name);
- if(read_cmdline(cmdline_filepath, arg0) && strcmp(process_name, arg0) == 0) {
- result = atoi(entry->d_name);
- break;
- }
- }
-
- closedir(dir);
- return result;
- }
-
- bool is_gpu_screen_recorder_running(pid_t &gsr_pid, GsrMode &mode) {
- // TODO: Set |mode| by checking cmdline
- gsr_pid = pidof("gpu-screen-recorder");
- if(gsr_pid == -1) {
- mode = GsrMode::Unknown;
- return false;
- } else {
- mode = GsrMode::Record;
- return true;
- }
- }
} \ No newline at end of file