Skip to content

Commit

Permalink
Properly handling inaccessible process path on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
houmain committed Aug 17, 2023
1 parent eddd8f6 commit b3ee769
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ A block continues until the next block (respectively the end of the file). The b
...
```

:warning: The device filter is currently only available on Linux and the process path may not be available on Wayland and for applications running as administrator on Windows.
:warning: The `device` filter is currently only available on Linux and the process `path` may not be available on Wayland and for processes with higher privileges.

Class and device filters match contexts with the _exact_ same string, others match contexts _containing_ the string.
For finer control [regular expressions](https://en.wikipedia.org/wiki/Regular_expression) can be used. These have to be delimited with slashes. Optionally `i` can be appended to make the comparison case insensitive:
Expand Down
2 changes: 2 additions & 0 deletions src/client/linux/FocusedWindowImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ std::string get_process_path_by_pid(int pid) {
char path[32];
std::sprintf(path, "/proc/%d/exe", pid);
const auto resolved = ::realpath(path, nullptr);
if (!resolved)
return { };
auto result = std::string(resolved);
::free(resolved);
return result;
Expand Down
5 changes: 2 additions & 3 deletions src/client/linux/FocusedWindowX11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,13 @@ class FocusedWindowX11 : public FocusedWindowSystem {

// window handles can become invalid any time
auto window_class = get_window_class(window);
auto window_path = get_window_path(window);
if (window_class.empty() || window_title.empty() || window_path.empty())
if (window_class.empty() || window_title.empty())
return false;

m_focused_window = window;
m_data.window_class = std::move(window_class);
m_data.window_title = std::move(window_title);
m_data.window_path = std::move(window_path);
m_data.window_path = get_window_path(window);
return true;
}

Expand Down

0 comments on commit b3ee769

Please sign in to comment.