mirror of
https://repo.dec05eba.com/gpu-screen-recorder-ui
synced 2026-05-05 06:20:44 +09:00
pidof ignore self
This commit is contained in:
@@ -21,5 +21,5 @@ namespace gsr {
|
|||||||
// This works the same as |exec_program_get_stdout|, except on flatpak where this runs the program on the
|
// This works the same as |exec_program_get_stdout|, except on flatpak where this runs the program on the
|
||||||
// host machine with flatpak-spawn --host
|
// host machine with flatpak-spawn --host
|
||||||
int exec_program_on_host_get_stdout(const char **args, std::string &result);
|
int exec_program_on_host_get_stdout(const char **args, std::string &result);
|
||||||
pid_t pidof(const char *process_name);
|
pid_t pidof(const char *process_name, pid_t ignore_pid);
|
||||||
}
|
}
|
||||||
@@ -206,7 +206,7 @@ namespace gsr {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pid_t pidof(const char *process_name) {
|
pid_t pidof(const char *process_name, pid_t ignore_pid) {
|
||||||
pid_t result = -1;
|
pid_t result = -1;
|
||||||
DIR *dir = opendir("/proc");
|
DIR *dir = opendir("/proc");
|
||||||
if(!dir)
|
if(!dir)
|
||||||
@@ -222,8 +222,11 @@ namespace gsr {
|
|||||||
|
|
||||||
snprintf(cmdline_filepath, sizeof(cmdline_filepath), "/proc/%s/cmdline", entry->d_name);
|
snprintf(cmdline_filepath, sizeof(cmdline_filepath), "/proc/%s/cmdline", entry->d_name);
|
||||||
if(read_cmdline_arg0(cmdline_filepath, arg0, sizeof(arg0)) && strcmp(process_name, arg0) == 0) {
|
if(read_cmdline_arg0(cmdline_filepath, arg0, sizeof(arg0)) && strcmp(process_name, arg0) == 0) {
|
||||||
result = atoi(entry->d_name);
|
const pid_t pid = atoi(entry->d_name);
|
||||||
break;
|
if(pid != ignore_pid) {
|
||||||
|
result = pid;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -231,7 +231,7 @@ int main(int argc, char **argv) {
|
|||||||
// that uses pid sandboxing. Replace this with a better method once we no longer rely on linux global hotkeys on some platform.
|
// that uses pid sandboxing. Replace this with a better method once we no longer rely on linux global hotkeys on some platform.
|
||||||
// TODO: This method doesn't work when disabling hotkeys and the method below with pidof gsr-ui doesn't work in flatpak.
|
// TODO: This method doesn't work when disabling hotkeys and the method below with pidof gsr-ui doesn't work in flatpak.
|
||||||
// What do? creating a pid file doesn't work in flatpak either.
|
// What do? creating a pid file doesn't work in flatpak either.
|
||||||
if(is_gsr_ui_virtual_keyboard_running() || gsr::pidof("gsr-ui") != -1) {
|
if(is_gsr_ui_virtual_keyboard_running() || gsr::pidof("gsr-ui", getpid()) != -1) {
|
||||||
gsr::Rpc rpc;
|
gsr::Rpc rpc;
|
||||||
if(rpc.open("gsr-ui") && rpc.write("show_ui\n", 8)) {
|
if(rpc.open("gsr-ui") && rpc.write("show_ui\n", 8)) {
|
||||||
fprintf(stderr, "Error: another instance of gsr-ui is already running, opening that one instead\n");
|
fprintf(stderr, "Error: another instance of gsr-ui is already running, opening that one instead\n");
|
||||||
|
|||||||
Reference in New Issue
Block a user