crash_allow_disabling_compression_on_linux.patch 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Jeremy Apthorp <[email protected]>
  3. Date: Thu, 14 May 2020 16:52:09 -0700
  4. Subject: crash: allow disabling compression on linux
  5. This makes compression optional on breakpad_linux.
  6. Upstream attempted here
  7. https://chromium-review.googlesource.com/c/chromium/src/+/2198641, but
  8. was denied.
  9. Ultimately we should remove the option to disable compression, and
  10. subsequently remove this patch.
  11. diff --git a/components/crash/core/app/breakpad_linux.cc b/components/crash/core/app/breakpad_linux.cc
  12. index 8df14f416ee321e1259433715a61fa6025207d80..1d7f38d3f89d9c7f110cc9eb880264464787eb32 100644
  13. --- a/components/crash/core/app/breakpad_linux.cc
  14. +++ b/components/crash/core/app/breakpad_linux.cc
  15. @@ -110,6 +110,8 @@ void SetUploadURL(const std::string& url) {
  16. DCHECK(!g_upload_url);
  17. g_upload_url = strdup(url.c_str());
  18. }
  19. +
  20. +bool g_compress_uploads = true;
  21. #endif
  22. bool g_is_node = false;
  23. @@ -1322,56 +1324,60 @@ void ExecUploadProcessOrTerminate(const BreakpadInfo& info,
  24. #else // BUILDFLAG(IS_CHROMEOS_ASH)
  25. - // Compress |dumpfile| with gzip.
  26. - const pid_t gzip_child = sys_fork();
  27. - if (gzip_child < 0) {
  28. - static const char msg[] = "sys_fork() for gzip process failed.\n";
  29. - WriteLog(msg, sizeof(msg) - 1);
  30. - sys__exit(1);
  31. - }
  32. - if (!gzip_child) {
  33. - // gzip process.
  34. - const char* args[] = {
  35. - "/bin/gzip",
  36. - "-f", // Do not prompt to verify before overwriting.
  37. - dumpfile,
  38. - nullptr,
  39. - };
  40. - execve(args[0], const_cast<char**>(args), environ);
  41. - static const char msg[] = "Cannot exec gzip.\n";
  42. - WriteLog(msg, sizeof(msg) - 1);
  43. - sys__exit(1);
  44. - }
  45. - // Wait for gzip process.
  46. - int status = 0;
  47. - if (sys_waitpid(gzip_child, &status, 0) != gzip_child ||
  48. - !WIFEXITED(status) || WEXITSTATUS(status) != 0) {
  49. - static const char msg[] = "sys_waitpid() for gzip process failed.\n";
  50. - WriteLog(msg, sizeof(msg) - 1);
  51. - sys_kill(gzip_child, SIGKILL);
  52. - sys__exit(1);
  53. - }
  54. + if (g_compress_uploads) {
  55. + // Compress |dumpfile| with gzip.
  56. + const pid_t gzip_child = sys_fork();
  57. + if (gzip_child < 0) {
  58. + static const char msg[] = "sys_fork() for gzip process failed.\n";
  59. + WriteLog(msg, sizeof(msg) - 1);
  60. + sys__exit(1);
  61. + }
  62. + if (!gzip_child) {
  63. + // gzip process.
  64. + const char* args[] = {
  65. + "/bin/gzip",
  66. + "-f", // Do not prompt to verify before overwriting.
  67. + dumpfile,
  68. + nullptr,
  69. + };
  70. + execve(args[0], const_cast<char**>(args), environ);
  71. + static const char msg[] = "Cannot exec gzip.\n";
  72. + WriteLog(msg, sizeof(msg) - 1);
  73. + sys__exit(1);
  74. + }
  75. + // Wait for gzip process.
  76. + int status = 0;
  77. + if (sys_waitpid(gzip_child, &status, 0) != gzip_child ||
  78. + !WIFEXITED(status) || WEXITSTATUS(status) != 0) {
  79. + static const char msg[] = "sys_waitpid() for gzip process failed.\n";
  80. + WriteLog(msg, sizeof(msg) - 1);
  81. + sys_kill(gzip_child, SIGKILL);
  82. + sys__exit(1);
  83. + }
  84. - static const char kGzipExtension[] = ".gz";
  85. - const size_t gzip_file_size = my_strlen(dumpfile) + sizeof(kGzipExtension);
  86. - char* const gzip_file = reinterpret_cast<char*>(allocator->Alloc(
  87. - gzip_file_size));
  88. - my_strlcpy(gzip_file, dumpfile, gzip_file_size);
  89. - my_strlcat(gzip_file, kGzipExtension, gzip_file_size);
  90. + static const char kGzipExtension[] = ".gz";
  91. + const size_t gzip_file_size = my_strlen(dumpfile) + sizeof(kGzipExtension);
  92. + char* const gzip_file =
  93. + reinterpret_cast<char*>(allocator->Alloc(gzip_file_size));
  94. + my_strlcpy(gzip_file, dumpfile, gzip_file_size);
  95. + my_strlcat(gzip_file, kGzipExtension, gzip_file_size);
  96. - // Rename |gzip_file| to |dumpfile| (the original file was deleted by gzip).
  97. - if (rename(gzip_file, dumpfile)) {
  98. - static const char msg[] = "Failed to rename gzipped file.\n";
  99. - WriteLog(msg, sizeof(msg) - 1);
  100. - sys__exit(1);
  101. + // Rename |gzip_file| to |dumpfile| (the original file was deleted by gzip).
  102. + if (rename(gzip_file, dumpfile)) {
  103. + static const char msg[] = "Failed to rename gzipped file.\n";
  104. + WriteLog(msg, sizeof(msg) - 1);
  105. + sys__exit(1);
  106. + }
  107. }
  108. // The --header argument to wget looks like:
  109. // --header=Content-Encoding: gzip
  110. // --header=Content-Type: multipart/form-data; boundary=XYZ
  111. // where the boundary has two fewer leading '-' chars
  112. - static const char header_content_encoding[] =
  113. + static const char header_content_encoding_gzip[] =
  114. "--header=Content-Encoding: gzip";
  115. + static const char header_content_encoding_identity[] =
  116. + "--header=Content-Encoding: identity";
  117. static const char header_msg[] =
  118. "--header=Content-Type: multipart/form-data; boundary=";
  119. const size_t header_content_type_size =
  120. @@ -1398,7 +1404,8 @@ void ExecUploadProcessOrTerminate(const BreakpadInfo& info,
  121. static const char kWgetBinary[] = "/usr/bin/wget";
  122. const char* args[] = {
  123. kWgetBinary,
  124. - header_content_encoding,
  125. + g_compress_uploads ? header_content_encoding_gzip
  126. + : header_content_encoding_identity,
  127. header_content_type,
  128. post_file,
  129. g_upload_url,
  130. @@ -2039,6 +2046,7 @@ void InitCrashReporter(const std::string& process_type) {
  131. #if !BUILDFLAG(IS_CHROMEOS_ASH)
  132. SetUploadURL(GetCrashReporterClient()->GetUploadUrl());
  133. + g_compress_uploads = GetCrashReporterClient()->GetShouldCompressUploads();
  134. #endif
  135. if (is_browser_process) {