app-i18n/mozc: Initial commit - add fcitx5 support
[gentoo-zh.git] / app-i18n / mozc / files / mozc-2.23.2815.102-server_path_check.patch
blobdd606e27fb563d0183b9b7fab93c28def3212fb9
1 https://github.com/google/mozc/issues/471
3 --- /src/ipc/ipc_path_manager.cc
4 +++ /src/ipc/ipc_path_manager.cc
5 @@ -332,9 +332,21 @@
6 return false;
9 + // Expand symbolic links in the expected server path to avoid false negatives
10 + // during comparisons of the expected server path and the actual server path.
11 + string real_server_path = server_path;
12 +#ifndef OS_WIN
13 + char real_server_path_[PATH_MAX];
14 + if (realpath(server_path.c_str(), real_server_path_) == NULL) {
15 + LOG(ERROR) << "realpath failed: " << strerror(errno);
16 + return false;
17 + }
18 + real_server_path = real_server_path_;
19 +#endif
21 // compare path name
22 if (pid == server_pid_) {
23 - return (server_path == server_path_);
24 + return (real_server_path == server_path_);
27 server_pid_ = 0;
28 @@ -344,17 +356,17 @@
30 std::wstring expected_server_ntpath;
31 const std::map<string, std::wstring>::const_iterator it =
32 - expected_server_ntpath_cache_.find(server_path);
33 + expected_server_ntpath_cache_.find(real_server_path);
34 if (it != expected_server_ntpath_cache_.end()) {
35 expected_server_ntpath = it->second;
36 } else {
37 std::wstring wide_server_path;
38 - Util::UTF8ToWide(server_path, &wide_server_path);
39 + Util::UTF8ToWide(real_server_path, &wide_server_path);
40 if (WinUtil::GetNtPath(wide_server_path, &expected_server_ntpath)) {
41 - // Caches the relationship from |server_path| to
42 - // |expected_server_ntpath| in case |server_path| is renamed later.
43 + // Caches the relationship from |real_server_path| to
44 + // |expected_server_ntpath| in case |real_server_path| is renamed later.
45 // (This can happen during the updating).
46 - expected_server_ntpath_cache_[server_path] = expected_server_ntpath;
47 + expected_server_ntpath_cache_[real_server_path] = expected_server_ntpath;
51 @@ -371,9 +383,9 @@
52 return false;
55 - // Here we can safely assume that |server_path| (expected one) should be
56 + // Here we can safely assume that |real_server_path| (expected one) should be
57 // the same to |server_path_| (actual one).
58 - server_path_ = server_path;
59 + server_path_ = real_server_path;
60 server_pid_ = pid;
62 #endif // OS_WIN
63 @@ -399,7 +411,7 @@
64 #ifdef OS_LINUX
65 // load from /proc/<pid>/exe
66 char proc[128];
67 - char filename[512];
68 + char filename[PATH_MAX];
69 snprintf(proc, sizeof(proc) - 1, "/proc/%u/exe", pid);
70 const ssize_t size = readlink(proc, filename, sizeof(filename) - 1);
71 if (size == -1) {
72 @@ -412,18 +424,18 @@
73 server_pid_ = pid;
74 #endif // OS_LINUX
76 - VLOG(1) << "server path: " << server_path << " " << server_path_;
77 - if (server_path == server_path_) {
78 + VLOG(1) << "server path: " << real_server_path << " " << server_path_;
79 + if (real_server_path == server_path_) {
80 return true;
83 #ifdef OS_LINUX
84 - if ((server_path + " (deleted)") == server_path_) {
85 - LOG(WARNING) << server_path << " on disk is modified";
86 + if ((real_server_path + " (deleted)") == server_path_) {
87 + LOG(WARNING) << real_server_path << " on disk is modified";
88 // If a user updates the server binary on disk during the server is running,
89 // "readlink /proc/<pid>/exe" returns a path with the " (deleted)" suffix.
90 // We allow the special case.
91 - server_path_ = server_path;
92 + server_path_ = real_server_path;
93 return true;
95 #endif // OS_LINUX