TODO(alexr): Consider making this asynchronous.
| 305 | |
| 306 | // TODO(alexr): Consider making this asynchronous. |
| 307 | Try<Nothing> generateJeprofFile( |
| 308 | const string& inputPath, |
| 309 | const string& options, |
| 310 | const string& outputPath) |
| 311 | { |
| 312 | // As jeprof doesn't have an option to specify an output file, we actually |
| 313 | // cannot use `os::spawn()` here. |
| 314 | // Note that the three parameters *MUST NOT* be controllable by the user |
| 315 | // accessing the HTTP endpoints, otherwise arbitrary shell commands could be |
| 316 | // trivially injected. |
| 317 | // Apart from that, we dont need to be as careful here as with the actual |
| 318 | // heap profile dump, because a failure will not crash the whole process. |
| 319 | Option<int> result = os::system(strings::format( |
| 320 | "jeprof %s /proc/self/exe %s > %s", |
| 321 | options, |
| 322 | inputPath, |
| 323 | outputPath).get()); |
| 324 | |
| 325 | if (result != 0) { |
| 326 | return Error( |
| 327 | "Error trying to run jeprof. Please make sure that jeprof is installed" |
| 328 | " and that the input file contains data. For more information, please" |
| 329 | " consult the log files of this process"); |
| 330 | } |
| 331 | |
| 332 | return Nothing(); |
| 333 | } |
| 334 | |
| 335 | |
| 336 | // TODO(bevers): Implement `http::Request::extractFromRequest<T>(string key)` |