Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 void Usage(const base::FilePath& me) { | 66 void Usage(const base::FilePath& me) { |
| 67 fprintf(stderr, | 67 fprintf(stderr, |
| 68 "Usage: %" PRFilePath " [OPTION]...\n" | 68 "Usage: %" PRFilePath " [OPTION]...\n" |
| 69 "Crashpad's exception handler server.\n" | 69 "Crashpad's exception handler server.\n" |
| 70 "\n" | 70 "\n" |
| 71 " --annotation=KEY=VALUE set a process annotation in each crash report\n" | 71 " --annotation=KEY=VALUE set a process annotation in each crash report\n" |
| 72 " --database=PATH store the crash report database at PATH\n" | 72 " --database=PATH store the crash report database at PATH\n" |
| 73 #if defined(OS_MACOSX) | 73 #if defined(OS_MACOSX) |
| 74 " --handshake-fd=FD establish communication with the client over FD\n " | 74 " --handshake-fd=FD establish communication with the client over FD\n " |
| 75 " --mach-service=SERVICE register SERVICE with the bootstrap server\n" | 75 " --mach-service=SERVICE register SERVICE with the bootstrap server\n" |
| 76 #elif defined(OS_WIN) | |
| 77 " --handshake-handle=HANDLE\n" | |
| 78 " create a new pipe and send its name via HANDLE\n" | |
| 79 #endif // OS_MACOSX | |
| 80 " --no-rate-limit don't rate limit crash uploads\n" | |
| 81 #if defined(OS_MACOSX) | |
| 76 " --reset-own-crash-exception-port-to-system-default\n" | 82 " --reset-own-crash-exception-port-to-system-default\n" |
| 77 " reset the server's exception handler to default\n " | 83 " reset the server's exception handler to default\n " |
| 78 #elif defined(OS_WIN) | 84 #elif defined(OS_WIN) |
| 79 " --handshake-handle=HANDLE\n" | |
| 80 " create a new pipe and send its name via HANDLE\n" | |
| 81 " --pipe-name=PIPE communicate with the client over PIPE\n" | 85 " --pipe-name=PIPE communicate with the client over PIPE\n" |
| 82 #endif // OS_MACOSX | 86 #endif // OS_MACOSX |
| 83 " --url=URL send crash reports to this Breakpad server URL,\n " | 87 " --url=URL send crash reports to this Breakpad server URL,\n " |
| 84 " only if uploads are enabled for the database\n" | 88 " only if uploads are enabled for the database\n" |
| 85 " --help display this help and exit\n" | 89 " --help display this help and exit\n" |
| 86 " --version output version information and exit\n", | 90 " --version output version information and exit\n", |
| 87 me.value().c_str()); | 91 me.value().c_str()); |
| 88 ToolSupport::UsageTail(me); | 92 ToolSupport::UsageTail(me); |
| 89 } | 93 } |
| 90 | 94 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 121 const base::FilePath me(argv0.BaseName()); | 125 const base::FilePath me(argv0.BaseName()); |
| 122 | 126 |
| 123 enum OptionFlags { | 127 enum OptionFlags { |
| 124 // Long options without short equivalents. | 128 // Long options without short equivalents. |
| 125 kOptionLastChar = 255, | 129 kOptionLastChar = 255, |
| 126 kOptionAnnotation, | 130 kOptionAnnotation, |
| 127 kOptionDatabase, | 131 kOptionDatabase, |
| 128 #if defined(OS_MACOSX) | 132 #if defined(OS_MACOSX) |
| 129 kOptionHandshakeFD, | 133 kOptionHandshakeFD, |
| 130 kOptionMachService, | 134 kOptionMachService, |
| 135 #elif defined(OS_WIN) | |
| 136 kOptionHandshakeHandle, | |
| 137 #endif // OS_MACOSX | |
| 138 kOptionNoRateLimit, | |
| 139 #if defined(OS_MACOSX) | |
| 131 kOptionResetOwnCrashExceptionPortToSystemDefault, | 140 kOptionResetOwnCrashExceptionPortToSystemDefault, |
| 132 #elif defined(OS_WIN) | 141 #elif defined(OS_WIN) |
| 133 kOptionHandshakeHandle, | |
| 134 kOptionPipeName, | 142 kOptionPipeName, |
| 135 #endif // OS_MACOSX | 143 #endif // OS_MACOSX |
| 136 kOptionURL, | 144 kOptionURL, |
| 137 | 145 |
| 138 // Standard options. | 146 // Standard options. |
| 139 kOptionHelp = -2, | 147 kOptionHelp = -2, |
| 140 kOptionVersion = -3, | 148 kOptionVersion = -3, |
| 141 }; | 149 }; |
| 142 | 150 |
| 143 struct { | 151 struct { |
| 144 std::map<std::string, std::string> annotations; | 152 std::map<std::string, std::string> annotations; |
| 145 std::string url; | 153 std::string url; |
| 146 const char* database; | 154 const char* database; |
| 147 #if defined(OS_MACOSX) | 155 #if defined(OS_MACOSX) |
| 148 int handshake_fd; | 156 int handshake_fd; |
| 149 std::string mach_service; | 157 std::string mach_service; |
| 150 bool reset_own_crash_exception_port_to_system_default; | 158 bool reset_own_crash_exception_port_to_system_default; |
| 151 #elif defined(OS_WIN) | 159 #elif defined(OS_WIN) |
| 152 HANDLE handshake_handle; | 160 HANDLE handshake_handle; |
| 153 std::string pipe_name; | 161 std::string pipe_name; |
| 154 #endif // OS_MACOSX | 162 #endif // OS_MACOSX |
| 163 bool rate_limit; | |
| 155 } options = {}; | 164 } options = {}; |
| 156 #if defined(OS_MACOSX) | 165 #if defined(OS_MACOSX) |
| 157 options.handshake_fd = -1; | 166 options.handshake_fd = -1; |
| 158 #elif defined(OS_WIN) | 167 #elif defined(OS_WIN) |
| 159 options.handshake_handle = INVALID_HANDLE_VALUE; | 168 options.handshake_handle = INVALID_HANDLE_VALUE; |
| 160 #endif | 169 #endif |
| 170 options.rate_limit = true; | |
| 161 | 171 |
| 162 const option long_options[] = { | 172 const option long_options[] = { |
| 163 {"annotation", required_argument, nullptr, kOptionAnnotation}, | 173 {"annotation", required_argument, nullptr, kOptionAnnotation}, |
| 164 {"database", required_argument, nullptr, kOptionDatabase}, | 174 {"database", required_argument, nullptr, kOptionDatabase}, |
| 165 #if defined(OS_MACOSX) | 175 #if defined(OS_MACOSX) |
| 166 {"handshake-fd", required_argument, nullptr, kOptionHandshakeFD}, | 176 {"handshake-fd", required_argument, nullptr, kOptionHandshakeFD}, |
| 167 {"mach-service", required_argument, nullptr, kOptionMachService}, | 177 {"mach-service", required_argument, nullptr, kOptionMachService}, |
| 168 {"reset-own-crash-exception-port-to-system-default", | 178 {"reset-own-crash-exception-port-to-system-default", |
| 169 no_argument, | 179 no_argument, |
| 170 nullptr, | 180 nullptr, |
| 171 kOptionResetOwnCrashExceptionPortToSystemDefault}, | 181 kOptionResetOwnCrashExceptionPortToSystemDefault}, |
| 172 #elif defined(OS_WIN) | 182 #elif defined(OS_WIN) |
| 173 {"handshake-handle", required_argument, nullptr, kOptionHandshakeHandle}, | 183 {"handshake-handle", required_argument, nullptr, kOptionHandshakeHandle}, |
| 174 {"pipe-name", required_argument, nullptr, kOptionPipeName}, | 184 {"pipe-name", required_argument, nullptr, kOptionPipeName}, |
| 175 #endif // OS_MACOSX | 185 #endif // OS_MACOSX |
| 176 {"url", required_argument, nullptr, kOptionURL}, | 186 {"url", required_argument, nullptr, kOptionURL}, |
| 187 {"no-rate-limit", no_argument, nullptr, kOptionNoRateLimit}, | |
|
Mark Mentovai
2016/01/06 17:51:50
Do the ugly dance with this one too.
scottmg
2016/01/06 17:55:37
Done.
| |
| 177 {"help", no_argument, nullptr, kOptionHelp}, | 188 {"help", no_argument, nullptr, kOptionHelp}, |
| 178 {"version", no_argument, nullptr, kOptionVersion}, | 189 {"version", no_argument, nullptr, kOptionVersion}, |
| 179 {nullptr, 0, nullptr, 0}, | 190 {nullptr, 0, nullptr, 0}, |
| 180 }; | 191 }; |
| 181 | 192 |
| 182 int opt; | 193 int opt; |
| 183 while ((opt = getopt_long(argc, argv, "", long_options, nullptr)) != -1) { | 194 while ((opt = getopt_long(argc, argv, "", long_options, nullptr)) != -1) { |
| 184 switch (opt) { | 195 switch (opt) { |
| 185 case kOptionAnnotation: { | 196 case kOptionAnnotation: { |
| 186 std::string key; | 197 std::string key; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 207 ToolSupport::UsageHint(me, | 218 ToolSupport::UsageHint(me, |
| 208 "--handshake-fd requires a file descriptor"); | 219 "--handshake-fd requires a file descriptor"); |
| 209 return EXIT_FAILURE; | 220 return EXIT_FAILURE; |
| 210 } | 221 } |
| 211 break; | 222 break; |
| 212 } | 223 } |
| 213 case kOptionMachService: { | 224 case kOptionMachService: { |
| 214 options.mach_service = optarg; | 225 options.mach_service = optarg; |
| 215 break; | 226 break; |
| 216 } | 227 } |
| 217 case kOptionResetOwnCrashExceptionPortToSystemDefault: { | |
| 218 options.reset_own_crash_exception_port_to_system_default = true; | |
| 219 break; | |
| 220 } | |
| 221 #elif defined(OS_WIN) | 228 #elif defined(OS_WIN) |
| 222 case kOptionHandshakeHandle: { | 229 case kOptionHandshakeHandle: { |
| 223 // Use unsigned int, because the handle was presented by the client in | 230 // Use unsigned int, because the handle was presented by the client in |
| 224 // 0x%x format. | 231 // 0x%x format. |
| 225 unsigned int handle_uint; | 232 unsigned int handle_uint; |
| 226 if (!StringToNumber(optarg, &handle_uint) || | 233 if (!StringToNumber(optarg, &handle_uint) || |
| 227 (options.handshake_handle = IntToHandle(handle_uint)) == | 234 (options.handshake_handle = IntToHandle(handle_uint)) == |
| 228 INVALID_HANDLE_VALUE) { | 235 INVALID_HANDLE_VALUE) { |
| 229 ToolSupport::UsageHint(me, "--handshake-handle requires a HANDLE"); | 236 ToolSupport::UsageHint(me, "--handshake-handle requires a HANDLE"); |
| 230 return EXIT_FAILURE; | 237 return EXIT_FAILURE; |
| 231 } | 238 } |
| 232 break; | 239 break; |
| 233 } | 240 } |
| 241 #endif // OS_MACOSX | |
| 242 case kOptionNoRateLimit: { | |
| 243 options.rate_limit = false; | |
| 244 break; | |
| 245 } | |
| 246 #if defined(OS_MACOSX) | |
| 247 case kOptionResetOwnCrashExceptionPortToSystemDefault: { | |
| 248 options.reset_own_crash_exception_port_to_system_default = true; | |
| 249 break; | |
| 250 } | |
| 251 #elif defined(OS_WIN) | |
| 234 case kOptionPipeName: { | 252 case kOptionPipeName: { |
| 235 options.pipe_name = optarg; | 253 options.pipe_name = optarg; |
| 236 break; | 254 break; |
| 237 } | 255 } |
| 238 #endif // OS_MACOSX | 256 #endif // OS_MACOSX |
| 239 case kOptionURL: { | 257 case kOptionURL: { |
| 240 options.url = optarg; | 258 options.url = optarg; |
| 241 break; | 259 break; |
| 242 } | 260 } |
| 243 case kOptionHelp: { | 261 case kOptionHelp: { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 364 } | 382 } |
| 365 #endif // OS_MACOSX | 383 #endif // OS_MACOSX |
| 366 | 384 |
| 367 scoped_ptr<CrashReportDatabase> database(CrashReportDatabase::Initialize( | 385 scoped_ptr<CrashReportDatabase> database(CrashReportDatabase::Initialize( |
| 368 base::FilePath(ToolSupport::CommandLineArgumentToFilePathStringType( | 386 base::FilePath(ToolSupport::CommandLineArgumentToFilePathStringType( |
| 369 options.database)))); | 387 options.database)))); |
| 370 if (!database) { | 388 if (!database) { |
| 371 return EXIT_FAILURE; | 389 return EXIT_FAILURE; |
| 372 } | 390 } |
| 373 | 391 |
| 374 CrashReportUploadThread upload_thread(database.get(), options.url); | 392 // TODO(scottmg): options.rate_limit should be removed when we have a |
| 393 // configurable database setting to control upload limiting. | |
| 394 // https://bugs.chromium.org/p/crashpad/issues/detail?id=23 | |
|
Mark Mentovai
2016/01/06 17:51:50
Short links, https://crashpad.chromium.org/bug/23
scottmg
2016/01/06 17:55:37
Ah, I can never remember what the shorter version
| |
| 395 CrashReportUploadThread upload_thread( | |
| 396 database.get(), options.url, options.rate_limit); | |
| 375 upload_thread.Start(); | 397 upload_thread.Start(); |
| 376 | 398 |
| 377 PruneCrashReportThread prune_thread(database.get(), | 399 PruneCrashReportThread prune_thread(database.get(), |
| 378 PruneCondition::GetDefault()); | 400 PruneCondition::GetDefault()); |
| 379 prune_thread.Start(); | 401 prune_thread.Start(); |
| 380 | 402 |
| 381 CrashReportExceptionHandler exception_handler( | 403 CrashReportExceptionHandler exception_handler( |
| 382 database.get(), &upload_thread, &options.annotations); | 404 database.get(), &upload_thread, &options.annotations); |
| 383 | 405 |
| 384 exception_handler_server.Run(&exception_handler); | 406 exception_handler_server.Run(&exception_handler); |
| 385 | 407 |
| 386 upload_thread.Stop(); | 408 upload_thread.Stop(); |
| 387 prune_thread.Stop(); | 409 prune_thread.Stop(); |
| 388 | 410 |
| 389 return EXIT_SUCCESS; | 411 return EXIT_SUCCESS; |
| 390 } | 412 } |
| 391 | 413 |
| 392 } // namespace crashpad | 414 } // namespace crashpad |
| OLD | NEW |